mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-24 12:55:45 +00:00
Use more efficient test for one value in a ConstantInt.
llvm-svn: 34859
This commit is contained in:
parent
76f02c5848
commit
70fbfc75e8
@ -540,7 +540,7 @@ Value *BasedUser::InsertCodeForBaseAtPosition(const SCEVHandle &NewBase,
|
|||||||
|
|
||||||
// If there is no immediate value, skip the next part.
|
// If there is no immediate value, skip the next part.
|
||||||
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Imm))
|
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Imm))
|
||||||
if (SC->getValue()->isNullValue())
|
if (SC->getValue()->isZero())
|
||||||
return Rewriter.expandCodeFor(NewBase, BaseInsertPt,
|
return Rewriter.expandCodeFor(NewBase, BaseInsertPt,
|
||||||
OperandValToReplace->getType());
|
OperandValToReplace->getType());
|
||||||
|
|
||||||
@ -779,7 +779,7 @@ static void SeparateSubExprs(std::vector<SCEVHandle> &SubExprs,
|
|||||||
SeparateSubExprs(SubExprs, SARE->getOperand(0));
|
SeparateSubExprs(SubExprs, SARE->getOperand(0));
|
||||||
}
|
}
|
||||||
} else if (!isa<SCEVConstant>(Expr) ||
|
} else if (!isa<SCEVConstant>(Expr) ||
|
||||||
!cast<SCEVConstant>(Expr)->getValue()->isNullValue()) {
|
!cast<SCEVConstant>(Expr)->getValue()->isZero()) {
|
||||||
// Do not add zero.
|
// Do not add zero.
|
||||||
SubExprs.push_back(Expr);
|
SubExprs.push_back(Expr);
|
||||||
}
|
}
|
||||||
@ -869,7 +869,7 @@ RemoveCommonExpressionsFromUseBases(std::vector<BasedUser> &Uses) {
|
|||||||
///
|
///
|
||||||
static bool isZero(SCEVHandle &V) {
|
static bool isZero(SCEVHandle &V) {
|
||||||
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(V))
|
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(V))
|
||||||
return SC->getValue()->getZExtValue() == 0;
|
return SC->getValue()->isZero();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -883,17 +883,18 @@ unsigned LoopStrengthReduce::CheckForIVReuse(const SCEVHandle &Stride,
|
|||||||
if (!TLI) return 0;
|
if (!TLI) return 0;
|
||||||
|
|
||||||
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Stride)) {
|
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Stride)) {
|
||||||
int64_t SInt = SC->getValue()->getSExtValue();
|
APInt SInt(SC->getValue()->getValue());
|
||||||
if (SInt == 1) return 0;
|
if (SInt == 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
for (TargetLowering::legal_am_scale_iterator
|
for (TargetLowering::legal_am_scale_iterator
|
||||||
I = TLI->legal_am_scale_begin(), E = TLI->legal_am_scale_end();
|
I = TLI->legal_am_scale_begin(), E = TLI->legal_am_scale_end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
unsigned Scale = *I;
|
APInt Scale(SInt.getBitWidth(), *I);
|
||||||
if (unsigned(abs(SInt)) < Scale || (SInt % Scale) != 0)
|
if (SInt.abs().ult(Scale) || SInt.srem(Scale) != 0)
|
||||||
continue;
|
continue;
|
||||||
std::map<SCEVHandle, IVsOfOneStride>::iterator SI =
|
std::map<SCEVHandle, IVsOfOneStride>::iterator SI =
|
||||||
IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt/Scale, UIntPtrTy));
|
IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt.sdiv(Scale)));
|
||||||
if (SI == IVsByStride.end())
|
if (SI == IVsByStride.end())
|
||||||
continue;
|
continue;
|
||||||
for (std::vector<IVExpr>::iterator II = SI->second.IVs.begin(),
|
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.
|
// Only reuse previous IV if it would not require a type conversion.
|
||||||
if (isZero(II->Base) && II->Base->getType() == Ty) {
|
if (isZero(II->Base) && II->Base->getType() == Ty) {
|
||||||
IV = *II;
|
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.
|
// are reusing an IV, it has not been used to initialize the PHI node.
|
||||||
// Add it to the expression used to rewrite the uses.
|
// Add it to the expression used to rewrite the uses.
|
||||||
if (!isa<ConstantInt>(CommonBaseV) ||
|
if (!isa<ConstantInt>(CommonBaseV) ||
|
||||||
!cast<ConstantInt>(CommonBaseV)->isNullValue())
|
!cast<ConstantInt>(CommonBaseV)->isZero())
|
||||||
RewriteExpr = SCEVAddExpr::get(RewriteExpr,
|
RewriteExpr = SCEVAddExpr::get(RewriteExpr,
|
||||||
SCEVUnknown::get(CommonBaseV));
|
SCEVUnknown::get(CommonBaseV));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we know what we need to do, insert code before User for the
|
// Now that we know what we need to do, insert code before User for the
|
||||||
// immediate and any loop-variant expressions.
|
// 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.
|
// Add BaseV to the PHI value if needed.
|
||||||
RewriteExpr = SCEVAddExpr::get(RewriteExpr, SCEVUnknown::get(BaseV));
|
RewriteExpr = SCEVAddExpr::get(RewriteExpr, SCEVUnknown::get(BaseV));
|
||||||
|
|
||||||
|
@ -1048,7 +1048,7 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist) {
|
|||||||
cast<BinaryOperator>(I)->swapOperands();
|
cast<BinaryOperator>(I)->swapOperands();
|
||||||
if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1)))
|
if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1)))
|
||||||
if (CB->getType() == Type::Int1Ty) {
|
if (CB->getType() == Type::Int1Ty) {
|
||||||
if (CB->getZExtValue()) // X & 1 -> X
|
if (CB->isOne()) // X & 1 -> X
|
||||||
ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
|
ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
|
||||||
else // X & 0 -> 0
|
else // X & 0 -> 0
|
||||||
ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
|
ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
|
||||||
@ -1061,7 +1061,7 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist) {
|
|||||||
cast<BinaryOperator>(I)->swapOperands();
|
cast<BinaryOperator>(I)->swapOperands();
|
||||||
if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1)))
|
if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1)))
|
||||||
if (CB->getType() == Type::Int1Ty) {
|
if (CB->getType() == Type::Int1Ty) {
|
||||||
if (CB->getZExtValue()) // X | 1 -> 1
|
if (CB->isOne()) // X | 1 -> 1
|
||||||
ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
|
ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
|
||||||
else // X | 0 -> X
|
else // X | 0 -> X
|
||||||
ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
|
ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user