From 579633cd1006f6add1b022e9c2bc96f7f0e65777 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 9 Apr 2007 22:20:14 +0000 Subject: [PATCH] switch LSR to use isLegalAddressingMode instead of other simpler hooks git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35837 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopStrengthReduce.cpp | 39 +++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 0cc9851f72c..7540f44e4e7 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -143,8 +143,7 @@ namespace { const TargetLowering *TLI; public: - LoopStrengthReduce(const TargetLowering *tli = NULL) - : TLI(tli) { + LoopStrengthReduce(const TargetLowering *tli = NULL) : TLI(tli) { } bool runOnLoop(Loop *L, LPPassManager &LPM); @@ -631,20 +630,25 @@ static bool isTargetConstant(const SCEVHandle &V, const Type *UseTy, const TargetLowering *TLI) { if (SCEVConstant *SC = dyn_cast(V)) { int64_t VC = SC->getValue()->getSExtValue(); - if (TLI) - return TLI->isLegalAddressImmediate(VC, UseTy); - else + if (TLI) { + TargetLowering::AddrMode AM; + AM.BaseOffs = VC; + return TLI->isLegalAddressingMode(AM, UseTy); + } else { // Defaults to PPC. PPC allows a sign-extended 16-bit immediate field. return (VC > -(1 << 16) && VC < (1 << 16)-1); + } } if (SCEVUnknown *SU = dyn_cast(V)) if (ConstantExpr *CE = dyn_cast(SU->getValue())) - if (CE->getOpcode() == Instruction::PtrToInt) { + if (TLI && CE->getOpcode() == Instruction::PtrToInt) { Constant *Op0 = CE->getOperand(0); - if (isa(Op0) && TLI && - TLI->isLegalAddressImmediate(cast(Op0))) - return true; + if (GlobalValue *GV = dyn_cast(Op0)) { + TargetLowering::AddrMode AM; + AM.BaseGV = GV; + return TLI->isLegalAddressingMode(AM, UseTy); + } } return false; } @@ -889,18 +893,11 @@ static bool isZero(SCEVHandle &V) { } /// ValidStride - Check whether the given Scale is valid for all loads and -/// stores in UsersToProcess. Pulled into a function to avoid disturbing the -/// sensibilities of those who dislike goto's. +/// stores in UsersToProcess. /// bool LoopStrengthReduce::ValidStride(int64_t Scale, const std::vector& UsersToProcess) { - int64_t Imm; for (unsigned i=0, e = UsersToProcess.size(); i!=e; ++i) { - if (SCEVConstant *SC = dyn_cast(UsersToProcess[i].Imm)) - Imm = SC->getValue()->getSExtValue(); - else - Imm = 0; - // If this is a load or other access, pass the type of the access in. const Type *AccessTy = Type::VoidTy; if (StoreInst *SI = dyn_cast(UsersToProcess[i].Inst)) @@ -908,7 +905,13 @@ bool LoopStrengthReduce::ValidStride(int64_t Scale, else if (LoadInst *LI = dyn_cast(UsersToProcess[i].Inst)) AccessTy = LI->getType(); - if (!TLI->isLegalAddressScaleAndImm(Scale, Imm, AccessTy)) + TargetLowering::AddrMode AM; + if (SCEVConstant *SC = dyn_cast(UsersToProcess[i].Imm)) + AM.BaseOffs = SC->getValue()->getSExtValue(); + AM.Scale = Scale; + + // If load[imm+r*scale] is illegal, bail out. + if (!TLI->isLegalAddressingMode(AM, AccessTy)) return false; } return true; -- 2.34.1