[llvm-commits] [llvm] r57872 - in /llvm/trunk: lib/CodeGen/SimpleRegisterCoalescing.cpp lib/Target/X86/X86InstrInfo.cpp test/CodeGen/X86/ret-i64-0.ll
Dan Gohman
gohman at apple.com
Mon Oct 20 20:24:39 PDT 2008
Author: djg
Date: Mon Oct 20 22:24:31 2008
New Revision: 57872
URL: http://llvm.org/viewvc/llvm-project?rev=57872&view=rev
Log:
When the coalescer is doing rematerializing, have it remove
the copy instruction from the instruction list before asking the
target to create the new instruction. This gets the old instruction
out of the way so that it doesn't interfere with the target's
rematerialization code. In the case of x86, this helps it find
more cases where EFLAGS is not live.
Also, in the X86InstrInfo.cpp, teach isSafeToClobberEFLAGS to check
to see if it reached the end of the block after scanning each
instruction, instead of just before. This lets it notice when the
end of the block is only two instructions away, without doing any
additional scanning.
These changes allow rematerialization to clobber EFLAGS in more
cases, for example using xor instead of mov to set the return value
to zero in the included testcase.
Added:
llvm/trunk/test/CodeGen/X86/ret-i64-0.ll
Modified:
llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp
llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
Modified: llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp?rev=57872&r1=57871&r2=57872&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp (original)
+++ llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp Mon Oct 20 22:24:31 2008
@@ -471,8 +471,9 @@
}
}
- MachineBasicBlock::iterator MII = CopyMI;
MachineBasicBlock *MBB = CopyMI->getParent();
+ MachineBasicBlock::iterator MII = next(MachineBasicBlock::iterator(CopyMI));
+ CopyMI->removeFromParent();
tii_->reMaterialize(*MBB, MII, DstReg, DefMI);
MachineInstr *NewMI = prior(MII);
// CopyMI may have implicit operands, transfer them over to the newly
@@ -491,7 +492,7 @@
}
li_->ReplaceMachineInstrInMaps(CopyMI, NewMI);
- CopyMI->eraseFromParent();
+ MBB->getParent()->DeleteMachineInstr(CopyMI);
ReMatCopies.insert(CopyMI);
ReMatDefs.insert(DefMI);
++NumReMats;
Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.cpp?rev=57872&r1=57871&r2=57872&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86InstrInfo.cpp Mon Oct 20 22:24:31 2008
@@ -848,12 +848,13 @@
/// two instructions it assumes it's not safe.
static bool isSafeToClobberEFLAGS(MachineBasicBlock &MBB,
MachineBasicBlock::iterator I) {
+ // It's always safe to clobber EFLAGS at the end of a block.
+ if (I == MBB.end())
+ return true;
+
// For compile time consideration, if we are not able to determine the
// safety after visiting 2 instructions, we will assume it's not safe.
for (unsigned i = 0; i < 2; ++i) {
- if (I == MBB.end())
- // Reached end of block, it's safe.
- return true;
bool SeenDef = false;
for (unsigned j = 0, e = I->getNumOperands(); j != e; ++j) {
MachineOperand &MO = I->getOperand(j);
@@ -870,6 +871,10 @@
// This instruction defines EFLAGS, no need to look any further.
return true;
++I;
+
+ // If we make it to the end of the block, it's safe to clobber EFLAGS.
+ if (I == MBB.end())
+ return true;
}
// Conservative answer.
Added: llvm/trunk/test/CodeGen/X86/ret-i64-0.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/ret-i64-0.ll?rev=57872&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/ret-i64-0.ll (added)
+++ llvm/trunk/test/CodeGen/X86/ret-i64-0.ll Mon Oct 20 22:24:31 2008
@@ -0,0 +1,5 @@
+; RUN: llvm-as < %s | llc -march=x86 | grep xor | count 2
+
+define i64 @foo() {
+ ret i64 0
+}
More information about the llvm-commits
mailing list