[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 15:42:22 PST 2012
On Mon, Dec 10, 2012 at 3:39 PM, Shuxin Yang <shuxin.llvm at gmail.com> wrote:
> Hi, Eli:
>
> Thank you for the feedback. See the interleaving text.
>
>
> On 12/10/12 2:38 PM, Eli Friedman wrote:
>>
>> 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.)
>
> You aright. APInt::getAllOnesValue() was the function I were looking for.
> I didn't find one. So, I try to use following function as alternative. But
> somehow
> I misread the default value of 3rd parameter. I will fix the problem and
> test it
> tomorrow.
>
> APInt BitMask1(Ty->getIntegerBitWidth(), (uint64_t)-1, *TRUE*);
OK.
>>
>>> + 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?
>
> I'm not sure this question. Could you please elaborate?
If the shift is e.g. "lshr exact i32 %x, 3", can we make the new shift
"exact" as well? (See
http://llvm.org/docs/LangRef.html#lshr-instruction .)
-Eli
More information about the llvm-commits
mailing list