The bug arises during register allocation on i686 for CMPXCHG8B instruction when base pointer is needed. CMPXCHG8B needs 4 implicit registers (EAX, EBX, ECX, EDX) and a memory address, plus ESI is reserved as the base pointer. With such constraints the only way register allocator would do its job successfully is when the addressing mode of the instruction requires only one register. If that is not the case - we are emitting additional LEA instruction to compute the address
Details
Diff Detail
Event Timeline
lib/Target/X86/X86ISelLowering.cpp | ||
---|---|---|
24614 | Split the NFC changes in a different patch. | |
24733 | Use an early return to reduce indentation per LLVM coding style. | |
24753 | Shouldn't we check for is32Bit or something? | |
test/CodeGen/X86/pr28755.ll | ||
1 ↗ | (On Diff #73030) | Couple of comment on the test case:
|
lib/Target/X86/X86ISelLowering.cpp | ||
---|---|---|
24614 | Uploaded as: https://reviews.llvm.org/D25192 | |
24753 | Right. I checked for "TRI->getBaseRegister() == X86::ESI", which is only true for i686, but I agree that it would be better to check directly for 32 bits |
Looks pretty good, just one nitpick.
test/CodeGen/X86/cmpxchg8b_alloca_regalloc_handling.ll | ||
---|---|---|
22 | Why to you need the regex here? |
test/CodeGen/X86/cmpxchg8b_alloca_regalloc_handling.ll | ||
---|---|---|
22 | You mean in the checks related to the first function? Well, I kinda wanted to express that the register that we are doing "lea" to is the same register we use for a memory location in cmpxchg8b. And since we don't hardcode the name of the register in EmitInstrWithCustomInserter, I did it as a regexp for esi/edi. Although it makes me wonder whether it is valid or not to define/use regexp with the same name lower in the test |
test/CodeGen/X86/cmpxchg8b_alloca_regalloc_handling.ll | ||
---|---|---|
22 | That's fine. My question was regarding the xor or mov. Why do we expect this to change? |
Ok, got the point. Attached patch represents what currently is generated for those gen's
One last nitpick, don't need to go through another round of review, just commit directly.
Cheers,
Q.
lib/Target/X86/X86InstrBuilder.h | ||
---|---|---|
129 | Could you add a comment on which operand are what? |
thank you a lot for reviewing this! I will ask smb to commit it after I got approve for D24938 - I'm using getAddressFromInstr and it has to work correctly
Split the NFC changes in a different patch.