On Mon, 3 Apr 2017, Richard Biener wrote:

--- gcc/match.pd        (revision 246642)
+++ gcc/match.pd        (working copy)
@@ -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))))))

Why do we match
(plus:c (convert1? @0) (convert2? (negate @1)))
instead of the simpler
(plus:c @0 (convert? (negate @1)))

 /* A - (-B) -> A + B */

Actually, I believe this transformation has issues as well, it seems possible to transform X-INT_MIN into X+INT_MIN if INT_MIN comes as (int)(-(unsigned)INT_MIN).

--
Marc Glisse

Reply via email to