summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-11-25 07:25:26 +0000
committerChris Lattner <sabre@nondot.org>2008-11-25 07:25:26 +0000
commit3b48501adc540c834fe33bf2695377c7e1189d3c (patch)
treea7ff089fb79361107b7d878ad0ee7427a9b1821c /lib/Transforms/Scalar/CodeGenPrepare.cpp
parent88a5c832ac71eb31d2b1bc143817af9248f4c549 (diff)
downloadllvm-3b48501adc540c834fe33bf2695377c7e1189d3c.tar.gz
llvm-3b48501adc540c834fe33bf2695377c7e1189d3c.tar.bz2
llvm-3b48501adc540c834fe33bf2695377c7e1189d3c.tar.xz
Teach MatchScaledValue to handle Scales by 1 with MatchAddr (which
can recursively match things) and scales by 0 by ignoring them. This triggers once in 403.gcc, saving 1 (!!!!) instruction in the whole huge app. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60013 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/CodeGenPrepare.cpp')
-rw-r--r--lib/Transforms/Scalar/CodeGenPrepare.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp
index 0eaf7e40c0..4ba8091d05 100644
--- a/lib/Transforms/Scalar/CodeGenPrepare.cpp
+++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp
@@ -557,7 +557,7 @@ public:
return Result;
}
private:
- bool MatchScaledValue(Value *ScaleReg, int64_t Scale);
+ bool MatchScaledValue(Value *ScaleReg, int64_t Scale, unsigned Depth);
bool MatchAddr(Value *V, unsigned Depth);
bool MatchOperationAddr(User *Operation, unsigned Opcode, unsigned Depth);
};
@@ -566,7 +566,17 @@ private:
/// MatchScaledValue - Try adding ScaleReg*Scale to the current addressing mode.
/// Return true and update AddrMode if this addr mode is legal for the target,
/// false if not.
-bool AddressingModeMatcher::MatchScaledValue(Value *ScaleReg, int64_t Scale) {
+bool AddressingModeMatcher::MatchScaledValue(Value *ScaleReg, int64_t Scale,
+ unsigned Depth) {
+ // If Scale is 1, then this is the same as adding ScaleReg to the addressing
+ // mode. Just process that directly.
+ if (Scale == 1)
+ return MatchAddr(ScaleReg, Depth);
+
+ // If the scale is 0, it takes nothing to add this.
+ if (Scale == 0)
+ return true;
+
// If we already have a scale of this value, we can add to it, otherwise, we
// need an available scale field.
if (AddrMode.Scale != 0 && AddrMode.ScaledReg != ScaleReg)
@@ -663,7 +673,7 @@ bool AddressingModeMatcher::MatchOperationAddr(User *AddrInst, unsigned Opcode,
if (Opcode == Instruction::Shl)
Scale = 1 << Scale;
- return MatchScaledValue(AddrInst->getOperand(0), Scale);
+ return MatchScaledValue(AddrInst->getOperand(0), Scale, Depth);
}
case Instruction::GetElementPtr: {
// Scan the GEP. We check it if it contains constant offsets and at most
@@ -728,8 +738,8 @@ bool AddressingModeMatcher::MatchOperationAddr(User *AddrInst, unsigned Opcode,
// See if the scale and offset amount is valid for this target.
AddrMode.BaseOffs += ConstantOffset;
- // FIXME: If VariableScale = 1, just call MatchAddr recursively?
- if (!MatchScaledValue(AddrInst->getOperand(VariableOperand),VariableScale)){
+ if (!MatchScaledValue(AddrInst->getOperand(VariableOperand), VariableScale,
+ Depth)) {
AddrMode = BackupAddrMode;
return false;
}