[llvm-commits] [llvm] r45384 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner clattner at apple.com
Fri Dec 28 11:10:51 PST 2007


On Dec 27, 2007, at 11:42 PM, Owen Anderson wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=45384&view=rev
> Log:
> Repair a transform that Chris noticed a bug in.  Thanks to Nicholas  
> for pointing out my stupid mistakes when writing this patch. :-)

Thanks Owen!  A minor tweak:

> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp  
> (original)
> +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Fri  
> Dec 28 01:42:12 2007
> @@ -4835,11 +4835,18 @@
>   if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
>       Value *A, *B;
>
> +    // (icmp cond (sub A B) 0) -> ...
> +    if (CI->isNullValue() && match(Op0, m_Sub(m_Value(A),  
> m_Value(B)))) {
> +      // (icmp cond A B) if cond is signed or equality
> +      if (CmpInst::isSigned(I.getPredicate()) || I.isEquality())
> +        return new ICmpInst(I.getPredicate(), A, B);
> +      // (icmp ne A B) if cond is ugt
> +      else if (I.getPredicate() == ICmpInst::ICMP_UGT)
> +        return new ICmpInst(ICmpInst::ICMP_NE, A, B);
> +      // (icmp eq A B) if cond is ule
> +      else if (I.getPredicate() == ICmpInst::ICMP_ULE)
> +        return new ICmpInst(ICmpInst::ICMP_EQ, A, B);
> +    }

Why not handle UGE and ULT?  If it is handled elsewhere, please add a  
comment to that effect, thanks!

-Chris



More information about the llvm-commits mailing list