From: Benjamin Kramer Date: Sun, 12 Oct 2014 14:02:34 +0000 (+0000) Subject: InstCombine: Turn (x != 0 & x X < 13 return Builder->CreateICmpULT(Val, LHSCst); + if (LHSCst->isNullValue()) // (X != 0 & X u< 14) -> X-1 u< 13 + return InsertRangeTest(Val, AddOne(LHSCst), RHSCst, false, true); break; // (X != 13 & X u< 15) -> no change case ICmpInst::ICMP_SLT: if (LHSCst == SubOne(RHSCst)) // (X != 13 & X s< 14) -> X < 13 diff --git a/test/Transforms/InstCombine/and2.ll b/test/Transforms/InstCombine/and2.ll index c76bb4499e8..96b535dda99 100644 --- a/test/Transforms/InstCombine/and2.ll +++ b/test/Transforms/InstCombine/and2.ll @@ -66,3 +66,14 @@ define i1 @test7(i32 %i, i1 %b) { %and2 = and i1 %and1, %cmp2 ret i1 %and2 } + +define i1 @test8(i32 %i) { +; CHECK-LABEL: @test8( +; CHECK-NEXT: [[DEC:%.*]] = add i32 %i, -1 +; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[DEC]], 13 +; CHECK-NEXT: ret i1 [[CMP]] + %cmp1 = icmp ne i32 %i, 0 + %cmp2 = icmp ult i32 %i, 14 + %cond = and i1 %cmp1, %cmp2 + ret i1 %cond +}