summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorManman Ren <mren@apple.com>2012-08-02 19:37:32 +0000
committerManman Ren <mren@apple.com>2012-08-02 19:37:32 +0000
commit127eea87d666ccc9fe7025f41148c33af0f8c84b (patch)
tree97b08e6625f5465adbdee33975e86a496bc85af8 /lib
parent1de266be13c956f4af9566b000b67ef75454d0a8 (diff)
downloadllvm-127eea87d666ccc9fe7025f41148c33af0f8c84b.tar.gz
llvm-127eea87d666ccc9fe7025f41148c33af0f8c84b.tar.bz2
llvm-127eea87d666ccc9fe7025f41148c33af0f8c84b.tar.xz
X86 Peephole: fold loads to the source register operand if possible.
Add more comments and use early returns to reduce nesting in isLoadFoldable. Also disable folding for V_SET0 to avoid introducing a const pool entry and a const pool load. rdar://10554090 and rdar://11873276 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161207 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/PeepholeOptimizer.cpp29
-rw-r--r--lib/Target/X86/X86InstrInfo.h6
2 files changed, 20 insertions, 15 deletions
diff --git a/lib/CodeGen/PeepholeOptimizer.cpp b/lib/CodeGen/PeepholeOptimizer.cpp
index d9474bf240..6bc7e37e3d 100644
--- a/lib/CodeGen/PeepholeOptimizer.cpp
+++ b/lib/CodeGen/PeepholeOptimizer.cpp
@@ -391,20 +391,21 @@ bool PeepholeOptimizer::optimizeCmpInstr(MachineInstr *MI,
/// register defined has a single use.
bool PeepholeOptimizer::isLoadFoldable(MachineInstr *MI,
unsigned &FoldAsLoadDefReg) {
- if (MI->canFoldAsLoad()) {
- const MCInstrDesc &MCID = MI->getDesc();
- if (MCID.getNumDefs() == 1) {
- unsigned Reg = MI->getOperand(0).getReg();
- // To reduce compilation time, we check MRI->hasOneUse when inserting
- // loads. It should be checked when processing uses of the load, since
- // uses can be removed during peephole.
- if (!MI->getOperand(0).getSubReg() &&
- TargetRegisterInfo::isVirtualRegister(Reg) &&
- MRI->hasOneUse(Reg)) {
- FoldAsLoadDefReg = Reg;
- return true;
- }
- }
+ if (!MI->canFoldAsLoad() || !MI->mayLoad())
+ return false;
+ const MCInstrDesc &MCID = MI->getDesc();
+ if (MCID.getNumDefs() != 1)
+ return false;
+
+ unsigned Reg = MI->getOperand(0).getReg();
+ // To reduce compilation time, we check MRI->hasOneUse when inserting
+ // loads. It should be checked when processing uses of the load, since
+ // uses can be removed during peephole.
+ if (!MI->getOperand(0).getSubReg() &&
+ TargetRegisterInfo::isVirtualRegister(Reg) &&
+ MRI->hasOneUse(Reg)) {
+ FoldAsLoadDefReg = Reg;
+ return true;
}
return false;
}
diff --git a/lib/Target/X86/X86InstrInfo.h b/lib/Target/X86/X86InstrInfo.h
index 9ed5210b22..b6f69af037 100644
--- a/lib/Target/X86/X86InstrInfo.h
+++ b/lib/Target/X86/X86InstrInfo.h
@@ -389,7 +389,11 @@ public:
/// optimizeLoadInstr - Try to remove the load by folding it to a register
/// operand at the use. We fold the load instructions if and only if the
- /// def and use are in the same BB.
+ /// def and use are in the same BB. We only look at one load and see
+ /// whether it can be folded into MI. FoldAsLoadDefReg is the virtual register
+ /// defined by the load we are trying to fold. DefMI returns the machine
+ /// instruction that defines FoldAsLoadDefReg, and the function returns
+ /// the machine instruction generated due to folding.
virtual MachineInstr* optimizeLoadInstr(MachineInstr *MI,
const MachineRegisterInfo *MRI,
unsigned &FoldAsLoadDefReg,