SCEV not simplifying

I have a pair of SCEVs that appear different to me.
However, when I compute the difference, it’s not known to be non-zero.

src = (sext i32 %n to i64)
dst = (sext i32 (1 + %n) to i64)
delta = ((sext i32 %n to i64) + (-1 * (sext i32 (1 + %n) to i64)))

Is this behavior expected?

If I repeat the experiment with 64-bit ints (or unsigned),
things work out like I expect. 32-bit unsigned is also bad.

Thanks,
Preston

Hi,

So SCEV cannot simplify that expression to -1 because of overflow issues (take e.g. src=0x7FFF..).
If you compile with 64 bits integers, then the sexts disappear and so SCEV can do the simplification.
Depending on what you want to do, you may want to either do not extend src and dst to 64 bits or add a NSW flag to the computations. That will hopefully make SCEV push the sext outside and then perform the simplification. You can also take a look at ScalarEvolution::SimplifyICmpOperands().

Nuno

Hi,

I don’t mind the expression not being simplified (incorrectly!) to -1, but I was hoping that the package would be clever enough to recognize that the expression wasn’t zero.

Thanks for the ideas about other approaches.

Preston