re PR tree-optimization/81162 (UBSAN switch triggers incorrect optimization in SLSR)
authorBill Schmidt <wschmidt@linux.vnet.ibm.com>
Fri, 14 Jul 2017 18:06:45 +0000 (18:06 +0000)
committerWilliam Schmidt <wschmidt@gcc.gnu.org>
Fri, 14 Jul 2017 18:06:45 +0000 (18:06 +0000)
[gcc]

2016-07-14  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

PR tree-optimization/81162
* gimple-ssa-strength-reduction.c (replace_mult_candidate): Don't
replace a negate with an add.

[gcc/testsuite]

2016-07-14  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

PR tree-optimization/81162
* gcc.dg/pr81162.c: New file.

From-SVN: r250212

gcc/ChangeLog
gcc/gimple-ssa-strength-reduction.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr81162.c [new file with mode: 0644]

index 3c8effb88de95558639b5b524d293babf97e24d9..fe1d9e937550c120cd21df23b3dd92b4bf3bd152 100644 (file)
@@ -1,3 +1,9 @@
+2016-07-14  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
+
+       PR tree-optimization/81162
+       * gimple-ssa-strength-reduction.c (replace_mult_candidate): Don't
+       replace a negate with an add.
+
 2017-07-14  James Greenhalgh  <james.greenhalgh@arm.com>
 
        * doc/invoke.texi (arm/-mcpu): Document +crypto.
index dc2cb469d6c5bd45cfff9c1e1469a9894e58732c..00c304447002321e6d399003a933f2a953e80ba1 100644 (file)
@@ -2082,13 +2082,14 @@ replace_mult_candidate (slsr_cand_t c, tree basis_name, widest_int bump)
      types but allows for safe negation without twisted logic.  */
   if (wi::fits_shwi_p (bump)
       && bump.to_shwi () != HOST_WIDE_INT_MIN
-      /* It is not useful to replace casts, copies, or adds of
+      /* It is not useful to replace casts, copies, negates, or adds of
         an SSA name and a constant.  */
       && cand_code != SSA_NAME
       && !CONVERT_EXPR_CODE_P (cand_code)
       && cand_code != PLUS_EXPR
       && cand_code != POINTER_PLUS_EXPR
-      && cand_code != MINUS_EXPR)
+      && cand_code != MINUS_EXPR
+      && cand_code != NEGATE_EXPR)
     {
       enum tree_code code = PLUS_EXPR;
       tree bump_tree;
index aa4fb1de2932f6bae541d81d2707fdea9a734fb8..073a8e5d62f06bb221eebfc3ca50b872073dc08d 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-14  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
+
+       PR tree-optimization/81162
+       * gcc.dg/pr81162.c: New file.
+
 2017-07-14  Martin Sebor  <msebor@redhat.com>
 
        * gcc.dg/tree-ssa/ssa-dse-30.c: Correct test to look for memmove
diff --git a/gcc/testsuite/gcc.dg/pr81162.c b/gcc/testsuite/gcc.dg/pr81162.c
new file mode 100644 (file)
index 0000000..9ce98af
--- /dev/null
@@ -0,0 +1,17 @@
+/* PR tree-optimization/81162 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined -O2" } */
+
+short s;
+int i1 = 1;
+int i2 = 1;
+unsigned char uc = 147;
+
+int main() {
+  s = (-uc + 2147483647) << 0;
+  if (9031239389974324562ULL >= (-((i1 && i2) + uc) ^ -21096) ) {
+    return 0;
+  } else {
+    return -1;
+  }
+}