re PR tree-optimization/85156 (ICE with -O1 -g: gimplification failed)
authorJakub Jelinek <jakub@redhat.com>
Tue, 3 Apr 2018 21:42:51 +0000 (23:42 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 3 Apr 2018 21:42:51 +0000 (23:42 +0200)
PR tree-optimization/85156
* builtins.c (fold_builtin_expect): Use save_expr on arg1 to avoid
evaluating the argument multiple times.

* c-c++-common/pr85156.c: New test.
* gcc.c-torture/execute/pr85156.c: New test.

From-SVN: r259057

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr85156.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/execute/pr85156.c [new file with mode: 0644]

index fea1bed40d125e9107b05a0dca5f07ef8428748c..78d14afe1717a6193a47328a6c7879074876fcb0 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/85156
+       * builtins.c (fold_builtin_expect): Use save_expr on arg1 to avoid
+       evaluating the argument multiple times.
+
 2018-04-03  Bill Schmidt  <wschmidt@linux.ibm.com>
 
        * config/rs6000/emmintrin.h (_mm_cvtpd_epi32): Use __vector rather
index 0c560182f72500d53cbc54c98efe24854d2068af..e0f6c2a1c0fd0fffcd5f3959f4af87dd0a77a70b 100644 (file)
@@ -7998,6 +7998,7 @@ fold_builtin_expect (location_t loc, tree arg0, tree arg1, tree arg2)
     {
       tree op0 = TREE_OPERAND (inner, 0);
       tree op1 = TREE_OPERAND (inner, 1);
+      arg1 = save_expr (arg1);
 
       op0 = build_builtin_expect_predicate (loc, op0, arg1, arg2);
       op1 = build_builtin_expect_predicate (loc, op1, arg1, arg2);
index 4bd6d261d656a79881e9a9f1d594abb73f7a4cbd..6d1322cb076d009bb3e78d4949fc7580ead92bdb 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/85156
+       * c-c++-common/pr85156.c: New test.
+       * gcc.c-torture/execute/pr85156.c: New test.
+
 2018-04-03  Bill Schmidt  <wschmidt@linux.ibm.com>
 
        * gcc.target/powerpc/powerpc.exp: Add .C suffix for main loop.
diff --git a/gcc/testsuite/c-c++-common/pr85156.c b/gcc/testsuite/c-c++-common/pr85156.c
new file mode 100644 (file)
index 0000000..4f5986b
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR tree-optimization/85156 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -g" } */
+
+int a, b;
+
+int
+foo (void)
+{
+  return __builtin_expect (a ? b != 0 : 0, ({ 1; }));
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr85156.c b/gcc/testsuite/gcc.c-torture/execute/pr85156.c
new file mode 100644 (file)
index 0000000..a296837
--- /dev/null
@@ -0,0 +1,21 @@
+/* PR tree-optimization/85156 */
+
+int x, y;
+
+__attribute__((noipa)) int
+foo (int z)
+{
+  if (__builtin_expect (x ? y != 0 : 0, z++))
+    return 7;
+  return z;
+}
+
+int
+main ()
+{
+  x = 1;
+  asm volatile ("" : "+m" (x), "+m" (y));
+  if (foo (10) != 11)
+    __builtin_abort ();
+  return 0;
+}