[llvm] [X86] Prefer andl to andb to save one byte encoding when using with bzhi or bextr (PR #86921)

Phoebe Wang via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 15 23:22:38 PDT 2024


phoebewang wrote:

> I'm still not sure this is the best place to implement this, if we really want it (I defer to others on this). The optimization seems general enough to me for it to live in this specific place and I'm not sure we can guarantee that other optimizations don't produce similar code and needs similar fix ups. Aren't there any sort of peephole x86 machine passes that swap instructions with equivalent acting on smaller sizes to save on size?

AFAIk, We have 3 classes of size optimizations on X86:

- EVEX to VEX/legacy encoding compress doing in a machine pass, see X86CompressEVEX.cpp;
- Miscellaneous compress doing in MCInst lowering, see X86EncodingOptimization.cpp;
- Specific compress doing in Instruction selection, see [X86InstrShiftRotate.td](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/X86/X86InstrShiftRotate.td#L242-L300);

You can see we optimize them differently for different cases.
Here what we do is similar to class 3. We do it specially for bzhi/bextr, because:

- As @topperc pointed, it is not a general optimization;
- As I mentioned above, it is considered beneficial for bzhi/bextr, which matches with GCC;

Does it sound more reasonable?

https://github.com/llvm/llvm-project/pull/86921


More information about the llvm-commits mailing list