llvm.org GIT mirror llvm / 60a2e51
Merge from mainline. Disallow the construction of SCEVs with could-not-compute operands. Catch CNCs returned by BinomialCoefficient and don't try to operate with them. This replaces the previous fix for PR2857. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_24@57958 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 10 years ago
1 changed file(s) with 6 addition(s) and 72 deletion(s). Raw diff Collapse all Expand all
643643 // The computation is correct in the face of overflow provided that the
644644 // multiplication is performed _after_ the evaluation of the binomial
645645 // coefficient.
646 SCEVHandle Val =
647 SE.getMulExpr(getOperand(i),
648 BinomialCoefficient(It, i, SE,
649 cast(getType())));
650 Result = SE.getAddExpr(Result, Val);
646 SCEVHandle Coeff = BinomialCoefficient(It, i, SE,
647 cast(getType()));
648 if (isa(Coeff))
649 return Coeff;
650
651 Result = SE.getAddExpr(Result, SE.getMulExpr(getOperand(i), Coeff));
651652 }
652653 return Result;
653654 }
675676 return getAddRecExpr(Operands, AddRec->getLoop());
676677 }
677678
678 if (isa(Op))
679 return new SCEVCouldNotCompute();
680
681679 SCEVTruncateExpr *&Result = (*SCEVTruncates)[std::make_pair(Op, Ty)];
682680 if (Result == 0) Result = new SCEVTruncateExpr(Op, Ty);
683681 return Result;
693691 // operands (often constants). This would allow analysis of something like
694692 // this: for (unsigned char X = 0; X < 100; ++X) { int Y = X; }
695693
696 if (isa(Op))
697 return new SCEVCouldNotCompute();
698
699694 SCEVZeroExtendExpr *&Result = (*SCEVZeroExtends)[std::make_pair(Op, Ty)];
700695 if (Result == 0) Result = new SCEVZeroExtendExpr(Op, Ty);
701696 return Result;
710705 // did not overflow the old, smaller, value, we can sign extend all of the
711706 // operands (often constants). This would allow analysis of something like
712707 // this: for (signed char X = 0; X < 100; ++X) { int Y = X; }
713
714 if (isa(Op))
715 return new SCEVCouldNotCompute();
716708
717709 SCEVSignExtendExpr *&Result = (*SCEVSignExtends)[std::make_pair(Op, Ty)];
718710 if (Result == 0) Result = new SCEVSignExtendExpr(Op, Ty);
741733
742734 // Sort by complexity, this groups all similar expression types together.
743735 GroupByComplexity(Ops);
744
745 // Could not compute plus anything equals could not compute.
746 if (isa(Ops.back()))
747 return new SCEVCouldNotCompute();
748736
749737 // If there are any constants, fold them together.
750738 unsigned Idx = 0;
971959 // Sort by complexity, this groups all similar expression types together.
972960 GroupByComplexity(Ops);
973961
974 if (isa(Ops.back())) {
975 // CNC * 0 = 0
976 for (unsigned i = 0, e = Ops.size() - 1; i != e; ++i) {
977 if (Ops[i]->getSCEVType() != scConstant)
978 break;
979
980 SCEVConstant *SC = cast(Ops[i]);
981 if (SC->getValue()->isMinValue(false))
982 return SC;
983 }
984
985 // Otherwise, we can't compute it.
986 return new SCEVCouldNotCompute();
987 }
988
989962 // If there are any constants, fold them together.
990963 unsigned Idx = 0;
991964 if (SCEVConstant *LHSC = dyn_cast(Ops[0])) {
11511124
11521125 // FIXME: implement folding of (X*4)/4 when we know X*4 doesn't overflow.
11531126
1154 if (isa(LHS) || isa(RHS))
1155 return new SCEVCouldNotCompute();
1156
11571127 SCEVUDivExpr *&Result = (*SCEVUDivs)[std::make_pair(LHS, RHS)];
11581128 if (Result == 0) Result = new SCEVUDivExpr(LHS, RHS);
11591129 return Result;
12011171 }
12021172 }
12031173
1204 // Refuse to build an AddRec out of SCEVCouldNotCompute.
1205 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
1206 if (isa(Operands[i]))
1207 return new SCEVCouldNotCompute();
1208 }
1209
12101174 SCEVAddRecExpr *&Result =
12111175 (*SCEVAddRecExprs)[std::make_pair(L, std::vector(Operands.begin(),
12121176 Operands.end()))];
12281192
12291193 // Sort by complexity, this groups all similar expression types together.
12301194 GroupByComplexity(Ops);
1231
1232 if (isa(Ops.back())) {
1233 // CNC smax +inf = +inf.
1234 for (unsigned i = 0, e = Ops.size() - 1; i != e; ++i) {
1235 if (Ops[i]->getSCEVType() != scConstant)
1236 break;
1237
1238 SCEVConstant *SC = cast(Ops[i]);
1239 if (SC->getValue()->isMaxValue(true))
1240 return SC;
1241 }
1242
1243 // Otherwise, we can't compute it.
1244 return new SCEVCouldNotCompute();
1245 }
12461195
12471196 // If there are any constants, fold them together.
12481197 unsigned Idx = 0;
13231272
13241273 // Sort by complexity, this groups all similar expression types together.
13251274 GroupByComplexity(Ops);
1326
1327 if (isa(Ops[0])) {
1328 // CNC umax inf = inf.
1329 for (unsigned i = 0, e = Ops.size() - 1; i != e; ++i) {
1330 if (Ops[i]->getSCEVType() != scConstant)
1331 break;
1332
1333 SCEVConstant *SC = cast(Ops[i]);
1334 if (SC->getValue()->isMaxValue(false))
1335 return SC;
1336 }
1337
1338 // Otherwise, we can't compute it.
1339 return new SCEVCouldNotCompute();
1340 }
13411275
13421276 // If there are any constants, fold them together.
13431277 unsigned Idx = 0;