[LLVMdev] Instruction combiner multiplication canonicalization
Sanjoy Das
sanjoy at playingwithpointers.com
Wed Apr 15 10:13:00 PDT 2015
> Consider following scenarios:
> 1) If input is ((X+C1)*C2)<nsw>
> Then post canonicalization output should be (X*C2+C1*C2) <nsw>
Say X = INT_SMAX, C1 = C2 = 1.
Then (X + C1) = INT_SMIN and INT_SMIN * 1 does not overflow.
But X*C2 = INT_SMAX and C1*C2 = 1 and INT_SMAX + 1 does sign overflow.
> 2) If input is (((X+C1)<nsw>)*C2)<nsw>
> Then post canonicalization output should be ((X*C2) <nsw>+(C1*C2) <nsw>)
> <nsw>
This is more interesting, let X = INT_SMIN, C1 = 1, C2 -1.
Then the first set of operations don't sign overflow. But X * C2 =
INT_SMIN * -1 will sign overflow
-- Sanjoy
More information about the llvm-dev
mailing list