[llvm-commits] SETCC InstructionCombining.cpp [3/3]

Reid Spencer rspencer at reidspencer.com
Fri Dec 22 19:54:25 PST 2006


On Fri, 2006-12-22 at 13:31 -0800, Chris Lattner wrote:

> 
> +  if (Res2 == CI) {
> +    // Make sure that sign of the Cmp and the sign of the Cast are
> the same.
> +    // For example, we might have:
> +    //    %A = sext short %X to uint
> +    //    %B = icmp ugt uint %A, 1330
> +    // It is incorrect to transform this into 
> +    //    %B = icmp ugt short %X, 1330 
> +    // because %A may have negative value. 
> +    //
> +    // However, it is OK if SrcTy is bool (See cast-set.ll testcase)
> +    // OR operation is EQ/NE.
> +    if (isSignedExt == isSignedCmp || SrcTy == Type::BoolTy ||
> ICI.isEquality())
> +      return new ICmpInst(ICI.getPredicate(), LHSCIOp, Res1);
> +    else
> +      return 0;
> +  }
> 
> 
> Can you explain why srcty == bool is a special case?

1. test/Regression/Transforms/InstCombine/JavaCompare.ll fails without
it.
2. Since Res1 is truncated to SrcTy, if the source of the LHS cast is
also bool,
   the compare is fine, type wise.
3. Since Res2 is Res1 casted back to the Cast's destination type and
Res2
   is equal to the RHS constant.

Without this we miss optimization opportunities.

Reid.





More information about the llvm-commits mailing list