aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG/FastISel.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-07-01 03:49:38 +0000
committerDan Gohman <gohman@apple.com>2010-07-01 03:49:38 +0000
commit7fbcc98f20c062273bf16ce9832f40e5b8a205c6 (patch)
treec88ad644469a76759d1eec12f802e4a4fef69ba0 /lib/CodeGen/SelectionDAG/FastISel.cpp
parent20d4be151b54feb18aa1e5cc04033a4aa64137ae (diff)
Teach fast-isel to avoid loading a value from memory when it's already
available in a register. This is pretty primitive, but it reduces the number of instructions in common testcases by 4%. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107380 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/FastISel.cpp')
-rw-r--r--lib/CodeGen/SelectionDAG/FastISel.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp
index 2d6b78840f..56009f3903 100644
--- a/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -48,6 +48,7 @@
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/Analysis/DebugInfo.h"
+#include "llvm/Analysis/Loads.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetLowering.h"
@@ -716,8 +717,31 @@ FastISel::SelectFNeg(const User *I) {
}
bool
+FastISel::SelectLoad(const User *I) {
+ LoadInst *LI = const_cast<LoadInst *>(cast<LoadInst>(I));
+
+ // For a load from an alloca, make a limited effort to find the value
+ // already available in a register, avoiding redundant loads.
+ if (!LI->isVolatile() && isa<AllocaInst>(LI->getPointerOperand())) {
+ BasicBlock::iterator ScanFrom = LI;
+ if (const Value *V = FindAvailableLoadedValue(LI->getPointerOperand(),
+ LI->getParent(), ScanFrom)) {
+ unsigned ResultReg = getRegForValue(V);
+ if (ResultReg != 0) {
+ UpdateValueMap(I, ResultReg);
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+bool
FastISel::SelectOperator(const User *I, unsigned Opcode) {
switch (Opcode) {
+ case Instruction::Load:
+ return SelectLoad(I);
case Instruction::Add:
return SelectBinaryOp(I, ISD::ADD);
case Instruction::FAdd: