Index: llvm/lib/Analysis/InstructionSimplify.cpp =================================================================== --- llvm/lib/Analysis/InstructionSimplify.cpp +++ llvm/lib/Analysis/InstructionSimplify.cpp @@ -2964,6 +2964,22 @@ } } + // icmp pred (urem Y, X), Y + if (LBO && match(LBO, m_URem(m_Specific(RHS), m_Value()))) { + if (Pred == ICmpInst::ICMP_ULE) + return getTrue(ITy); + if (Pred == ICmpInst::ICMP_UGT) + return getFalse(ITy); + } + + // icmp pred Y, (urem Y, X), + if (RBO && match(RBO, m_URem(m_Specific(LHS), m_Value()))) { + if (Pred == ICmpInst::ICMP_ULE) + return getFalse(ITy); + if (Pred == ICmpInst::ICMP_UGT) + return getTrue(ITy); + } + // x >> y <=u x // x udiv y <=u x. if (LBO && (match(LBO, m_LShr(m_Specific(RHS), m_Value())) || Index: llvm/test/Transforms/InstSimplify/compare.ll =================================================================== --- llvm/test/Transforms/InstSimplify/compare.ll +++ llvm/test/Transforms/InstSimplify/compare.ll @@ -723,6 +723,38 @@ ret i1 %B } +define i1 @urem8(i32 %X, i32 %Y) { + ; CHECK-LABEL: @urem8( + ; CHECK-NEXT: ret i1 true + %A = urem i32 %X, %Y + %B = icmp ule i32 %A, %Y + ret i1 %B +} + +define i1 @urem9(i32 %X, i32 %Y) { + ; CHECK-LABEL: @urem9( + ; CHECK-NEXT: ret i1 false + %A = urem i32 %X, %Y + %B = icmp ugt i32 %A, %Y + ret i1 %B +} + +define i1 @urem10(i8 %X, i8 %Y) { + ; CHECK-LABEL: @urem8( + ; CHECK-NEXT: ret i1 true + %A = urem i8 %X, %Y + %B = icmp ule i8 %Y, %A + ret i1 %B +} + +define i1 @ure11(i8 %X, i8 %Y) { + ; CHECK-LABEL: @urem9( + ; CHECK-NEXT: ret i1 false + %A = urem i8 %X, %Y + %B = icmp ugt i8 %Y, %A + ret i1 %B +} + ; PR9343 #15 define i1 @srem2(i16 %X, i32 %Y) { ; CHECK-LABEL: @srem2(