llvm.org GIT mirror llvm / cf96db2
Be more careful when transforming | to +. Patch from Wojciech Matyjewicz. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44248 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 12 years ago
2 changed file(s) with 26 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
14831483 case Instruction::SDiv:
14841484 return SE.getSDivExpr(getSCEV(I->getOperand(0)),
14851485 getSCEV(I->getOperand(1)));
1486 break;
1487
14881486 case Instruction::Sub:
14891487 return SE.getMinusSCEV(getSCEV(I->getOperand(0)),
14901488 getSCEV(I->getOperand(1)));
14911489 case Instruction::Or:
14921490 // If the RHS of the Or is a constant, we may have something like:
1493 // X*4+1 which got turned into X*4|1. Handle this as an add so loop
1491 // X*4+1 which got turned into X*4|1. Handle this as an Add so loop
14941492 // optimizations will transparently handle this case.
1493 //
1494 // In order for this transformation to be safe, the LHS must be of the
1495 // form X*(2^n) and the Or constant must be less than 2^n.
1496
14951497 if (ConstantInt *CI = dyn_cast(I->getOperand(1))) {
14961498 SCEVHandle LHS = getSCEV(I->getOperand(0));
14971499 APInt CommonFact(GetConstantFactor(LHS));
14981500 assert(!CommonFact.isMinValue() &&
14991501 "Common factor should at least be 1!");
1500 if (CommonFact.ugt(CI->getValue())) {
1501 // If the LHS is a multiple that is larger than the RHS, use +.
1502 const APInt &CIVal = CI->getValue();
1503 if (CommonFact.countTrailingZeros() >=
1504 (CIVal.getBitWidth() - CIVal.countLeadingZeros()))
15021505 return SE.getAddExpr(LHS,
15031506 getSCEV(I->getOperand(1)));
1504 }
15051507 }
15061508 break;
15071509 case Instruction::Xor:
0 ; RUN: llvm-as < %s | opt -analyze -scalar-evolution 2>&1 | grep -e '--> %b'
1 ; PR1810
2
3 define void @fun() {
4 entry:
5 br label %header
6 header:
7 %i = phi i32 [ 1, %entry ], [ %i.next, %body ]
8 %cond = icmp eq i32 %i, 10
9 br i1 %cond, label %exit, label %body
10 body:
11 %a = mul i32 %i, 5
12 %b = or i32 %a, 1
13 %i.next = add i32 %i, 1
14 br label %header
15 exit:
16 ret void
17 }