From a5dae0cac062a53edb2fc2dcd5be7658388d025a Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Fri, 2 Mar 2007 23:35:28 +0000 Subject: [PATCH] Use more efficient test for one value in a ConstantInt. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34859 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopStrengthReduce.cpp | 23 ++++++++++---------- lib/Transforms/Scalar/LoopUnswitch.cpp | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index e97921237fc..c4ee5237ae8 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/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(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 &SubExprs, SeparateSubExprs(SubExprs, SARE->getOperand(0)); } } else if (!isa(Expr) || - !cast(Expr)->getValue()->isNullValue()) { + !cast(Expr)->getValue()->isZero()) { // Do not add zero. SubExprs.push_back(Expr); } @@ -869,7 +869,7 @@ RemoveCommonExpressionsFromUseBases(std::vector &Uses) { /// static bool isZero(SCEVHandle &V) { if (SCEVConstant *SC = dyn_cast(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(Stride)) { - int64_t SInt = SC->getValue()->getSExtValue(); - if (SInt == 1) return 0; + 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::iterator SI = - IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt/Scale, UIntPtrTy)); + IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt.sdiv(Scale))); if (SI == IVsByStride.end()) continue; for (std::vector::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(CommonBaseV) || - !cast(CommonBaseV)->isNullValue()) + !cast(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(BaseV) || !cast(BaseV)->isNullValue()) + if (!isa(BaseV) || !cast(BaseV)->isZero()) // Add BaseV to the PHI value if needed. RewriteExpr = SCEVAddExpr::get(RewriteExpr, SCEVUnknown::get(BaseV)); diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 861e97ce586..5274c9dd107 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -1048,7 +1048,7 @@ void LoopUnswitch::SimplifyCode(std::vector &Worklist) { cast(I)->swapOperands(); if (ConstantInt *CB = dyn_cast(I->getOperand(1))) if (CB->getType() == Type::Int1Ty) { - if (CB->getZExtValue()) // X & 1 -> X + if (CB->isOne()) // X & 1 -> X ReplaceUsesOfWith(I, I->getOperand(0), Worklist); else // X & 0 -> 0 ReplaceUsesOfWith(I, I->getOperand(1), Worklist); @@ -1061,7 +1061,7 @@ void LoopUnswitch::SimplifyCode(std::vector &Worklist) { cast(I)->swapOperands(); if (ConstantInt *CB = dyn_cast(I->getOperand(1))) if (CB->getType() == Type::Int1Ty) { - if (CB->getZExtValue()) // X | 1 -> 1 + if (CB->isOne()) // X | 1 -> 1 ReplaceUsesOfWith(I, I->getOperand(1), Worklist); else // X | 0 -> X ReplaceUsesOfWith(I, I->getOperand(0), Worklist); -- 2.34.1