@@ -3157,6 +3157,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(simplify (cond (le @0 (plus:c@2 @0 @1)) @2 integer_minus_onep)
(if (types_match (type, @0, @1))
(bit_ior (plus@2 @0 @1) (negate (convert (lt @2 @0))))))
+ /* From SAT_ADD = x > (X + Y) ? -1 : (X + Y). */
+ (simplify (cond (gt @0 (plus:c@2 @0 @1)) integer_minus_onep @2)
+ (if (types_match (type, @0, @1))
+ (bit_ior (plus@2 @0 @1) (negate (convert (lt @2 @0))))))
/* From SAT_U_ADD = (X + Y) < x ? -1 : (X + Y). */
(simplify (cond (lt (plus:c@2 @0 @1) @0) integer_minus_onep @2)
(if (types_match (type, @0, @1))
@@ -3174,11 +3178,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 8 (branch with gt):
- SAT_ADD = x > (X + Y) ? -1 : (X + Y). */
-(match (unsigned_integer_sat_add @0 @1)
- (cond^ (gt @0 (usadd_left_part_1@2 @0 @1)) integer_minus_onep @2))
-
/* Unsigned saturation add, case 9 (one op is imm):
SAT_U_ADD = (X + 3) >= x ? (X + 3) : -1. */
(match (unsigned_integer_sat_add @0 @1)
@@ -13,4 +13,10 @@ T sat_u_add_##T##_3 (T x, T y) \
return x <= (T)(x + y) ? (x + y) : -1; \
}
+#define DEF_SAT_U_ADD_4(T) \
+T sat_u_add_##T##_4 (T x, T y) \
+{ \
+ return x > (T)(x + y) ? -1 : (x + y); \
+}
+
#endif
new file mode 100644
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-gimple-details" } */
+
+#include <stdint.h>
+#include "sat_arith_simplify.h"
+
+DEF_SAT_U_ADD_4 (uint16_t)
+
+/* { 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,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-gimple-details" } */
+
+#include <stdint.h>
+#include "sat_arith_simplify.h"
+
+DEF_SAT_U_ADD_4 (uint32_t)
+
+/* { 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,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-gimple-details" } */
+
+#include <stdint.h>
+#include "sat_arith_simplify.h"
+
+DEF_SAT_U_ADD_4 (uint64_t)
+
+/* { 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,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-gimple-details" } */
+
+#include <stdint.h>
+#include "sat_arith_simplify.h"
+
+DEF_SAT_U_ADD_4 (uint8_t)
+
+/* { dg-final { scan-tree-dump-not " if " "gimple" } } */
+/* { dg-final { scan-tree-dump-not " else " "gimple" } } */
+/* { dg-final { scan-tree-dump-not " goto " "gimple" } } */