[llvm-commits] [llvm] r145618 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCompares.cpp test/Transforms/InstCombine/icmp.ll

Benjamin Kramer benny.kra at googlemail.com
Thu Dec 1 12:05:56 PST 2011


On 01.12.2011, at 20:13, Pete Cooper wrote:

> Author: pete
> Date: Thu Dec  1 13:13:26 2011
> New Revision: 145618
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=145618&view=rev
> Log:
> Improved fix for abs(val) != 0 to check other similar case.  Also fixed style issues and confusing comment

what about abs(val) == 0? Should be fairly easy to extend your optimization for that case.

- Ben

> Modified:
>    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
>    llvm/trunk/test/Transforms/InstCombine/icmp.ll
> 
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=145618&r1=145617&r2=145618&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Thu Dec  1 13:13:26 2011
> @@ -1796,15 +1796,19 @@
>     return ReplaceInstUsesWith(I, V);
> 
>   // comparing -val or val with non-zero is the same as just comparing val
> -  // ie, (val != 0) == (-val != 0)
> +  // ie, abs(val) != 0 -> val != 0
>   if (I.getPredicate() == ICmpInst::ICMP_NE && match(Op1, m_Zero()))
>   {
> -    Value *Cond, *SubSrc, *SelectFalse;
> -    if (match(Op0, m_Select(m_Value(Cond), m_Sub(m_Zero(), m_Value(SubSrc)),
> +    Value *Cond, *SelectTrue, *SelectFalse;
> +    if (match(Op0, m_Select(m_Value(Cond), m_Value(SelectTrue),
>                             m_Value(SelectFalse)))) {
> -      if (SubSrc == SelectFalse) {
> -        return CmpInst::Create(Instruction::ICmp, I.getPredicate(),
> -                               SubSrc, Op1);
> +      if (Value *V = dyn_castNegVal(SelectTrue)) {
> +        if (V == SelectFalse)
> +          return CmpInst::Create(Instruction::ICmp, I.getPredicate(), V, Op1);
> +      }
> +      else if (Value *V = dyn_castNegVal(SelectFalse)) {
> +        if (V == SelectTrue)
> +          return CmpInst::Create(Instruction::ICmp, I.getPredicate(), V, Op1);
>       }
>     }
>   }
> 
> Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=145618&r1=145617&r2=145618&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Thu Dec  1 13:13:26 2011
> @@ -561,12 +561,22 @@
> }
> 
> ; rdar://problem/10482509
> -; CHECK: @cmpabs
> +; CHECK: @cmpabs1
> ; CHECK-NEXT: icmp ne
> -define zeroext i1 @cmpabs(i64 %val) {
> +define zeroext i1 @cmpabs1(i64 %val) {
>   %sub = sub nsw i64 0, %val
>   %cmp = icmp slt i64 %val, 0
>   %sub.val = select i1 %cmp, i64 %sub, i64 %val
>   %tobool = icmp ne i64 %sub.val, 0
>   ret i1 %tobool
> }
> +
> +; CHECK: @cmpabs2
> +; CHECK-NEXT: icmp ne
> +define zeroext i1 @cmpabs2(i64 %val) {
> +  %sub = sub nsw i64 0, %val
> +  %cmp = icmp slt i64 %val, 0
> +  %sub.val = select i1 %cmp, i64 %val, i64 %sub
> +  %tobool = icmp ne i64 %sub.val, 0
> +  ret i1 %tobool
> +}
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list