Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp +++ lib/Analysis/InstructionSimplify.cpp @@ -1309,7 +1309,7 @@ ICmpInst::isUnsigned(UnsignedPred)) ; else if (match(UnsignedICmp, - m_ICmp(UnsignedPred, m_Value(Y), m_Specific(X))) && + m_ICmp(UnsignedPred, m_Specific(Y), m_Value(X))) && ICmpInst::isUnsigned(UnsignedPred)) UnsignedPred = ICmpInst::getSwappedPredicate(UnsignedPred); else Index: test/Transforms/InstCombine/range-check.ll =================================================================== --- test/Transforms/InstCombine/range-check.ll +++ test/Transforms/InstCombine/range-check.ll @@ -157,3 +157,15 @@ ret i1 %c } +; CHECK-LABEL: @test1( +; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 %x, %y +; CHECK-NEXT: [[TMP2:%.*]] = zext i1 [[TMP1]] to i32 +; CHECK-NEXT: ret i32 [[TMP2]] +define i32 @test1(i32 %x, i32 %y) { + %1 = icmp ugt i32 %x, %y + %2 = icmp ne i32 %x, 0 + %3 = and i1 %2, %1 + %4 = zext i1 %3 to i32 + ret i32 %4 +} + Index: test/Transforms/InstSimplify/AndOrXor.ll =================================================================== --- test/Transforms/InstSimplify/AndOrXor.ll +++ test/Transforms/InstSimplify/AndOrXor.ll @@ -374,6 +374,17 @@ define i1 @and_icmp2(i32 %x, i32 %y) { ; CHECK-LABEL: @and_icmp2( +; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: ret i1 [[TMP1]] +; + %1 = icmp ugt i32 %x, %y + %2 = icmp ne i32 %x, 0 + %3 = and i1 %1, %2 + ret i1 %3 +} + +define i1 @and_icmp3(i32 %x, i32 %y) { +; CHECK-LABEL: @and_icmp3( ; CHECK-NEXT: ret i1 false ; %1 = icmp ult i32 %x, %y @@ -382,6 +393,16 @@ ret i1 %3 } +define i1 @and_icmp4(i32 %x, i32 %y) { +; CHECK-LABEL: @and_icmp4( +; CHECK-NEXT: ret i1 false +; + %1 = icmp ugt i32 %x, %y + %2 = icmp eq i32 %x, 0 + %3 = and i1 %1, %2 + ret i1 %3 +} + define i1 @or_icmp1(i32 %x, i32 %y) { ; CHECK-LABEL: @or_icmp1( ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i32 [[Y:%.*]], 0 @@ -395,6 +416,17 @@ define i1 @or_icmp2(i32 %x, i32 %y) { ; CHECK-LABEL: @or_icmp2( +; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i32 [[Y:%.*]], 0 +; CHECK-NEXT: ret i1 [[TMP1]] +; + %1 = icmp ugt i32 %x, %y + %2 = icmp ne i32 %x, 0 + %3 = or i1 %1, %2 + ret i1 %3 +} + +define i1 @or_icmp3(i32 %x, i32 %y) { +; CHECK-LABEL: @or_icmp3( ; CHECK-NEXT: ret i1 true ; %1 = icmp uge i32 %x, %y @@ -403,8 +435,18 @@ ret i1 %3 } -define i1 @or_icmp3(i32 %x, i32 %y) { -; CHECK-LABEL: @or_icmp3( +define i1 @or_icmp4(i32 %x, i32 %y) { +; CHECK-LABEL: @or_icmp4( +; CHECK-NEXT: ret i1 true +; + %1 = icmp ule i32 %x, %y + %2 = icmp ne i32 %x, 0 + %3 = or i1 %1, %2 + ret i1 %3 +} + +define i1 @or_icmp5(i32 %x, i32 %y) { +; CHECK-LABEL: @or_icmp5( ; CHECK-NEXT: [[TMP1:%.*]] = icmp uge i32 [[X:%.*]], [[Y:%.*]] ; CHECK-NEXT: ret i1 [[TMP1]] ; @@ -414,6 +456,17 @@ ret i1 %3 } +define i1 @or_icmp6(i32 %x, i32 %y) { +; CHECK-LABEL: @or_icmp6( +; CHECK-NEXT: [[TMP1:%.*]] = icmp ule i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: ret i1 [[TMP1]] +; + %1 = icmp ule i32 %x, %y + %2 = icmp eq i32 %x, 0 + %3 = or i1 %1, %2 + ret i1 %3 +} + ; PR27869 - Look through casts to eliminate cmps and bitwise logic. define i32 @and_of_zexted_icmps(i32 %i) {