Index: llvm/lib/Analysis/InstructionSimplify.cpp =================================================================== --- llvm/lib/Analysis/InstructionSimplify.cpp +++ llvm/lib/Analysis/InstructionSimplify.cpp @@ -2814,6 +2814,14 @@ } } + // icmp pred (urem X, Y), X + if (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); + } + // x >> y <=u x // x udiv y <=u x. if (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,40 @@ ret i1 %B } +define i1 @urem8(i8 %X, i8 %Y) { +; CHECK-LABEL: @urem8( +; CHECK-NEXT: ret i1 true +; + %A = urem i8 %X, %Y + %B = icmp ule i8 %A, %X + ret i1 %B +} + +define i1 @urem9(i8 %X, i8 %Y) { + ; CHECK-LABEL: @urem9( + ; CHECK-NEXT: ret i1 false + ; + %A = urem i8 %X, %Y + %B = icmp ugt i8 %A, %X + ret i1 %B +} + +define i1 @urem10(i8 %X, i8 %Y) { + ; CHECK-LABEL: @urem10( + ; CHECK-NEXT: ret i1 true + %A = urem i8 %X, %Y + %B = icmp uge i8 %X, %A + ret i1 %B +} + +define i1 @urem11(i8 %X, i8 %Y) { + ; CHECK-LABEL: @urem11( + ; CHECK-NEXT: ret i1 false + %A = urem i8 %X, %Y + %B = icmp ult i8 %X, %A + ret i1 %B +} + ; PR9343 #15 define i1 @srem2(i16 %X, i32 %Y) { ; CHECK-LABEL: @srem2(