mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
Allow "exhaustive" trip count evaluation on phi nodes with all
constant operands. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106537 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e4acff8720
commit
9d4588ffad
@ -4133,8 +4133,7 @@ static PHINode *getConstantEvolvingPHI(Value *V, const Loop *L) {
|
||||
// constant or derived from a PHI node themselves.
|
||||
PHINode *PHI = 0;
|
||||
for (unsigned Op = 0, e = I->getNumOperands(); Op != e; ++Op)
|
||||
if (!(isa<Constant>(I->getOperand(Op)) ||
|
||||
isa<GlobalValue>(I->getOperand(Op)))) {
|
||||
if (!isa<Constant>(I->getOperand(Op))) {
|
||||
PHINode *P = getConstantEvolvingPHI(I->getOperand(Op), L);
|
||||
if (P == 0) return 0; // Not evolving from PHI
|
||||
if (PHI == 0)
|
||||
@ -4155,11 +4154,9 @@ static Constant *EvaluateExpression(Value *V, Constant *PHIVal,
|
||||
const TargetData *TD) {
|
||||
if (isa<PHINode>(V)) return PHIVal;
|
||||
if (Constant *C = dyn_cast<Constant>(V)) return C;
|
||||
if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) return GV;
|
||||
Instruction *I = cast<Instruction>(V);
|
||||
|
||||
std::vector<Constant*> Operands;
|
||||
Operands.resize(I->getNumOperands());
|
||||
std::vector<Constant*> Operands(I->getNumOperands());
|
||||
|
||||
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
|
||||
Operands[i] = EvaluateExpression(I->getOperand(i), PHIVal, TD);
|
||||
@ -4201,8 +4198,8 @@ ScalarEvolution::getConstantEvolutionLoopExitValue(PHINode *PN,
|
||||
return RetVal = 0; // Must be a constant.
|
||||
|
||||
Value *BEValue = PN->getIncomingValue(SecondIsBackedge);
|
||||
PHINode *PN2 = getConstantEvolvingPHI(BEValue, L);
|
||||
if (PN2 != PN)
|
||||
if (getConstantEvolvingPHI(BEValue, L) != PN &&
|
||||
!isa<Constant>(BEValue))
|
||||
return RetVal = 0; // Not derived from same PHI.
|
||||
|
||||
// Execute the loop symbolically to determine the exit value.
|
||||
@ -4249,8 +4246,9 @@ ScalarEvolution::ComputeBackedgeTakenCountExhaustively(const Loop *L,
|
||||
if (StartCST == 0) return getCouldNotCompute(); // Must be a constant.
|
||||
|
||||
Value *BEValue = PN->getIncomingValue(SecondIsBackedge);
|
||||
PHINode *PN2 = getConstantEvolvingPHI(BEValue, L);
|
||||
if (PN2 != PN) return getCouldNotCompute(); // Not derived from same PHI.
|
||||
if (getConstantEvolvingPHI(BEValue, L) != PN &&
|
||||
!isa<Constant>(BEValue))
|
||||
return getCouldNotCompute(); // Not derived from same PHI.
|
||||
|
||||
// Okay, we find a PHI node that defines the trip count of this loop. Execute
|
||||
// the loop symbolically to determine when the condition gets a value of
|
||||
|
@ -105,3 +105,22 @@ bb2:
|
||||
retbb:
|
||||
ret void
|
||||
}
|
||||
|
||||
; PHI nodes with all constant operands.
|
||||
|
||||
; CHECK: Determining loop execution counts for: @constant_phi_operands
|
||||
; CHECK: Loop %loop: backedge-taken count is 1
|
||||
; CHECK: Loop %loop: max backedge-taken count is 1
|
||||
|
||||
define void @constant_phi_operands() nounwind {
|
||||
entry:
|
||||
br label %loop
|
||||
|
||||
loop:
|
||||
%i = phi i64 [ 1, %loop ], [ 0, %entry ]
|
||||
%exitcond = icmp eq i64 %i, 1
|
||||
br i1 %exitcond, label %return, label %loop
|
||||
|
||||
return:
|
||||
ret void
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user