[llvm-commits] [llvm] r145563 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCompares.cpp test/Transforms/InstCombine/compare-abs-nonzero.ll

Peter Cooper peter_cooper at apple.com
Wed Nov 30 20:39:00 PST 2011


Thanks, good point.  Done in r145570.

On Nov 30, 2011, at 8:16 PM, Chandler Carruth wrote:

> 
> 
> On Wed, Nov 30, 2011 at 7:58 PM, Pete Cooper <peter_cooper at apple.com> wrote:
> Author: pete
> Date: Wed Nov 30 21:58:40 2011
> New Revision: 145563
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=145563&view=rev
> Log:
> Added instcombine pattern to spot comparing -val or val against 0.
> (val != 0) == (-val != 0) so "abs(val) != 0" becomes "val != 0"
> 
> Fixes <rdar://problem/10482509>
> 
> Added:
>    llvm/trunk/test/Transforms/InstCombine/compare-abs-nonzero.ll
> Modified:
>    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
> 
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=145563&r1=145562&r2=145563&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Wed Nov 30 21:58:40 2011
> @@ -1795,6 +1795,20 @@
>   if (Value *V = SimplifyICmpInst(I.getPredicate(), Op0, Op1, TD))
>     return ReplaceInstUsesWith(I, V);
> 
> +  // comparing -val or val with non-zero is the same as just comparing val
> +  // ie, (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)),
> +                            m_Value(SelectFalse)))) {
> +      if (SubSrc == SelectFalse) {
> +        return CmpInst::Create(Instruction::ICmp, I.getPredicate(),
> +                               SubSrc, Op1);
> +      }
> +    }
> +  }
> +
>   Type *Ty = Op0->getType();
> 
>   // icmp's with boolean values can always be turned into bitwise operations
> 
> Added: llvm/trunk/test/Transforms/InstCombine/compare-abs-nonzero.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/compare-abs-nonzero.ll?rev=145563&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/compare-abs-nonzero.ll (added)
> +++ llvm/trunk/test/Transforms/InstCombine/compare-abs-nonzero.ll Wed Nov 30 21:58:40 2011
> @@ -0,0 +1,10 @@
> +; RUN: opt < %s -instcombine -S | grep -v {select}
> 
> Please always use FileCheck on new tests...
> 
> That said, is there not an existing test this could be added to rather than creating a whole new test file which is very narrow?
> 
> +
> +define zeroext i1 @cmpabs(i64 %val) nounwind uwtable readnone ssp {
> +entry:
> +  %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
> +}
> 
> 
> _______________________________________________
> 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/20111130/97f0d2a0/attachment.html>


More information about the llvm-commits mailing list