Case 7 of unsigned scalar saturating addition defines
SAT_ADD = X <= (X + Y) ? (X + Y) : -1. This is the same as
SAT_ADD = Y <= (X + Y) ? (X + Y) : -1 due to usadd_left_part_1
being commutative.

The pattern for case 7 currently does not accept the alternative
where Y is used in the condition. Therefore, this commit adds the
commutative property to this case which causes more valid cases of
unsigned saturating arithmetic to be recognised.

Before:
 <bb 2>
 _1 = BIT_FIELD_REF <b_3(D), 8, 0>;
 sum_5 = _1 + a_4(D);
 if (a_4(D) <= sum_5)
   goto <bb 4>; [INV]
 else
   goto <bb 3>; [INV]

 <bb 3> :

 <bb 4> :
 _2 = PHI <255(3), sum_5(2)>
 return _2;

After:
  <bb 2> [local count: 1073741824]:
  _1 = BIT_FIELD_REF <b_3(D), 8, 0>;
  _2 = .SAT_ADD (_1, a_4(D)); [tail call]
  return _2;

This passes the aarch64-none-linux-gnu regression tests with no new
failures.

gcc/ChangeLog:

        * match.pd: Modify existing case for SAT_ADD.
---
 gcc/match.pd | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 4fc5efa6247..a77fca92181 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3166,7 +3166,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* Unsigned saturation add, case 7 (branch with le):
    SAT_ADD = x <= (X + Y) ? (X + Y) : -1.  */
 (match (unsigned_integer_sat_add @0 @1)
- (cond^ (le @0 (usadd_left_part_1@2 @0 @1)) @2 integer_minus_onep))
+ (cond^ (le @0 (usadd_left_part_1:c@2 @0 @1)) @2 integer_minus_onep))
 
 /* Unsigned saturation add, case 8 (branch with gt):
    SAT_ADD = x > (X + Y) ? -1 : (X + Y).  */
-- 
2.34.1

Reply via email to