diff options
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/icmp.ll | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 9bf38189542..fea0d0245c8 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3010,7 +3010,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { return FoldICmpAddOpCst(I, X, Cst, I.getSwappedPredicate()); ConstantInt *Cst2; - if (match(Op1, m_ConstantInt(Cst)) && + if (I.isSigned() && + match(Op1, m_ConstantInt(Cst)) && match(Op0, m_Add(m_Value(X), m_ConstantInt(Cst2))) && cast<BinaryOperator>(Op0)->hasNoSignedWrap()) { // icmp X+Cst2, Cst --> icmp X, Cst-Cst2 diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll index 2e3ff24f6ba..63fefc08776 100644 --- a/llvm/test/Transforms/InstCombine/icmp.ll +++ b/llvm/test/Transforms/InstCombine/icmp.ll @@ -1409,3 +1409,13 @@ entry: %conv = zext i1 %cmp to i32 ret i32 %conv } + +; CHECK-LABEL: icmp_add_const_ult +; CHECK: %cmp = icmp ult i32 %add, 6 +define i32 @icmp_add_const_ult(i32 %a) #0 { +entry: + %add = add nsw i32 %a, -49 + %cmp = icmp ult i32 %add, 6 + %conv = zext i1 %cmp to i32 + ret i32 %conv +} |