re PR tree-optimization/66726 (missed optimization, factor conversion out of COND_EXPR)
authorJoern Rennecke <joern.rennecke@riscy-ip.com>
Mon, 1 Jul 2019 21:48:55 +0000 (21:48 +0000)
committerJoern Rennecke <amylaar@gcc.gnu.org>
Mon, 1 Jul 2019 21:48:55 +0000 (22:48 +0100)
        PR middle-end/66726
        * tree-ssa-phiopt.c (factor_out_conditional_conversion):
        Tune heuristic from PR71016 to allow MIN / MAX.
        * testsuite/gcc.dg/tree-ssa/pr66726-4.c: New testcase.

From-SVN: r272911

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

index 4e80c34e8aeee523bbcd795c58cb12bda8a0eec6..dad3442b9497429947716d1089263e4ded2f20da 100644 (file)
@@ -1,3 +1,10 @@
+2019-07-01  Joern Rennecke  <joern.rennecke@riscy-ip.com>
+
+       PR middle-end/66726
+       * tree-ssa-phiopt.c (factor_out_conditional_conversion):
+       Tune heuristic from PR71016 to allow MIN / MAX.
+       * testsuite/gcc.dg/tree-ssa/pr66726-4.c: New testcase.
+
 2019-07-01  Segher Boessenkool  <segher@kernel.crashing.org>
 
        * config/rs6000/rs6000.md (ieee_128bit_vsx_abs<mode>2): Make this a
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr66726-4.c b/gcc/testsuite/gcc.dg/tree-ssa/pr66726-4.c
new file mode 100644 (file)
index 0000000..4e43522
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-phiopt1-details" } */
+
+#define SAT(x) (x < 0 ? 0 : (x > 255 ? 255 : x))
+
+void
+foo (unsigned char *p, int i)
+{
+  *p = SAT (i);
+}
+
+/* { dg-final { scan-tree-dump-times "COND_EXPR .*and PHI .*converted to straightline code" 1 "phiopt1" } } */
index 90674a2f3c49a852b208daf032b2934c343c45be..7088ff9199882c34d8e0db1dbdab1850c9e460d0 100644 (file)
@@ -504,7 +504,24 @@ factor_out_conditional_conversion (edge e0, edge e1, gphi *phi,
                  gsi = gsi_for_stmt (arg0_def_stmt);
                  gsi_prev_nondebug (&gsi);
                  if (!gsi_end_p (gsi))
-                   return NULL;
+                   {
+                     if (gassign *assign
+                           = dyn_cast <gassign *> (gsi_stmt (gsi)))
+                       {
+                         tree lhs = gimple_assign_lhs (assign);
+                         enum tree_code ass_code
+                           = gimple_assign_rhs_code (assign);
+                         if (ass_code != MAX_EXPR && ass_code != MIN_EXPR)
+                           return NULL;
+                         if (lhs != gimple_assign_rhs1 (arg0_def_stmt))
+                           return NULL;
+                         gsi_prev_nondebug (&gsi);
+                         if (!gsi_end_p (gsi))
+                           return NULL;
+                       }
+                     else
+                       return NULL;
+                   }
                  gsi = gsi_for_stmt (arg0_def_stmt);
                  gsi_next_nondebug (&gsi);
                  if (!gsi_end_p (gsi))