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/and3.ll =================================================================== --- /dev/null +++ test/Transforms/InstCombine/and3.ll @@ -0,0 +1,17 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -instcombine -S | FileCheck %s + +; x > y && x != 0 -> x > y + +define i32 @test1(i32 %x, i32 %y) { +; CHECK-LABEL: @test1( +; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 %x, %y +; CHECK-NEXT: [[TMP2:%.*]] = zext i1 [[TMP1]] to i32 +; CHECK-NEXT: ret i32 [[TMP2]] +; + %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 +}