[X86] Invert transforming `(x * (Pow2_Ceil(C1) - (1 << C0))) & C1` -> `(-x << C0) & C1`
We can detect the case under the following circumstances: Take `(Pow2_Ceil(C1) - (1 << C0))` as `C2`. 1) `C2` is NOT a power of 2. 2) `C2 + LeastSignificantBit(C2)` is a nonzero power of 2. 3) `C2 u>= C1` The motivation is the middle end transforms: `(-x << C0) & C1` to `(x * (Pow2_Ceil(C1) - (1 << C2))) & C1` As it saves IR instructions. On X86 the two instruction, `sub` and `shl`, and better than the `mul` so we want to undo the transform. This comes up when shifting a bit-mask by a byte-misalignment i.e: `y << ((-(uintptr)x * 8) & 63)` Alive2 Proofs (including all cases with undefs in the vector): https://alive2.llvm.org/ce/z/f-65b6 Reviewed By: RKSimon, pengfei Differential Revision: https://reviews.llvm.org/D150294
Loading
Please sign in to comment