[llvm] r205010 - Revert "InstCombine: merge constants in both operands of icmp."

Reid Kleckner rnk at google.com
Sat Mar 29 11:02:47 PDT 2014


Can you leave behind the icmp_add_const_ult test case so we don't regress?


On Fri, Mar 28, 2014 at 7:50 AM, Erik Verbruggen <erikjv at me.com> wrote:

> Author: erikjv
> Date: Fri Mar 28 09:50:57 2014
> New Revision: 205010
>
> URL: http://llvm.org/viewvc/llvm-project?rev=205010&view=rev
> Log:
> Revert "InstCombine: merge constants in both operands of icmp."
>
> This reverts commit r204912, and follow-up commit r204948.
>
> This introduced a performance regression, and the fix is not completely
> clear yet.
>
>
> Modified:
>     llvm/trunk/lib/Target/README.txt
>     llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
>     llvm/trunk/test/Transforms/InstCombine/icmp.ll
>
> Modified: llvm/trunk/lib/Target/README.txt
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/README.txt?rev=205010&r1=205009&r2=205010&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Target/README.txt (original)
> +++ llvm/trunk/lib/Target/README.txt Fri Mar 28 09:50:57 2014
> @@ -930,6 +930,18 @@ optimized with "clang -emit-llvm-bc | op
>
>
>  //===---------------------------------------------------------------------===//
>
> +int g(int x) { return (x - 10) < 0; }
> +Should combine to "x <= 9" (the sub has nsw).  Currently not
> +optimized with "clang -emit-llvm-bc | opt -std-compile-opts".
> +
>
> +//===---------------------------------------------------------------------===//
> +
> +int g(int x) { return (x + 10) < 0; }
> +Should combine to "x < -10" (the add has nsw).  Currently not
> +optimized with "clang -emit-llvm-bc | opt -std-compile-opts".
> +
>
> +//===---------------------------------------------------------------------===//
> +
>  int f(int i, int j) { return i < j + 1; }
>  int g(int i, int j) { return j > i - 1; }
>  Should combine to "i <= j" (the add/sub has nsw).  Currently not
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=205010&r1=205009&r2=205010&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
> (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Fri Mar
> 28 09:50:57 2014
> @@ -3008,20 +3008,6 @@ Instruction *InstCombiner::visitICmpInst
>      // icmp X, X+Cst
>      if (match(Op1, m_Add(m_Value(X), m_ConstantInt(Cst))) && Op0 == X)
>        return FoldICmpAddOpCst(I, X, Cst, I.getSwappedPredicate());
> -
> -    ConstantInt *Cst2;
> -    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
> -      // iff Cst-Cst2 does not overflow
> -      bool Overflow;
> -      APInt NewCst = Cst->getValue().ssub_ov(Cst2->getValue(), Overflow);
> -      if (!Overflow)
> -        return new ICmpInst(I.getPredicate(), X,
> -                            ConstantInt::get(Cst->getType(), NewCst));
> -    }
>    }
>    return Changed ? &I : 0;
>  }
>
> Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=205010&r1=205009&r2=205010&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Fri Mar 28 09:50:57 2014
> @@ -1356,66 +1356,3 @@ define i1 @icmp_ashr_ashr_ne(i32 %a, i32
>   %z = icmp ne i32 %x, %y
>   ret i1 %z
>  }
> -
> -; CHECK-LABEL: icmp_add_const_const1
> -; CHECK: %cmp = icmp slt i32 %x, -10
> -; CHECK-NOT: %add = add nsw i32 %x, 10
> -define i32 @icmp_add_const_const1(i32 %x) nounwind ssp uwtable {
> -entry:
> -  %add = add nsw i32 %x, 10
> -  %cmp = icmp slt i32 %add, 0
> -  %conv = zext i1 %cmp to i32
> -  ret i32 %conv
> -}
> -
> -; CHECK-LABEL: icmp_add_const_const2
> -; CHECK: %cmp = icmp slt i32 %x, -10
> -; CHECK-NOT: %add = add nsw i32 %x, 10
> -define i32 @icmp_add_const_const2(i32 %x) nounwind ssp uwtable {
> -entry:
> -  %add = add nsw i32 10, %x
> -  %cmp = icmp sgt i32 0, %add
> -  %conv = zext i1 %cmp to i32
> -  ret i32 %conv
> -}
> -
> -; CHECK-LABEL: icmp_add_const_const3
> -; CHECK: %cmp = icmp slt i32 %x, 20
> -; CHECK-NOT: %sub = add nsw i32 %x, -10
> -define i32 @icmp_add_const_const3(i32 %x) nounwind ssp uwtable {
> -entry:
> -  %add = add nsw i32 -10, %x
> -  %cmp = icmp sgt i32 10, %add
> -  %conv = zext i1 %cmp to i32
> -  ret i32 %conv
> -}
> -
> -; CHECK-LABEL: icmp_add_const_intmin
> -; CHECK: %cmp = icmp ne i32 %x, 2147483638
> -define i32 @icmp_add_const_intmin(i32 %x) nounwind ssp uwtable {
> -entry:
> -  %add = add nsw i32 %x, 10
> -  %cmp = icmp sgt i32 %add, -2147483648
> -  %conv = zext i1 %cmp to i32
> -  ret i32 %conv
> -}
> -
> -; CHECK-LABEL: icmp_add_const_intmax
> -; CHECK: %cmp = icmp ne i32 %x, 2147483637
> -define i32 @icmp_add_const_intmax(i32 %x) nounwind ssp uwtable {
> -entry:
> -  %add = add nsw i32 %x, 10
> -  %cmp = icmp slt i32 %add, 2147483647
> -  %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
> -}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140329/b340f5b4/attachment.html>


More information about the llvm-commits mailing list