(cond (eq @0 integer_all_onesp) @1 (op:c@2 @1 @0))
@2))
+/* a != 0 ? a / b : 0 -> a / b iff b is nonzero. */
+(for op (trunc_div ceil_div floor_div round_div exact_div)
+ (simplify
+ (cond (ne @0 integer_zerop) (op@2 @3 @1) integer_zerop )
+ (if (bitwise_equal_p (@0, @3)
+ && tree_expr_nonzero_p (@1))
+ @2)))
+
+/* Note we prefer the != case here
+ as (a != 0) * (a * b) will generate that version. */
+/* a != 0 ? a * b : 0 -> a * b */
+/* a != 0 ? a & b : 0 -> a & b */
+(for op (mult bit_and)
+ (simplify
+ (cond (ne @0 integer_zerop) (op:c@2 @1 @3) integer_zerop)
+ (if (bitwise_equal_p (@0, @3))
+ @2)))
+
/* Simplifications of shift and rotates. */
(for rotate (lrotate rrotate)
--- /dev/null
+/* { dg-do compile } */
+/* PR treee-optimization/114894 */
+/* Phi-OPT should be able to optimize these without sinking being invoked. */
+/* { dg-options "-O -fdump-tree-phiopt2 -fdump-tree-phiopt3 -fdump-tree-optimized -fno-tree-sink" } */
+
+int fmul1(int a, int b)
+{
+ int c = a * b;
+ if (a != 0)
+ return c;
+ return 0;
+}
+
+
+int fand1(int a, int b)
+{
+ int c = a & b;
+ if (a != 0)
+ return c;
+ return 0;
+}
+
+
+void g(int);
+
+int fdiv1(int a, int b)
+{
+ int d = b|1;
+ g(d);
+ int c = a / d;
+ return a != 0 ? c : 0;
+}
+
+/* fdiv1 requires until later than phiopt2 to be able to detect that
+ d is non-zero. to be able to remove the conditional. */
+/* { dg-final { scan-tree-dump-times "goto" 2 "phiopt2" } } */
+/* { dg-final { scan-tree-dump-not "goto" "phiopt3" } } */
+/* { dg-final { scan-tree-dump-not "goto" "optimized" } } */
+