@@ -3154,6 +3154,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& types_match (type, @0, @1))
(bit_ior @2 (negate (convert (lt @2 @0))))))
+/* Simplify SAT_U_ADD to the cheap form
+ From: SAT_U_ADD = x <= (X + Y) ? (X + Y) : -1.
+ To: SAT_U_ADD = (X + Y) | - ((X + Y) < X). */
+(simplify (cond (le @0 (plus:c@2 @0 @1)) @2 integer_minus_onep)
+ (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
+ && types_match (type, @0, @1))
+ (bit_ior @2 (negate (convert (lt @2 @0))))))
+
/* Simplify SAT_U_ADD to the cheap form
From: SAT_U_ADD = (X + Y) < x ? -1 : (X + Y).
To: SAT_U_ADD = (X + Y) | - ((X + Y) < X). */
@@ -3174,11 +3182,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(cond^ (ne (imagpart (IFN_ADD_OVERFLOW:c @0 @1)) integer_zerop)
integer_minus_onep (usadd_left_part_2 @0 @1)))
-/* 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))
-
/* Unsigned saturation add, case 8 (branch with gt):
SAT_ADD = x > (X + Y) ? -1 : (X + Y). */
(match (unsigned_integer_sat_add @0 @1)
new file mode 100644
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-gimple-details" } */
+
+#include <stdint.h>
+
+#define T uint16_t
+
+T sat_add_u_1 (T x, T y)
+{
+ return x <= (T)(x + y) ? (x + y) : -1;
+}
+
+/* { dg-final { scan-tree-dump-not " if " "gimple" } } */
+/* { dg-final { scan-tree-dump-not " else " "gimple" } } */
+/* { dg-final { scan-tree-dump-not " goto " "gimple" } } */
new file mode 100644
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-gimple-details" } */
+
+#include <stdint.h>
+
+#define T uint32_t
+
+T sat_add_u_1 (T x, T y)
+{
+ return x <= (T)(x + y) ? (x + y) : -1;
+}
+
+/* { dg-final { scan-tree-dump-not " if " "gimple" } } */
+/* { dg-final { scan-tree-dump-not " else " "gimple" } } */
+/* { dg-final { scan-tree-dump-not " goto " "gimple" } } */
new file mode 100644
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-gimple-details" } */
+
+#include <stdint.h>
+
+#define T uint32_t
+
+T sat_add_u_1 (T x, T y)
+{
+ return x <= (T)(x + y) ? (x + y) : -1;
+}
+
+/* { dg-final { scan-tree-dump-not " if " "gimple" } } */
+/* { dg-final { scan-tree-dump-not " else " "gimple" } } */
+/* { dg-final { scan-tree-dump-not " goto " "gimple" } } */
new file mode 100644
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-gimple-details" } */
+
+#include <stdint.h>
+
+#define T uint8_t
+
+T sat_add_u_1 (T x, T y)
+{
+ return x <= (T)(x + y) ? (x + y) : -1;
+}
+
+/* { dg-final { scan-tree-dump-not " if " "gimple" } } */
+/* { dg-final { scan-tree-dump-not " else " "gimple" } } */
+/* { dg-final { scan-tree-dump-not " goto " "gimple" } } */