Hello,
While looking at some internal benchmarks, I found that llvm generates codes with redundant promotion, something like:
xor %al, %cl
movzbl %cl, %ecx
cmp $0x20, %ecx
I believe that the promotion stems from the logic in X86TargetLowering::EmitCmp. Comments in the code says,
“Do the comparison at i32 if it’s smaller, besides the Atom case. This avoids subregister aliasing issues. Keep the smaller reference if we’re optimizing for size, however, as that’ll allow better folding of memory operations.”
Can anybody please explain me more in detail about the subregister aliasing issues?
Thanks,
Taewook
Hi Taewook -
There’s a discussion about the underlying x86 micro-arch details here:
http://comments.gmane.org/gmane.comp.compilers.llvm.cvs/167221
The conclusion was that we should change how we currently handle these, but we don’t want to regress the case that was addressed by:
http://reviews.llvm.org/rL195496
There are open bugs with more discussion related to this:
https://llvm.org/bugs/show_bug.cgi?id=17113
https://llvm.org/bugs/show_bug.cgi?id=22473
https://llvm.org/bugs/show_bug.cgi?id=22532
https://llvm.org/bugs/show_bug.cgi?id=23155 (cc’ing Kevin in case there’s any update on this one)
This is an excerpt from Chandler’s comment in https://llvm.org/bugs/show_bug.cgi?id=22473
Ø We need to add a pass that replaces movb (and movw) with movzbl (and movzwl) when the destination is a register and the high bytes aren’t used.
I have created such a pass, and have it working in a local workspace of mine. However, I think that the way it attempts to prove that the high bytes aren’t
used is flawed, and so I haven’t yet submitted it for community review.
Kevin
This is an excerpt from Chandler’s comment in https://llvm.org/bugs/show_bug.cgi?id=22473
Ø We need to add a pass that replaces movb (and movw) with movzbl (and movzwl) when the destination is a register and the high bytes aren’t used.
I have created such a pass, and have it working in a local workspace of mine. However, I think that the way it attempts to prove that the high bytes aren’t
used is flawed, and so I haven’t yet submitted it for community review.
Kevin
Yes, I am still working on it. I believe I have it conservatively correct. I suppose I should just go ahead and submit it
with comments explaining why I think it is conservatively correct, and a TODO on what I think is actually required for complete
generality.
Kevin
Yes, I am still working on it. I believe I have it conservatively correct. I suppose I should just go ahead and submit it
with comments explaining why I think it is conservatively correct, and a TODO on what I think is actually required for complete
generality.
Kevin