[llvm-commits] [llvm] r169182 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombine.h lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp test/Transforms/InstCombine/2010-11-01-lshr-mask.ll test/Transforms/InstCombine/shift.ll test/Transforms/InstCombine/signext.ll

Eli Friedman eli.friedman at gmail.com
Mon Dec 10 14:38:28 PST 2012


On Mon, Dec 3, 2012 at 4:04 PM, Shuxin Yang <shuxin.llvm at gmail.com> wrote:
> +  Value *VarX = Shr->getOperand(0);
> +  Type *Ty = VarX->getType();
> +
> +  APInt BitMask1(Ty->getIntegerBitWidth(), (uint64_t)-1);
> +  APInt BitMask2(Ty->getIntegerBitWidth(), (uint64_t)-1);

APInt::getAllOnesValue().  (As-is, this isn't right for bit-widths >= 64.)

> +    BinaryOperator *New;
> +    if (ShrAmt < ShlAmt) {
> +      Constant *Amt = ConstantInt::get(VarX->getType(), ShlAmt - ShrAmt);
> +      New = BinaryOperator::CreateShl(VarX, Amt);
> +      BinaryOperator *Orig = cast<BinaryOperator>(Shl);
> +      New->setHasNoSignedWrap(Orig->hasNoSignedWrap());
> +      New->setHasNoUnsignedWrap(Orig->hasNoUnsignedWrap());
> +    } else {
> +      Constant *Amt = ConstantInt::get(VarX->getType(), ShrAmt - ShlAmt);
> +      New = BinaryOperator::CreateLShr(VarX, Amt);
> +    }

Can we propagate the "exact" bit from the original shr?

-Eli



More information about the llvm-commits mailing list