diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -2964,6 +2964,14 @@ } } + // 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); + } + // x >> y <=u x // x udiv y <=u x. if (LBO && (match(LBO, m_LShr(m_Specific(RHS), m_Value())) || diff --git a/llvm/test/Transforms/InstSimplify/compare.ll b/llvm/test/Transforms/InstSimplify/compare.ll --- a/llvm/test/Transforms/InstSimplify/compare.ll +++ b/llvm/test/Transforms/InstSimplify/compare.ll @@ -723,6 +723,22 @@ 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 +} + ; PR9343 #15 define i1 @srem2(i16 %X, i32 %Y) { ; CHECK-LABEL: @srem2(