[llvm-commits] [PATCH] [llvm] Transform (x&C)>V into (x&C)!=0 wherepossible.

Duncan Sands baldrick at free.fr
Sun Dec 16 08:41:59 PST 2012


Hi Kevin,

On 14/12/12 17:24, Schoedel, Kevin P wrote:
> Nuno Lopes [mailto:nunoplopes at sapo.pt] wrote:
>> Ok, so please add a CHECK to your test to ensure that the 'and' is changed
>> correctly.
>
> Thanks for catching that. Revised patch attached.

> @@ -1226,6 +1226,15 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
>          ICI.setOperand(0, NewAnd);
>          return &ICI;
>        }
> +
> +      // If any bit set in (X & AndCST) will produce a result greater than RHSV,
> +      // replace ((X & AndCST) > RHSV) with ((X & AndCST) != 0).
> +      unsigned NTZ = AndCST->getValue().countTrailingZeros();

any chance of having the countTrailingZeros computation only be done for UGT
comparisons, and not when the result isn't going to be used?  (If the optimizers
sink the computation down to the use then there's no need to bother).

> +      if ((ICI.getPredicate() == ICmpInst::ICMP_UGT) &&
> +          (NTZ < AndCST->getBitWidth()) &&
> +          APInt::getOneBitSet(AndCST->getBitWidth(), NTZ).ugt(RHSV))
> +        return new ICmpInst(ICmpInst::ICMP_NE, LHSI,
> +                            Constant::getNullValue(RHS->getType()));
>      }
>
>      // Try to optimize things like "A[i]&42 == 0" to index computations.

Ciao, Duncan.



More information about the llvm-commits mailing list