From 088a1e84ea985a22efcf907d7789064fee3a97b9 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 25 Nov 2008 04:42:10 +0000 Subject: [PATCH] minor cleanups no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60009 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/CodeGenPrepare.cpp | 63 ++++++++++++------------ 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp index 16c3e63f133..0a464a78837 100644 --- a/lib/Transforms/Scalar/CodeGenPrepare.cpp +++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp @@ -33,7 +33,9 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/GetElementPtrTypeIterator.h" +#include "llvm/Support/PatternMatch.h" using namespace llvm; +using namespace llvm::PatternMatch; namespace { class VISIBILITY_HIDDEN CodeGenPrepare : public FunctionPass { @@ -537,41 +539,38 @@ static bool TryMatchingScaledValue(Value *ScaleReg, int64_t Scale, if (AddrMode.Scale != 0 && AddrMode.ScaledReg != ScaleReg) return false; - ExtAddrMode InputAddrMode = AddrMode; + ExtAddrMode TestAddrMode = AddrMode; // Add scale to turn X*4+X*3 -> X*7. This could also do things like // [A+B + A*7] -> [B+A*8]. - AddrMode.Scale += Scale; - AddrMode.ScaledReg = ScaleReg; - - if (TLI.isLegalAddressingMode(AddrMode, AccessTy)) { - // Okay, we decided that we can add ScaleReg+Scale to AddrMode. Check now - // to see if ScaleReg is actually X+C. If so, we can turn this into adding - // X*Scale + C*Scale to addr mode. - BinaryOperator *BinOp = dyn_cast(ScaleReg); - if (BinOp && BinOp->getOpcode() == Instruction::Add && - isa(BinOp->getOperand(1)) && InputAddrMode.ScaledReg ==0) { - - InputAddrMode.Scale = Scale; - InputAddrMode.ScaledReg = BinOp->getOperand(0); - InputAddrMode.BaseOffs += - cast(BinOp->getOperand(1))->getSExtValue()*Scale; - if (TLI.isLegalAddressingMode(InputAddrMode, AccessTy)) { - AddrModeInsts.push_back(BinOp); - AddrMode = InputAddrMode; - return true; - } - } + TestAddrMode.Scale += Scale; + TestAddrMode.ScaledReg = ScaleReg; - // Otherwise, not (x+c)*scale, just return what we have. - return true; - } + // If the new address isn't legal, bail out. + if (!TLI.isLegalAddressingMode(TestAddrMode, AccessTy)) + return false; - // Otherwise, back this attempt out. - AddrMode.Scale -= Scale; - if (AddrMode.Scale == 0) AddrMode.ScaledReg = 0; + // It was legal, so commit it. + AddrMode = TestAddrMode; + + // Okay, we decided that we can add ScaleReg+Scale to AddrMode. Check now + // to see if ScaleReg is actually X+C. If so, we can turn this into adding + // X*Scale + C*Scale to addr mode. + ConstantInt *CI; Value *AddLHS; + if (match(ScaleReg, m_Add(m_Value(AddLHS), m_ConstantInt(CI)))) { + TestAddrMode.ScaledReg = AddLHS; + TestAddrMode.BaseOffs += CI->getSExtValue()*TestAddrMode.Scale; + + // If this addressing mode is legal, commit it and remember that we folded + // this instruction. + if (TLI.isLegalAddressingMode(TestAddrMode, AccessTy)) { + AddrModeInsts.push_back(cast(ScaleReg)); + AddrMode = TestAddrMode; + } + } - return false; + // Otherwise, not (x+c)*scale, just return what we have. + return true; } @@ -584,7 +583,7 @@ static bool TryMatchingScaledValue(Value *ScaleReg, int64_t Scale, /// operands. static bool FindMaximalLegalAddressingMode(Value *Addr, const Type *AccessTy, ExtAddrMode &AddrMode, - SmallVector &AddrModeInsts, + SmallVectorImpl &AddrModeInsts, const TargetLowering &TLI, unsigned Depth) { @@ -672,8 +671,8 @@ static bool FindMaximalLegalAddressingMode(Value *Addr, const Type *AccessTy, break; } case Instruction::Or: { - ConstantInt *RHS = dyn_cast(AddrInst->getOperand(1)); - if (!RHS) break; + //ConstantInt *RHS = dyn_cast(AddrInst->getOperand(1)); + //if (!RHS) break; // TODO: We can handle "Or Val, Imm" iff this OR is equivalent to an ADD. break; } -- 2.34.1