[Bug tree-optimization/80281] [5/6/7 Regression] Wrong constant folding

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Apr 3 07:52:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80281

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
We need to keep the type of the negation, thus

 c + (int)-(unsigned)b  ->  (int)((unsigned) c - (unsigned) b)

 /* A + (-B) -> A - B */
 (simplify
  (plus:c (convert1? @0) (convert2? (negate @1)))
  /* Apply STRIP_NOPS on @0 and the negate.  */
  (if (tree_nop_conversion_p (type, TREE_TYPE (@0))
       && tree_nop_conversion_p (type, TREE_TYPE (@1))
       && !TYPE_OVERFLOW_SANITIZED (type))
   (with { tree t1 = TREE_TYPE (@1); }
    (convert (minus (convert:t1 @0) @1)))))


More information about the Gcc-bugs mailing list