aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-03-02 00:28:52 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-03-02 00:28:52 +0000
commitcae5754619433aed7be74abbf1c0551a82d369cb (patch)
tree77599913d2e900d4774e81cce3333f31f25c9fa6 /lib/Transforms
parent34da0ac28f7bfe737f92d3a098697a6ebc09a25e (diff)
Prefer non-virtual calls to ConstantInt::isZero over virtual calls to
Constant::isNullValue() in situations where it is possible. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34821 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp2
-rw-r--r--lib/Transforms/IPO/SimplifyLibCalls.cpp6
-rw-r--r--lib/Transforms/Scalar/CondPropagate.cpp2
-rw-r--r--lib/Transforms/Scalar/IndVarSimplify.cpp6
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp38
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp8
6 files changed, 33 insertions, 29 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index dbdea1ecdd..89850d2e3d 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1155,7 +1155,7 @@ static void ShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
// instead of a select to synthesize the desired value.
bool IsOneZero = false;
if (ConstantInt *CI = dyn_cast<ConstantInt>(OtherVal))
- IsOneZero = InitVal->isNullValue() && CI->equalsInt(1);
+ IsOneZero = InitVal->isNullValue() && CI->isOne();
while (!GV->use_empty()) {
Instruction *UI = cast<Instruction>(GV->use_back());
diff --git a/lib/Transforms/IPO/SimplifyLibCalls.cpp b/lib/Transforms/IPO/SimplifyLibCalls.cpp
index 08286216f9..6d71925867 100644
--- a/lib/Transforms/IPO/SimplifyLibCalls.cpp
+++ b/lib/Transforms/IPO/SimplifyLibCalls.cpp
@@ -584,7 +584,7 @@ public:
for (uint64_t i = 0; i < len; ++i) {
if (ConstantInt* CI = dyn_cast<ConstantInt>(CA->getOperand(i))) {
// Check for the null terminator
- if (CI->isNullValue())
+ if (CI->isZero())
break; // we found end of string
else if (CI->getSExtValue() == chr) {
char_found = true;
@@ -2023,7 +2023,7 @@ static bool getConstantStringLength(Value *V, uint64_t &len, ConstantArray **CA)
// Check to make sure that the first operand of the GEP is an integer and
// has value 0 so that we are sure we're indexing into the initializer.
if (ConstantInt* op1 = dyn_cast<ConstantInt>(GEP->getOperand(1))) {
- if (!op1->isNullValue())
+ if (!op1->isZero())
return false;
} else
return false;
@@ -2069,7 +2069,7 @@ static bool getConstantStringLength(Value *V, uint64_t &len, ConstantArray **CA)
for (len = start_idx; len < max_elems; len++) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(A->getOperand(len))) {
// Check for the null terminator
- if (CI->isNullValue())
+ if (CI->isZero())
break; // we found end of string
} else
return false; // This array isn't suitable, non-int initializer
diff --git a/lib/Transforms/Scalar/CondPropagate.cpp b/lib/Transforms/Scalar/CondPropagate.cpp
index fdcb404e11..90a4f3048f 100644
--- a/lib/Transforms/Scalar/CondPropagate.cpp
+++ b/lib/Transforms/Scalar/CondPropagate.cpp
@@ -139,7 +139,7 @@ void CondProp::SimplifyPredecessors(BranchInst *BI) {
// ultimate destination.
bool PHIGone = PN->getNumIncomingValues() == 2;
RevectorBlockTo(PN->getIncomingBlock(i-1),
- BI->getSuccessor(CB->isNullValue()));
+ BI->getSuccessor(CB->isZero()));
++NumBrThread;
// If there were two predecessors before this simplification, the PHI node
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
index 4d03f28c4b..fa2b3bde30 100644
--- a/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -178,9 +178,9 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN,
Constant *NCE = ConstantExpr::getGetElementPtr(CE->getOperand(0),
&CEIdxs[0],
CEIdxs.size());
- GetElementPtrInst *NGEPI =
- new GetElementPtrInst(NCE, Constant::getNullValue(Type::Int32Ty),
- NewAdd, GEPI->getName(), GEPI);
+ GetElementPtrInst *NGEPI = new GetElementPtrInst(
+ NCE, Constant::getNullValue(Type::Int32Ty), NewAdd,
+ GEPI->getName(), GEPI);
GEPI->replaceAllUsesWith(NGEPI);
GEPI->eraseFromParent();
GEPI = NGEPI;
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index e97921237f..1a1ea7a72b 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<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);
}
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp
index aa851b290f..8030a76ece 100644
--- a/lib/Transforms/Scalar/Reassociate.cpp
+++ b/lib/Transforms/Scalar/Reassociate.cpp
@@ -536,7 +536,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
switch (Opcode) {
default: break;
case Instruction::And:
- if (CstVal->isNullValue()) { // ... & 0 -> 0
+ if (CstVal->isZero()) { // ... & 0 -> 0
++NumAnnihil;
return CstVal;
} else if (CstVal->isAllOnesValue()) { // ... & -1 -> ...
@@ -544,10 +544,10 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
}
break;
case Instruction::Mul:
- if (CstVal->isNullValue()) { // ... * 0 -> 0
+ if (CstVal->isZero()) { // ... * 0 -> 0
++NumAnnihil;
return CstVal;
- } else if (cast<ConstantInt>(CstVal)->isUnitValue()) {
+ } else if (cast<ConstantInt>(CstVal)->isOne()) {
Ops.pop_back(); // ... * 1 -> ...
}
break;
@@ -559,7 +559,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
// FALLTHROUGH!
case Instruction::Add:
case Instruction::Xor:
- if (CstVal->isNullValue()) // ... [|^+] 0 -> ...
+ if (CstVal->isZero()) // ... [|^+] 0 -> ...
Ops.pop_back();
break;
}