[PATCH] D150294: [X86] Transforming `(x*C0)&C1`->`(-x<<log2(C0&(-C0)))&C1`; NFC
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 10 13:10:26 PDT 2023
goldstein.w.n created this revision.
goldstein.w.n added reviewers: RKSimon, pengfei.
Herald added a subscriber: hiraditya.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is valid under the following circumstances:
1. `C0` is NOT a power of 2.
2. `C0 + (C0 & (-C0))` is a nonzero power of 2.
3. `C0 u>= C1`
The motivation is the middle end transforms:
`(-x << C2) & 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 wan't 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
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D150294
Files:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/undo-mul-and.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150294.521081.patch
Type: text/x-patch
Size: 11456 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230510/d63a842c/attachment.bin>
More information about the llvm-commits
mailing list