gnu/gcc/2fcbe075ec3b32f4a523ebae68a8a32381bb46a9 tree-optimization/126171 - SCEV and minus of INT_MIN
The following fixes the existing mitigation against UB for handling
of subtraction of the most negative value in a type. We've only
guarded the negation itself which is effective for avoiding UB in
that but it does not help in fixing a wrong scev_direction that
results from flipping the operation from minus to plus. So the
patch, instead of only promoting the negation to unsigned, promotes
the whole operation.
PR tree-optimization/126171
* tree-scalar-evolution.cc (scev_dfs::add_to_evolution):
Remove code argument. Remove MINUS_EXPR handling here.
(scev_dfs::follow_ssa_edge_binary): Likewise.
(scev_dfs::follow_ssa_edge_expr): Handle MINUS_EXPR
separately here, promoting the whole operation to unsigned
instead of just the addend.
* gcc.dg/pr126171-1.c: New testcase.
* gcc.dg/torture/pr126171-2.c: Likewise.
3 files changed