[llvm-commits] [patch][pr12251] Use the range metadata in computeMaskedBits and add an optimization to InstructionSimplify.

Duncan Sands baldrick at free.fr
Sat Mar 24 22:10:13 PDT 2012


Hi Rafael,

> @@ -195,6 +197,26 @@ static void ComputeMaskedBitsMul(Value *Op0, Value *Op1, bool NSW,
>      KnownOne.setBit(BitWidth - 1);
>  }
>
> +static void computeMaskedBitsLoad(const MDNode &Ranges, const APInt &Mask,
> +                                  APInt &KnownZero) {
> +  unsigned BitWidth = Mask.getBitWidth();
> +  unsigned NumRanges = Ranges.getNumOperands() / 2;
> +  assert(NumRanges >= 1);
> +
> +  // Use the high end of the ranges to find leading zeros.
> +  unsigned MinLeadingZeros = BitWidth;
> +  for (unsigned i = 0; i < NumRanges; ++i) {
> +    ConstantInt *Lower = cast<ConstantInt>(Ranges.getOperand(2*i + 0));
> +    ConstantInt *Upper = cast<ConstantInt>(Ranges.getOperand(2*i + 1));
> +    ConstantRange Range(Lower->getValue(), Upper->getValue());
> +    if (Range.isWrappedSet())
> +      MinLeadingZeros = 0; // -1 has no zeros

here you could break out of the loop.

> +    unsigned LeadingZeros = (Upper->getValue() - 1).countLeadingZeros();
> +    MinLeadingZeros = std::min(LeadingZeros, MinLeadingZeros);
> +  }
> +
> +  KnownZero = Mask & APInt::getHighBitsSet(BitWidth, MinLeadingZeros);
> +}
>  /// ComputeMaskedBits - Determine which of the bits specified in Mask are
>  /// known to be either zero or one and return them in the KnownZero/KnownOne
>  /// bit sets.  This code only analyzes bits in Mask, in order to short-circuit

Ciao, Duncan.



More information about the llvm-commits mailing list