diff options
| author | Reid Spencer <rspencer@reidspencer.com> | 2007-03-02 00:28:52 +0000 | 
|---|---|---|
| committer | Reid Spencer <rspencer@reidspencer.com> | 2007-03-02 00:28:52 +0000 | 
| commit | 2e54a15943637fd337ed2e17e17879ff735f5bf2 (patch) | |
| tree | 92aac23fc083d008216073abe2ea135578ebbb8c /llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp | |
| parent | 3f770e4afdcc7e1fd7b933c5ec98f38c69ba0c89 (diff) | |
| download | bcm5719-llvm-2e54a15943637fd337ed2e17e17879ff735f5bf2.tar.gz bcm5719-llvm-2e54a15943637fd337ed2e17e17879ff735f5bf2.zip  | |
Prefer non-virtual calls to ConstantInt::isZero over virtual calls to
Constant::isNullValue() in situations where it is possible.
llvm-svn: 34821
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp | 38 | 
1 files changed, 21 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index e97921237fc..1a1ea7a72b7 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -540,7 +540,7 @@ Value *BasedUser::InsertCodeForBaseAtPosition(const SCEVHandle &NewBase,    // If there is no immediate value, skip the next part.    if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Imm)) -    if (SC->getValue()->isNullValue()) +    if (SC->getValue()->isZero())        return Rewriter.expandCodeFor(NewBase, BaseInsertPt,                                      OperandValToReplace->getType()); @@ -779,7 +779,7 @@ static void SeparateSubExprs(std::vector<SCEVHandle> &SubExprs,        SeparateSubExprs(SubExprs, SARE->getOperand(0));      }    } else if (!isa<SCEVConstant>(Expr) || -             !cast<SCEVConstant>(Expr)->getValue()->isNullValue()) { +             !cast<SCEVConstant>(Expr)->getValue()->isZero()) {      // Do not add zero.      SubExprs.push_back(Expr);    } @@ -869,7 +869,7 @@ RemoveCommonExpressionsFromUseBases(std::vector<BasedUser> &Uses) {  ///  static bool isZero(SCEVHandle &V) {    if (SCEVConstant *SC = dyn_cast<SCEVConstant>(V)) -    return SC->getValue()->getZExtValue() == 0; +    return SC->getValue()->isZero();    return false;  } @@ -883,17 +883,18 @@ unsigned LoopStrengthReduce::CheckForIVReuse(const SCEVHandle &Stride,    if (!TLI) return 0;    if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Stride)) { -    int64_t SInt = SC->getValue()->getSExtValue(); -    if (SInt == 1) return 0; +    const APInt &SInt = SC->getValue()->getValue(); +    if (SInt == 1)  +      return 0;      for (TargetLowering::legal_am_scale_iterator             I = TLI->legal_am_scale_begin(), E = TLI->legal_am_scale_end();           I != E; ++I) { -      unsigned Scale = *I; -      if (unsigned(abs(SInt)) < Scale || (SInt % Scale) != 0) +      APInt Scale(SInt.getBitWidth(), *I); +      if (SInt.abs().ult(Scale) || SInt.srem(Scale) != 0)          continue;        std::map<SCEVHandle, IVsOfOneStride>::iterator SI = -        IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt/Scale, UIntPtrTy)); +        IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt.sdiv(Scale)));        if (SI == IVsByStride.end())          continue;        for (std::vector<IVExpr>::iterator II = SI->second.IVs.begin(), @@ -902,7 +903,7 @@ unsigned LoopStrengthReduce::CheckForIVReuse(const SCEVHandle &Stride,          // Only reuse previous IV if it would not require a type conversion.          if (isZero(II->Base) && II->Base->getType() == Ty) {            IV = *II; -          return Scale; +          return Scale.getZExtValue();          }      }    } @@ -1148,14 +1149,14 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,          // are reusing an IV, it has not been used to initialize the PHI node.          // Add it to the expression used to rewrite the uses.          if (!isa<ConstantInt>(CommonBaseV) || -            !cast<ConstantInt>(CommonBaseV)->isNullValue()) +            !cast<ConstantInt>(CommonBaseV)->isZero())            RewriteExpr = SCEVAddExpr::get(RewriteExpr,                                           SCEVUnknown::get(CommonBaseV));        }        // Now that we know what we need to do, insert code before User for the        // immediate and any loop-variant expressions. -      if (!isa<ConstantInt>(BaseV) || !cast<ConstantInt>(BaseV)->isNullValue()) +      if (!isa<ConstantInt>(BaseV) || !cast<ConstantInt>(BaseV)->isZero())          // Add BaseV to the PHI value if needed.          RewriteExpr = SCEVAddExpr::get(RewriteExpr, SCEVUnknown::get(BaseV)); @@ -1257,14 +1258,17 @@ namespace {        SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS);        SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS);        if (LHSC && RHSC) { -        int64_t  LV = LHSC->getValue()->getSExtValue(); -        int64_t  RV = RHSC->getValue()->getSExtValue(); -        uint64_t ALV = (LV < 0) ? -LV : LV; -        uint64_t ARV = (RV < 0) ? -RV : RV; +        APInt LV(LHSC->getValue()->getValue()); +        APInt RV(RHSC->getValue()->getValue()); +        uint32_t MaxWidth = std::max(LV.getBitWidth(), RV.getBitWidth()); +        LV.sextOrTrunc(MaxWidth); +        RV.sextOrTrunc(MaxWidth); +        APInt ALV(LV.abs()); +        APInt ARV(RV.abs());          if (ALV == ARV) -          return LV > RV; +          return LV.sgt(RV);          else -          return ALV < ARV; +          return ALV.ult(ARV);        }        return (LHSC && !RHSC);      }  | 

