llvm.org GIT mirror
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).
 1483 1483 case Instruction::SDiv: 1484 1484 return SE.getSDivExpr(getSCEV(I->getOperand(0)), 1485 1485 getSCEV(I->getOperand(1))); 1486 break; 1487 1488 1486 case Instruction::Sub: 1489 1487 return SE.getMinusSCEV(getSCEV(I->getOperand(0)), 1490 1488 getSCEV(I->getOperand(1))); 1491 1489 case Instruction::Or: 1492 1490 // 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⏎ 1494 1492 // 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 1495 1497 if (ConstantInt *CI = dyn_cast(I->getOperand(1))) { 1496 1498 SCEVHandle LHS = getSCEV(I->getOperand(0)); 1497 1499 APInt CommonFact(GetConstantFactor(LHS)); 1498 1500 assert(!CommonFact.isMinValue() && 1499 1501 "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())) 1502 1505 return SE.getAddExpr(LHS, 1503 1506 getSCEV(I->getOperand(1))); 1504 } 1505 1507 } 1506 1508 break; 1507 1509 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 }