llvm.org GIT mirror llvm / b042f8e
Teach InstCombine to fold "(shr exact X, Y) == 0" --> X == 0, fixing #1 from PR9343. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126643 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 8 years ago
2 changed file(s) with 30 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
12881288 }
12891289
12901290 case Instruction::LShr: // (icmp pred (shr X, ShAmt), CI)
1291 case Instruction::AShr:
1292 // Only handle equality comparisons of shift-by-constant.
1293 if (ConstantInt *ShAmt = dyn_cast(LHSI->getOperand(1)))
1294 if (Instruction *Res = FoldICmpShrCst(ICI, cast(LHSI),
1295 ShAmt))
1291 case Instruction::AShr: {
1292 // Handle equality comparisons of shift-by-constant.
1293 BinaryOperator *BO = cast(LHSI);
1294 if (ConstantInt *ShAmt = dyn_cast(LHSI->getOperand(1))) {
1295 if (Instruction *Res = FoldICmpShrCst(ICI, BO, ShAmt))
12961296 return Res;
1297 }
1298
1299 // Handle exact shr's.
1300 if (ICI.isEquality() && BO->isExact() && BO->hasOneUse()) {
1301 if (RHSV.isMinValue())
1302 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0), RHS);
1303 }
12971304 break;
1305 }
12981306
12991307 case Instruction::SDiv:
13001308 case Instruction::UDiv:
386386 %C = icmp slt i32 %B, 0
387387 ret i1 %C
388388 }
389
390 ; PR9343 #1
391 ; CHECK: test40
392 ; CHECK %B = icmp eq i32 %X, 0
393 define i1 @test40(i32 %X, i32 %Y) {
394 %A = ashr exact i32 %X, %Y
395 %B = icmp eq i32 %A, 0
396 ret i1 %B
397 }
398
399 ; CHECK: test41
400 ; CHECK %B = icmp ne i32 %X, 0
401 define i1 @test41(i32 %X, i32 %Y) {
402 %A = lshr exact i32 %X, %Y
403 %B = icmp ne i32 %A, 0
404 ret i1 %B
405 }