re PR middle-end/78228 (fstrict-overflow breaks code without overflow?)
authorRichard Biener <rguenther@suse.de>
Mon, 7 Nov 2016 12:25:09 +0000 (12:25 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 7 Nov 2016 12:25:09 +0000 (12:25 +0000)
2016-11-07  Richard Biener  <rguenther@suse.de>

PR tree-optimization/78228
* tree-ssa-phiopt.c (abs_replacement): Avoid introducing
undefined behavior.

* gcc.dg/tree-ssa/phi-opt-15.c: New testcase.

From-SVN: r241899

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c [new file with mode: 0644]
gcc/tree-ssa-phiopt.c

index 1bc2934e5c0275f9a0182e02e5e19be977bf29a4..262f0068b488905de73814e722f5aa011b676013 100644 (file)
@@ -1,3 +1,9 @@
+2016-11-07  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/78228
+       * tree-ssa-phiopt.c (abs_replacement): Avoid introducing
+       undefined behavior.
+
 2016-11-07  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        PR target/77822
index 7094c885ab4a91a867a2fb1f68fb6e2bb3f0f158..0dff659bda47ddaf3bcc2e509def033b95c3f642 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-07  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/78228
+       * gcc.dg/tree-ssa/phi-opt-15.c: New testcase.
+
 2016-11-07  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        PR target/77822
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c
new file mode 100644 (file)
index 0000000..ac3018e
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+foo (int i)
+{
+  if (i > 0)
+    i = -i;
+  return i;
+}
+
+/* { dg-final { scan-tree-dump-not "ABS" "optimized" } } */
index 3f3b88cfc61386b660349b4d3681337a349124cc..63738d07e2e77fb3a5670b6fc3f530b6547e8103 100644 (file)
@@ -1474,6 +1474,14 @@ abs_replacement (basic_block cond_bb, basic_block middle_bb,
   else
     negate = false;
 
+  /* If the code negates only iff positive then make sure to not
+     introduce undefined behavior when negating or computing the absolute.
+     ???  We could use range info if present to check for arg1 == INT_MIN.  */
+  if (negate
+      && (ANY_INTEGRAL_TYPE_P (TREE_TYPE (arg1))
+         && ! TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1))))
+    return false;
+
   result = duplicate_ssa_name (result, NULL);
 
   if (negate)