re PR tree-optimization/24574 (a!=0?a/10:0 is not reduced to a/10)
authorRichard Biener <rguenther@suse.de>
Wed, 13 Jul 2016 13:57:05 +0000 (13:57 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 13 Jul 2016 13:57:05 +0000 (13:57 +0000)
2016-07-13  Richard Biener  <rguenther@suse.de>

PR tree-optimization/24574
* tree-ssa-phiopt.c (absorbing_element_p): Pass in argument
position and add shift, rotate, divison and modulo support
for left zero.
(value_replacement): Pass in argument position to absorbing_element_p.

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

From-SVN: r238299

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

index 03dac3322bdf280f5a255c2f215cb5a82bb8e750..cd416b7d8e9646333158c1ed0a785f120b110323 100644 (file)
@@ -1,3 +1,11 @@
+2016-07-13  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/24574
+       * tree-ssa-phiopt.c (absorbing_element_p): Pass in argument
+       position and add shift, rotate, divison and modulo support
+       for left zero.
+       (value_replacement): Pass in argument position to absorbing_element_p.
+
 2016-07-13  Ilya Enkovich  <ilya.enkovich@intel.com>
 
        PR ipa/71633
index bccd0d8e9564746ecdb5f73d0abcf85443f47700..92a7cb63ebf94000091af9a939ce7b321085c702 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-13  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/24574
+       * gcc.dg/pr24574.c: New testcase.
+
 2016-07-13  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>
 
        * c-c++-common/Wduplicated-cond-3.c (fn10): Use smaller 
diff --git a/gcc/testsuite/gcc.dg/pr24574.c b/gcc/testsuite/gcc.dg/pr24574.c
new file mode 100644 (file)
index 0000000..db0d869
--- /dev/null
@@ -0,0 +1,36 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-phiopt1" } */
+
+int f0(int i)
+{
+  if (i == 0) return 0;
+  return i/10;
+}
+int f1(int i)
+{
+  return i?i/10:0;
+}
+
+int f2(int i)
+{
+  if (i == 0) return 0;
+  return i%10;
+}
+int f3(int i)
+{
+  return i?i%10:0;
+}
+
+int f4(int i)
+{
+  if (i == 0) return 0;
+  return i<<10;
+}
+int f5(int i)
+{
+  return i?i<<10:0;
+}
+
+/* We should if-convert all functions to carry out the operation
+   unconditionally.  */
+/* { dg-final { scan-tree-dump-not "= PHI" "phiopt1" } } */
index caf591bc529fd123726a37d5f9b6c4040319d540..dd9aa0195fad67aaf902a5c9014c951838a3fe8f 100644 (file)
@@ -812,7 +812,7 @@ neutral_element_p (tree_code code, tree arg, bool right)
 /* Returns true if ARG is an absorbing element for operation CODE.  */
 
 static bool
-absorbing_element_p (tree_code code, tree arg)
+absorbing_element_p (tree_code code, tree arg, bool right)
 {
   switch (code)
     {
@@ -823,6 +823,21 @@ absorbing_element_p (tree_code code, tree arg)
     case BIT_AND_EXPR:
       return integer_zerop (arg);
 
+    case LSHIFT_EXPR:
+    case RSHIFT_EXPR:
+    case LROTATE_EXPR:
+    case RROTATE_EXPR:
+    case TRUNC_DIV_EXPR:
+    case CEIL_DIV_EXPR:
+    case FLOOR_DIV_EXPR:
+    case ROUND_DIV_EXPR:
+    case EXACT_DIV_EXPR:
+    case TRUNC_MOD_EXPR:
+    case CEIL_MOD_EXPR:
+    case FLOOR_MOD_EXPR:
+    case ROUND_MOD_EXPR:
+      return !right && integer_zerop (arg);
+
     default:
       return false;
     }
@@ -994,9 +1009,10 @@ value_replacement (basic_block cond_bb, basic_block middle_bb,
              && operand_equal_for_phi_arg_p (rhs1, cond_lhs)
              && neutral_element_p (code_def, cond_rhs, false))
          || (operand_equal_for_phi_arg_p (arg1, cond_rhs)
-             && (operand_equal_for_phi_arg_p (rhs2, cond_lhs)
-                 || operand_equal_for_phi_arg_p (rhs1, cond_lhs))
-             && absorbing_element_p (code_def, cond_rhs))))
+             && ((operand_equal_for_phi_arg_p (rhs2, cond_lhs)
+                  && absorbing_element_p (code_def, cond_rhs, true))
+                 || (operand_equal_for_phi_arg_p (rhs1, cond_lhs)
+                     && absorbing_element_p (code_def, cond_rhs, false))))))
     {
       gsi = gsi_for_stmt (cond);
       if (INTEGRAL_TYPE_P (TREE_TYPE (lhs)))