re PR c/84607 (Side effects discarded in address computation inside 'if')
authorRichard Biener <rguenther@suse.de>
Wed, 28 Feb 2018 13:40:41 +0000 (13:40 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 28 Feb 2018 13:40:41 +0000 (13:40 +0000)
2018-02-28  Richard Biener  <rguenther@suse.de>

PR middle-end/84607
* genmatch.c (capture_info::walk_match): Do not mark
captured expressions without operands as expr_p given
they act more like predicates and should be subject to
"lost tail" side-effect preserving.

* gcc.dg/pr84607.c: New testcase.

From-SVN: r258061

gcc/ChangeLog
gcc/genmatch.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr84607.c [new file with mode: 0644]

index 8eedfcaaf82781b8f6acccbe8f0ba056da02cf47..d7f8754d2e9ab94e0e36b322978b3285d0e1b778 100644 (file)
@@ -1,3 +1,11 @@
+2018-02-28  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/84607
+       * genmatch.c (capture_info::walk_match): Do not mark
+       captured expressions without operands as expr_p given
+       they act more like predicates and should be subject to
+       "lost tail" side-effect preserving.
+
 2018-02-28  Alexandre Oliva <aoliva@redhat.com>
 
        PR rtl-optimization/81611
index e2b2cbfe66c4ddb20ea9355fbf68ab48c48949cd..be6efe3bf1274acdb6ab3519f4ffdf3c2f42360a 100644 (file)
@@ -2104,7 +2104,11 @@ capture_info::walk_match (operand *o, unsigned toplevel_arg,
       if (c->what
          && (e = dyn_cast <expr *> (c->what)))
        {
-         info[where].expr_p = true;
+         /* Zero-operand expression captures like ADDR_EXPR@0 are
+            similar as predicates -- if they are not mentioned in
+            the result we have to force them to have no side-effects.  */
+         if (e->ops.length () != 0)
+           info[where].expr_p = true;
          info[where].force_single_use |= e->force_single_use;
        }
     }
index 252a33a00d43f0ccd04ad54b0550be7d3a570fdd..eaa5041b18d7bc9f2996d2563be59d302af0abe5 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-28  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/84607
+       * gcc.dg/pr84607.c: New testcase.
+
 2018-02-28  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/84602
diff --git a/gcc/testsuite/gcc.dg/pr84607.c b/gcc/testsuite/gcc.dg/pr84607.c
new file mode 100644 (file)
index 0000000..710ee94
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do run } */
+
+extern void exit(int);
+extern void abort(void);
+int a[10];
+int foo()
+{
+  exit (0);
+  return 0;
+}
+int main()
+{
+  if (&a[foo()])
+    abort ();
+  return 0;
+}