llvm.org GIT mirror llvm / 9d4588f
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 Dan Gohman 9 years ago
2 changed file(s) with 26 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
41324132 // constant or derived from a PHI node themselves.
41334133 PHINode *PHI = 0;
41344134 for (unsigned Op = 0, e = I->getNumOperands(); Op != e; ++Op)
4135 if (!(isa(I->getOperand(Op)) ||
4136 isa(I->getOperand(Op)))) {
4135 if (!isa(I->getOperand(Op))) {
41374136 PHINode *P = getConstantEvolvingPHI(I->getOperand(Op), L);
41384137 if (P == 0) return 0; // Not evolving from PHI
41394138 if (PHI == 0)
41544153 const TargetData *TD) {
41554154 if (isa(V)) return PHIVal;
41564155 if (Constant *C = dyn_cast(V)) return C;
4157 if (GlobalValue *GV = dyn_cast(V)) return GV;
41584156 Instruction *I = cast(V);
41594157
4160 std::vector Operands;
4161 Operands.resize(I->getNumOperands());
4158 std::vector Operands(I->getNumOperands());
41624159
41634160 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
41644161 Operands[i] = EvaluateExpression(I->getOperand(i), PHIVal, TD);
42004197 return RetVal = 0; // Must be a constant.
42014198
42024199 Value *BEValue = PN->getIncomingValue(SecondIsBackedge);
4203 PHINode *PN2 = getConstantEvolvingPHI(BEValue, L);
4204 if (PN2 != PN)
4200 if (getConstantEvolvingPHI(BEValue, L) != PN &&
4201 !isa(BEValue))
42054202 return RetVal = 0; // Not derived from same PHI.
42064203
42074204 // Execute the loop symbolically to determine the exit value.
42484245 if (StartCST == 0) return getCouldNotCompute(); // Must be a constant.
42494246
42504247 Value *BEValue = PN->getIncomingValue(SecondIsBackedge);
4251 PHINode *PN2 = getConstantEvolvingPHI(BEValue, L);
4252 if (PN2 != PN) return getCouldNotCompute(); // Not derived from same PHI.
4248 if (getConstantEvolvingPHI(BEValue, L) != PN &&
4249 !isa(BEValue))
4250 return getCouldNotCompute(); // Not derived from same PHI.
42534251
42544252 // Okay, we find a PHI node that defines the trip count of this loop. Execute
42554253 // the loop symbolically to determine when the condition gets a value of
104104 retbb:
105105 ret void
106106 }
107
108 ; PHI nodes with all constant operands.
109
110 ; CHECK: Determining loop execution counts for: @constant_phi_operands
111 ; CHECK: Loop %loop: backedge-taken count is 1
112 ; CHECK: Loop %loop: max backedge-taken count is 1
113
114 define void @constant_phi_operands() nounwind {
115 entry:
116 br label %loop
117
118 loop:
119 %i = phi i64 [ 1, %loop ], [ 0, %entry ]
120 %exitcond = icmp eq i64 %i, 1
121 br i1 %exitcond, label %return, label %loop
122
123 return:
124 ret void
125 }