HomePhabricator

[InstructionSimplify] icmp (X+Y), (X+Z) simplification

Authored by SjoerdMeijer on Oct 21 2020, 3:06 AM.

Description

[InstructionSimplify] icmp (X+Y), (X+Z) simplification

This improves simplifications for pattern icmp (X+Y), (X+Z) -> icmp Y,Z
if only one of the operands has NSW set, e.g.:

icmp slt (x + 0), (x +nsw 1)

We can still safely rewrite this to:

icmp slt 0, 1

because we know that the LHS can't overflow if the RHS has NSW set and
C1 < C2 && C1 >= 0, or C2 < C1 && C1 <= 0

This simplification is useful because ScalarEvolutionExpander which is used to
generate code for SCEVs in different loop optimisers is not always able to put
back NSW flags across control-flow, thus inhibiting CFG simplifications.

Differential Revision: https://reviews.llvm.org/D89317

Details