===================================================================
@@ -1153,7 +1153,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (tree_nop_conversion_p (type, TREE_TYPE (@0))
&& tree_nop_conversion_p (type, TREE_TYPE (@1))
&& !TYPE_OVERFLOW_SANITIZED (type))
- (minus (convert @0) (convert @1))))
+ (with
+ {
+ tree t1 = type;
+ if (INTEGRAL_TYPE_P (type)
+ && TYPE_OVERFLOW_WRAPS (type) != TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1)))
+ t1 = TYPE_OVERFLOW_WRAPS (type) ? type : TREE_TYPE (@1);
+ }
+ (convert (minus (convert:t1 @0) (convert:t1 @1))))))
/* A - (-B) -> A + B */
(simplify
(minus (convert1? @0) (convert2? (negate @1)))
===================================================================
@@ -831,8 +831,12 @@ split_tree (location_t loc, tree in, tre
/* Now do any needed negations. */
if (neg_litp_p)
*minus_litp = *litp, *litp = 0;
- if (neg_conp_p)
- *conp = negate_expr (*conp);
+ if (neg_conp_p && *conp)
+ {
+ /* Convert to TYPE before negating. */
+ *conp = fold_convert_loc (loc, type, *conp);
+ *conp = negate_expr (*conp);
+ }
if (neg_var_p && var)
{
/* Convert to TYPE before negating. */
@@ -859,7 +863,12 @@ split_tree (location_t loc, tree in, tre
*minus_litp = *litp, *litp = 0;
else if (*minus_litp)
*litp = *minus_litp, *minus_litp = 0;
- *conp = negate_expr (*conp);
+ if (*conp)
+ {
+ /* Convert to TYPE before negating. */
+ *conp = fold_convert_loc (loc, type, *conp);
+ *conp = negate_expr (*conp);
+ }
if (var)
{
/* Convert to TYPE before negating. */
===================================================================
@@ -0,0 +1,14 @@
+/* { dg-run } */
+/* { dg-require-effective-target int32plus } */
+
+int
+main ()
+{
+ volatile int a = 0;
+ long long b = 2147483648LL;
+ int c = a % 2;
+ int x = ((int) -b + c) % -2147483647;
+ if (x != -1)
+ __builtin_abort ();
+ return 0;
+}