[llvm-commits] [llvm] r127598 - in /llvm/trunk: lib/CodeGen/SelectionDAG/SelectionDAG.cpp test/CodeGen/ARM/shifter_operand.ll test/CodeGen/ARM/undef-sext.ll

Evan Cheng evan.cheng at apple.com
Mon Mar 14 17:54:35 PDT 2011


On Mar 14, 2011, at 5:39 PM, Chris Lattner wrote:

> 
> On Mar 14, 2011, at 4:37 PM, Evan Cheng wrote:
> 
>> 
>> On Mar 14, 2011, at 11:25 AM, Frits van Bommel wrote:
>> 
>>> On Mon, Mar 14, 2011 at 7:15 PM, Evan Cheng <evan.cheng at apple.com> wrote:
>>>> Log:
>>>> Minor optimization. sign-ext/anyext of undef is still undef.
>>> 
>>> I can believe this for anyext, but a sext'ed undef should probably
>>> still have equal high bits, which is not a requirement for the bigger
>>> undef you're replacing it with.
>> 
>> I don't see the problem, the high-bit of an undef is an unknown value. zero-extend is definitely not safe, but sign-extend should be fine.
> 
> Sign extend doesn't specify what the top bit is, but it does guarantee that the top bits are all the same.  Instead of folding to undef, sext(undef) should fold to 0.  This is what happens at the IR level:

That makes sense. I'll fix.

Evan

> 
> Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
>                                            const Type *DestTy) {
>  if (isa<UndefValue>(V)) {
>    // zext(undef) = 0, because the top bits will be zero.
>    // sext(undef) = 0, because the top bits will all be the same.
>    // [us]itofp(undef) = 0, because the result value is bounded.
>    if (opc == Instruction::ZExt || opc == Instruction::SExt ||
>        opc == Instruction::UIToFP || opc == Instruction::SIToFP)
>      return Constant::getNullValue(DestTy);
>    return UndefValue::get(DestTy);
>  }
> 
> -Chris





More information about the llvm-commits mailing list