]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
match: Move `(cmp (cond @0 @1 @2) @3)` simplification after the bool compare simplifc...
authorAndrew Pinski <quic_apinski@quicinc.com>
Tue, 22 Apr 2025 22:13:39 +0000 (15:13 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Fri, 25 Apr 2025 18:31:15 +0000 (11:31 -0700)
This moves the `(cmp (cond @0 @1 @2) @3)` simplifcation to be after the boolean comparison
simplifcations so that we don't end up simplifing into the same thing for a GIMPLE_COND.

gcc/ChangeLog:

* match.pd: Move `(cmp (cond @0 @1 @2) @3)` simplifcation after
the bool comparison simplifications.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/match.pd

index ba036e528370a19ebc76aaa41f28eb082bdb2515..0fe90a6edc46302ebb2c1f632010ea4e0447aba7 100644 (file)
@@ -7759,20 +7759,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (cmp (bit_and@2 @0 integer_pow2p@1) @1)
   (icmp @2 { build_zero_cst (TREE_TYPE (@0)); })))
 
-#if GIMPLE
-/* From fold_binary_op_with_conditional_arg handle the case of
-   rewriting (a ? b : c) > d to a ? (b > d) : (c > d) when the
-   compares simplify.  */
-(for cmp (simple_comparison)
- (simplify
-  (cmp:c (cond @0 @1 @2) @3)
-  /* Do not move possibly trapping operations into the conditional as this
-     pessimizes code and causes gimplification issues when applied late.  */
-  (if (!FLOAT_TYPE_P (TREE_TYPE (@3))
-       || !operation_could_trap_p (cmp, true, false, @3))
-   (cond @0 (cmp! @1 @3) (cmp! @2 @3)))))
-#endif
-
 (for cmp (ge lt)
 /* x < 0 ? ~y : y into (x >> (prec-1)) ^ y. */
 /* x >= 0 ? ~y : y into ~((x >> (prec-1)) ^ y). */
@@ -8119,6 +8105,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    replace if (x == 0) with tem = ~x; if (tem != 0) which is
    clearly less optimal and which we'll transform again in forwprop.  */
 
+#if GIMPLE
+/* From fold_binary_op_with_conditional_arg handle the case of
+   rewriting (a ? b : c) > d to a ? (b > d) : (c > d) when the
+   compares simplify.
+   This should be after the boolean comparison simplification so
+   that it can remove the outer comparison before appling it to
+   the inner condtional operands.  */
+(for cmp (simple_comparison)
+ (simplify
+  (cmp:c (cond @0 @1 @2) @3)
+  /* Do not move possibly trapping operations into the conditional as this
+     pessimizes code and causes gimplification issues when applied late.  */
+  (if (!FLOAT_TYPE_P (TREE_TYPE (@3))
+       || !operation_could_trap_p (cmp, true, false, @3))
+   (cond @0 (cmp! @1 @3) (cmp! @2 @3)))))
+#endif
+
 /* Transform comparisons of the form (X & Y) CMP 0 to X CMP2 Z
    where ~Y + 1 == pow2 and Z = ~Y.  */
 (for cst (VECTOR_CST INTEGER_CST)