This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
 /* 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))
   (minus (convert @0) (convert @1))))

(gdb) p debug_generic_expr (captures[1])
(unsigned int) b
$9 = void
(gdb) p debug_generic_expr (captures[0])
c

so that results in c + (int)-(unsigned)b -> c - (int)(unsigned)b.  Similar
code was in tree-ssa-forwprop.c before but that didn't trigger for the testcase
because we first constant propagated.

> gcc-4.8 t.c -O2 -fdisable-tree-ccp1
> ./a.out
Aborted (core dumped)

so probably latent since quite some time.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]