]> gcc.gnu.org Git - gcc.git/commitdiff
gimple-fold: Recompute ADDR_EXPR flags after folding a TMR [PR98268]
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 31 Mar 2021 18:34:01 +0000 (19:34 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Wed, 31 Mar 2021 18:34:01 +0000 (19:34 +0100)
The gimple verifier picked up that an ADDR_EXPR of a MEM_REF was not
marked TREE_CONSTANT even though the address was in fact invariant.
This came from folding a &TARGET_MEM_REF with constant operands to
a &MEM_REF; &TARGET_MEM_REF is never treated as TREE_CONSTANT
but &MEM_REF can be.

gcc/
PR tree-optimization/98268
* gimple-fold.c (maybe_canonicalize_mem_ref_addr): Call
recompute_tree_invariant_for_addr_expr after successfully
folding a TARGET_MEM_REF that occurs inside an ADDR_EXPR.

gcc/testsuite/
PR tree-optimization/98268
* gcc.target/aarch64/sve/pr98268-1.c: New test.
* gcc.target/aarch64/sve/pr98268-2.c: Likewise.

gcc/gimple-fold.c
gcc/testsuite/gcc.target/aarch64/sve/pr98268-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/sve/pr98268-2.c [new file with mode: 0644]

index de5a6c22395d8114000eea7599aba2d4a39f6c6d..9e6683dbac919eaf3d4fb7f3a77e7336cc71cb15 100644 (file)
@@ -5877,6 +5877,8 @@ maybe_canonicalize_mem_ref_addr (tree *t, bool is_debug = false)
       if (tem)
        {
          *t = tem;
+         if (TREE_CODE (*orig_t) == ADDR_EXPR)
+           recompute_tree_invariant_for_addr_expr (*orig_t);
          res = true;
        }
     }
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr98268-1.c b/gcc/testsuite/gcc.target/aarch64/sve/pr98268-1.c
new file mode 100644 (file)
index 0000000..fdbe55e
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do link } */
+/* { dg-options "-flto -O -ftree-vectorize --param=aarch64-autovec-preference=3" } */
+/* { dg-additional-sources "pr98268-2.c" } */
+
+short d, e;
+void f(char, long*);
+int main() {
+  long x;
+  f(-114, &x);
+  return d == e;
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr98268-2.c b/gcc/testsuite/gcc.target/aarch64/sve/pr98268-2.c
new file mode 100644 (file)
index 0000000..de3b05d
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O -ftree-vectorize --param=aarch64-autovec-preference=3" } */
+
+extern short d[], e[];
+void f(char a, long *b) {
+  for (int c = 0; c < a - 12; c++) {
+    d[c] = b[c];
+    e[c] = 0;
+  }
+}
This page took 0.078047 seconds and 5 git commands to generate.