llvm.org GIT mirror llvm / b028593
Fix bogus overflow checks by replacing them with actual overflow checks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71284 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
2 changed file(s) with 28 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
13801380 dyn_cast(AR->getStepRecurrence(*this)))
13811381 if (!Step->getValue()->getValue()
13821382 .urem(RHSC->getValue()->getValue()) &&
1383 getTruncateExpr(getZeroExtendExpr(AR, ExtTy), Ty) == AR) {
1383 getZeroExtendExpr(AR, ExtTy) ==
1384 getAddRecExpr(getZeroExtendExpr(AR->getStart(), ExtTy),
1385 getZeroExtendExpr(Step, ExtTy),
1386 AR->getLoop())) {
13841387 std::vector Operands;
13851388 for (unsigned i = 0, e = AR->getNumOperands(); i != e; ++i)
13861389 Operands.push_back(getUDivExpr(AR->getOperand(i), RHS));
13871390 return getAddRecExpr(Operands, AR->getLoop());
13881391 }
13891392 // (A*B)/C --> A*(B/C) if safe and B/C can be folded.
1390 if (const SCEVMulExpr *M = dyn_cast(LHS))
1391 if (getTruncateExpr(getZeroExtendExpr(M, ExtTy), Ty) == M)
1393 if (const SCEVMulExpr *M = dyn_cast(LHS)) {
1394 std::vector Operands;
1395 for (unsigned i = 0, e = M->getNumOperands(); i != e; ++i)
1396 Operands.push_back(getZeroExtendExpr(M->getOperand(i), ExtTy));
1397 if (getZeroExtendExpr(M, ExtTy) == getMulExpr(Operands))
13921398 // Find an operand that's safely divisible.
13931399 for (unsigned i = 0, e = M->getNumOperands(); i != e; ++i) {
13941400 SCEVHandle Op = M->getOperand(i);
13951401 SCEVHandle Div = getUDivExpr(Op, RHSC);
13961402 if (!isa(Div) && getMulExpr(Div, RHSC) == Op) {
1397 std::vector Operands = M->getOperands();
1403 Operands = M->getOperands();
13981404 Operands[i] = Div;
13991405 return getMulExpr(Operands);
14001406 }
14011407 }
1408 }
14021409 // (A+B)/C --> (A/C + B/C) if safe and A/C and B/C can be folded.
1403 if (const SCEVAddRecExpr *A = dyn_cast(LHS))
1404 if (getTruncateExpr(getZeroExtendExpr(A, ExtTy), Ty) == A) {
1405 std::vector Operands;
1410 if (const SCEVAddRecExpr *A = dyn_cast(LHS)) {
1411 std::vector Operands;
1412 for (unsigned i = 0, e = A->getNumOperands(); i != e; ++i)
1413 Operands.push_back(getZeroExtendExpr(A->getOperand(i), ExtTy));
1414 if (getZeroExtendExpr(A, ExtTy) == getAddExpr(Operands)) {
1415 Operands.clear();
14061416 for (unsigned i = 0, e = A->getNumOperands(); i != e; ++i) {
14071417 SCEVHandle Op = getUDivExpr(A->getOperand(i), RHS);
14081418 if (isa(Op) || getMulExpr(Op, RHS) != A->getOperand(i))
14121422 if (Operands.size() == A->getNumOperands())
14131423 return getAddExpr(Operands);
14141424 }
1425 }
14151426
14161427 // Fold if both operands are constant.
14171428 if (const SCEVConstant *LHSC = dyn_cast(LHS)) {
0 ; RUN: llvm-as < %s | opt -scalar-evolution -analyze -disable-output \
1 ; RUN: | grep {\\--> ((-128 \\* %a) /u -128)}
2
3 ; Don't let ScalarEvolution fold this div away.
4
5 define i8 @foo(i8 %a) {
6 %t0 = shl i8 %a, 7
7 %t1 = lshr i8 %t0, 7
8 ret i8 %t1
9 }