forked from OSchip/llvm-project
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%. llvm-svn: 107380
This commit is contained in:
parent
7c42659cee
commit
aef3d140b7
|
@ -307,6 +307,8 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool SelectLoad(const User *I);
|
||||||
|
|
||||||
bool SelectBinaryOp(const User *I, unsigned ISDOpcode);
|
bool SelectBinaryOp(const User *I, unsigned ISDOpcode);
|
||||||
|
|
||||||
bool SelectFNeg(const User *I);
|
bool SelectFNeg(const User *I);
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#include "llvm/CodeGen/MachineModuleInfo.h"
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
||||||
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
||||||
#include "llvm/Analysis/DebugInfo.h"
|
#include "llvm/Analysis/DebugInfo.h"
|
||||||
|
#include "llvm/Analysis/Loads.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Target/TargetInstrInfo.h"
|
#include "llvm/Target/TargetInstrInfo.h"
|
||||||
#include "llvm/Target/TargetLowering.h"
|
#include "llvm/Target/TargetLowering.h"
|
||||||
|
@ -715,9 +716,32 @@ FastISel::SelectFNeg(const User *I) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
bool
|
||||||
FastISel::SelectOperator(const User *I, unsigned Opcode) {
|
FastISel::SelectOperator(const User *I, unsigned Opcode) {
|
||||||
switch (Opcode) {
|
switch (Opcode) {
|
||||||
|
case Instruction::Load:
|
||||||
|
return SelectLoad(I);
|
||||||
case Instruction::Add:
|
case Instruction::Add:
|
||||||
return SelectBinaryOp(I, ISD::ADD);
|
return SelectBinaryOp(I, ISD::ADD);
|
||||||
case Instruction::FAdd:
|
case Instruction::FAdd:
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
; RUN: llc -march=x86-64 -O0 -asm-verbose=false < %s | FileCheck %s
|
||||||
|
|
||||||
|
; Fast-isel shouldn't reload the argument values from the stack.
|
||||||
|
|
||||||
|
; CHECK: foo:
|
||||||
|
; CHECK-NEXT: movq %rdi, -8(%rsp)
|
||||||
|
; CHECK-NEXT: movq %rsi, -16(%rsp)
|
||||||
|
; CHECK-NEXT: movsd 128(%rsi,%rdi,8), %xmm0
|
||||||
|
; CHECK-NEXT: ret
|
||||||
|
|
||||||
|
define double @foo(i64 %x, double* %p) nounwind {
|
||||||
|
entry:
|
||||||
|
%x.addr = alloca i64, align 8 ; <i64*> [#uses=2]
|
||||||
|
%p.addr = alloca double*, align 8 ; <double**> [#uses=2]
|
||||||
|
store i64 %x, i64* %x.addr
|
||||||
|
store double* %p, double** %p.addr
|
||||||
|
%tmp = load i64* %x.addr ; <i64> [#uses=1]
|
||||||
|
%tmp1 = load double** %p.addr ; <double*> [#uses=1]
|
||||||
|
%add = add nsw i64 %tmp, 16 ; <i64> [#uses=1]
|
||||||
|
%arrayidx = getelementptr inbounds double* %tmp1, i64 %add ; <double*> [#uses=1]
|
||||||
|
%tmp2 = load double* %arrayidx ; <double> [#uses=1]
|
||||||
|
ret double %tmp2
|
||||||
|
}
|
Loading…
Reference in New Issue