[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner clattner at apple.com
Sat Mar 24 22:22:47 PDT 2007


On Mar 24, 2007, at 9:55 PM, Nick Lewycky wrote:

> Chris Lattner wrote:
>> On Mar 23, 2007, at 11:46 AM, Reid Spencer wrote:
>>
>>>   // shl uint X, 32 = 0 and shr ubyte Y, 9 = 0, ... just don't
>>> eliminate shr
>>>   // of a signed value.
>>>   //
>>> -  unsigned TypeBits = Op0->getType()->getPrimitiveSizeInBits();
>>> -  if (Op1->getZExtValue() >= TypeBits) {
>>> +  if (Op1->getZExtValue() >= TypeBits) {  // shift amount always
>>> <= 32 bits
>>
>>
>> This isn't safe.  Code like:
>>
>> shl i1024 %A, 123456789123456789123456789123456789
>>
>> is undefined but legal.  The compiler should not crash on it.
>
> What exactly is undefined? Just the result of that single instruction,
> or the behaviour of any program that attempts to execute it?

The behavior of any program that attempts to execute it.

> Would it be
> acceptable to replace such an instruction with "unreachable"?

Yes, in theory, but I'm not sure that's a good idea.

> If so, then it gives me a new source of information for predsimplify.
> After the instruction executes, I can assume that the RHS of a  
> shift is
> within range.

I don't think this is appropriate.  The failure mode is just too  
great.  You can treat the shift as though it returns an undef though.

-Chris



More information about the llvm-commits mailing list