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

Chris Lattner clattner at apple.com
Wed Dec 19 17:10:51 PST 2007


On Dec 18, 2007, at 1:32 PM, Christopher Lamb wrote:
> Fold subtracts into integer compares vs. zero. This improves  
> generate code for this case on X86
> from

Very nice xform!  Please add a testcase to Transforms/Instcombine

Also:
>    if (isa<UndefValue>(Op1))                  // X icmp undef -> undef
>      return ReplaceInstUsesWith(I, UndefValue::get(Type::Int1Ty));
> -
> +
> +  // (icmp cond (sub m A) 0) ->
> +  //   (icmp cond m A)
> +  {
> +    ConstantInt *C1, *C2;
> +    Value *A;

This code can be simplified in two ways: first, you can drop the  
first version of the pattern: compares (and other binops, where  
possible) are canonicalized so that any constant will be on the RHS.   
This means you don't have to test to see if the LHS is a constant.

Second, if you sink this down into this "if" block:

   // See if we are doing a comparison between a constant and an  
instruction that
   // can be folded into the comparison.
   if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {

then you can turn the first match into just: if (CI->isNullValue() &&  
match(Op0, ...)

Finally, is "m" really required to be a constant?  This xform seems  
valid for any "m" and "A", and more general is good.

Thanks Christopher!

-Chris


> +    // Check both arguments of the compare for a matching subtract.
> +    if (match(Op0, m_ConstantInt(C1)) && C1->getValue() == 0 &&
> +        match(Op1, m_Sub(m_ConstantInt(C2), m_Value(A)))) {
> +      // We managed to fold the add into the RHS of the select  
> condition.
> +      return new ICmpInst(I.getPredicate(), A, C2);
> +    } else if (match(Op1, m_ConstantInt(C1)) && C1->getValue() ==  
> 0 &&
> +               match(Op0, m_Sub(m_ConstantInt(C2), m_Value(A)))) {
> +      // We managed to fold the add into the LHS of the select  
> condition.
> +      return new ICmpInst(I.getPredicate(), C2, A);
> +    }
> +  }
> +
>    // icmp <global/alloca*/null>, <global/alloca*/null> - Global/ 
> Stack value
>    // addresses never equal each other!  We already know that Op0 ! 
> = Op1.
>    if ((isa<GlobalValue>(Op0) || isa<AllocaInst>(Op0) ||
>
>
> _______________________________________________
> 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