[llvm] e087b4f - Revert "[X86FixupLEAs] Sub register usage of LEA dest should block LEA/SUB optimization"
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 12 03:43:58 PDT 2021
Author: Florian Hahn
Date: 2021-06-12T11:40:47+01:00
New Revision: e087b4f14986f8330336b005c6ebb41f2bdaea63
URL: https://github.com/llvm/llvm-project/commit/e087b4f14986f8330336b005c6ebb41f2bdaea63
DIFF: https://github.com/llvm/llvm-project/commit/e087b4f14986f8330336b005c6ebb41f2bdaea63.diff
LOG: Revert "[X86FixupLEAs] Sub register usage of LEA dest should block LEA/SUB optimization"
This reverts commit f35bcea1d4748889b8240defdf00cb7a71cbe070 because it
depends on 1b748faf2bae246e2fc77d88420df13c2e60f4df, which breaks
building the llvm-test-suite with -verify-machineinstrs on X86.
See 154adc0f135cff3f8a8861c335d2b88c8049d098 for more details.
Added:
Modified:
llvm/lib/Target/X86/X86FixupLEAs.cpp
llvm/test/CodeGen/X86/lea-opt2.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86FixupLEAs.cpp b/llvm/lib/Target/X86/X86FixupLEAs.cpp
index 12724f8ca6abd..7a241292b068b 100644
--- a/llvm/lib/Target/X86/X86FixupLEAs.cpp
+++ b/llvm/lib/Target/X86/X86FixupLEAs.cpp
@@ -418,30 +418,26 @@ FixupLEAPass::searchALUInst(MachineBasicBlock::iterator &I,
// Check if the lea dest register is used in an add/sub instruction only.
for (unsigned I = 0, E = CurInst->getNumOperands(); I != E; ++I) {
MachineOperand &Opnd = CurInst->getOperand(I);
- if (Opnd.isReg()) {
- if (Opnd.getReg() == DestReg) {
- if (Opnd.isDef() || !Opnd.isKill())
- return MachineBasicBlock::iterator();
-
- unsigned AluOpcode = CurInst->getOpcode();
- if (AluOpcode != AddOpcode && AluOpcode != SubOpcode)
- return MachineBasicBlock::iterator();
-
- MachineOperand &Opnd2 = CurInst->getOperand(3 - I);
- MachineOperand AluDest = CurInst->getOperand(0);
- if (Opnd2.getReg() != AluDest.getReg())
- return MachineBasicBlock::iterator();
-
- // X - (Y + Z) may generate
diff erent flags than (X - Y) - Z when
- // there is overflow. So we can't change the alu instruction if the
- // flags register is live.
- if (!CurInst->registerDefIsDead(X86::EFLAGS, TRI))
- return MachineBasicBlock::iterator();
-
- return CurInst;
- }
- if (TRI->regsOverlap(DestReg, Opnd.getReg()))
+ if (Opnd.isReg() && Opnd.getReg() == DestReg) {
+ if (Opnd.isDef() || !Opnd.isKill())
return MachineBasicBlock::iterator();
+
+ unsigned AluOpcode = CurInst->getOpcode();
+ if (AluOpcode != AddOpcode && AluOpcode != SubOpcode)
+ return MachineBasicBlock::iterator();
+
+ MachineOperand &Opnd2 = CurInst->getOperand(3 - I);
+ MachineOperand AluDest = CurInst->getOperand(0);
+ if (Opnd2.getReg() != AluDest.getReg())
+ return MachineBasicBlock::iterator();
+
+ // X - (Y + Z) may generate
diff erent flags than (X - Y) - Z when there
+ // is overflow. So we can't change the alu instruction if the flags
+ // register is live.
+ if (!CurInst->registerDefIsDead(X86::EFLAGS, TRI))
+ return MachineBasicBlock::iterator();
+
+ return CurInst;
}
}
diff --git a/llvm/test/CodeGen/X86/lea-opt2.ll b/llvm/test/CodeGen/X86/lea-opt2.ll
index 5543602740bdc..e036a3fddce2f 100644
--- a/llvm/test/CodeGen/X86/lea-opt2.ll
+++ b/llvm/test/CodeGen/X86/lea-opt2.ll
@@ -182,32 +182,3 @@ endif:
%sub1 = sub i64 %ld, %b
ret i64 %sub1
}
-
-; PR50615
-; The sub register usage of lea dest should block the transformation.
-define void @test9(i64 %p, i64 %s) {
-; CHECK-LABEL: test9:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: leaq (%rsi,%rdi), %rax
-; CHECK-NEXT: xorl %ecx, %ecx
-; CHECK-NEXT: testl $4095, %eax # imm = 0xFFF
-; CHECK-NEXT: setne %cl
-; CHECK-NEXT: shlq $12, %rcx
-; CHECK-NEXT: addq %rax, %rcx
-; CHECK-NEXT: andq $-4096, %rcx # imm = 0xF000
-; CHECK-NEXT: addq %rcx, %rdi
-; CHECK-NEXT: jmp bar at PLT # TAILCALL
-entry:
- %add = add i64 %s, %p
- %rem = and i64 %add, 4095
- %cmp.not = icmp eq i64 %rem, 0
- %add18 = select i1 %cmp.not, i64 0, i64 4096
- %div9 = add i64 %add18, %add
- %mul = and i64 %div9, -4096
- %add2 = add i64 %mul, %p
- tail call void @bar(i64 %add2, i64 %s)
- ret void
-}
-
-declare void @bar(i64, i64)
-
More information about the llvm-commits
mailing list