@@ -3096,6 +3096,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(match (unsigned_integer_sat_add @0 @1)
(bit_ior:c (usadd_left_part_2 @0 @1) (usadd_right_part_2 @0 @1)))
+#if GIMPLE
+
+/* Simplify the branch version of SAT_ADD into branchless if and only if
+ the backend has supported the IFN_SAT_ADD. Thus, the backend has the
+ ability to choose branch or branchless implementation of .SAT_ADD. */
+
+(simplify
+ (cond (ge (plus:c@2 @0 @1) @0) @2 integer_minus_onep)
+ (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED (type)
+ && direct_internal_fn_supported_p (IFN_SAT_ADD, type, OPTIMIZE_FOR_BOTH))
+ (bit_ior @2 (negate (convert (lt @2 @0))))))
+
+(simplify
+ (cond (le @0 (plus:c@2 @0 @1)) @2 integer_minus_onep)
+ (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED (type)
+ && direct_internal_fn_supported_p (IFN_SAT_ADD, type, OPTIMIZE_FOR_BOTH))
+ (bit_ior @2 (negate (convert (lt @2 @0))))))
+
+#endif
+
/* x > y && x != XXX_MIN --> x > y
x > y && x == XXX_MIN --> false . */
(for eqne (eq ne)