[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
Tue Apr 16 01:10:47 PDT 2024


phoebewang wrote:

> > > > * As I mentioned above, it is considered beneficial for bzhi/bextr, which matches with GCC;
> > > 
> > > 
> > > It's been a long time since I looked, but I thought gcc generally avoids 8 bit registers. Not just for bzhi/bextr.
> > 
> > 
> > Do you have an example in mind, I did some simple experiment, the Clang code generation looks good to me https://godbolt.org/z/6h3W348WM
> 
> gcc uses %eax, clang uses %al https://godbolt.org/z/vfbezP9ac but like I said its been a long time since I looked at this. My recollection was that gcc promotes more operations to 32-bit registers than clang. I long ago thought maybe we should promote i8 to i32 like we do i16 through IsDesirableToPromoteOp.

Thanks @topperc for the point! i16 has more benefits compared to i8 https://godbolt.org/z/d1ofbTros
For i8, the benefits depends on the frequency of AL vs. SIL/DIL/BPL/SPL, though the latter has 4, but I think AL should have more frequency in practice, not to mention the H register case. So, I think we don't need to apply i8 to general cases.

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


More information about the llvm-commits mailing list