llvm-project
24146ce5 - [TargetLowering] Remove INT_MIN special case from prepareSREMEqFold. (#188653)

Commit
11 days ago
[TargetLowering] Remove INT_MIN special case from prepareSREMEqFold. (#188653) If the divisor is INT_MIN, we can still treat it like any other power of 2. We'll fold i32 (seteq (srem X, INT_MIN)) to (setule (rotr (add (mul X, 1), INT_MIN), 31), 1). Alive2 says this is correct https://alive2.llvm.org/ce/z/vjzqKk. The multiply is a NOP, the add toggles the sign bits. The rotate puts the lowest 31 bits of into the upper 31 bits. The sign bit is now in the LSB. The compare checks if the upper 31 bits are 0. srem X, INT_MIN has a remainder of 0 if X is 0 or INT_MIN which is equivalent to checking if the uppper 31 bits are 0 after the rotate. I don't think we need to add any constant for power of 2 but toggling the sign bit like we do now doesn't hurt.
Author
Parents
Loading