[llvm] r193694 - make ConstantRange::signExtend() optimal

Nuno Lopes nunoplopes at sapo.pt
Thu Oct 31 12:59:11 PDT 2013


> Nuno Lopes wrote:
>> Author: nlopes
>> Date: Wed Oct 30 10:36:50 2013
>> New Revision: 193694
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=193694&view=rev
>> Log:
>> make ConstantRange::signExtend() optimal
>> the case [x, INT_MIN) was not handled optimally
>>
>> Modified:
>>      llvm/trunk/lib/Support/ConstantRange.cpp
>>      llvm/trunk/unittests/Support/ConstantRangeTest.cpp
>>
>> Modified: llvm/trunk/lib/Support/ConstantRange.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ConstantRange.cpp?rev=193694&r1=193693&r2=193694&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Support/ConstantRange.cpp (original)
>> +++ llvm/trunk/lib/Support/ConstantRange.cpp Wed Oct 30 10:36:50 2013
>> @@ -445,6 +445,11 @@ ConstantRange ConstantRange::signExtend(
>>
>>     unsigned SrcTySize = getBitWidth();
>>     assert(SrcTySize<  DstTySize&&  "Not a value extension");
>> +
>> +  // special case: [X, INT_MIN) -- not really wrapping around
>> +  if (Upper == APInt::getHighBitsSet(SrcTySize, 1))
>
> Use "Upper.isMinSignedValue()" (or "Upper.isSignBit()").
>
> Nick

Ah, thanks, that's exactly the function I was looking for, but failed to 
find for some reason.
Fixed in r193795.

Nuno


>> +    return ConstantRange(Lower.sext(DstTySize), Upper.zext(DstTySize));
>> +
>>     if (isFullSet() || isSignWrappedSet()) {
>>       return 
>> ConstantRange(APInt::getHighBitsSet(DstTySize,DstTySize-SrcTySize+1),
>>                            APInt::getLowBitsSet(DstTySize, SrcTySize-1) + 
>> 1);
>>
>> Modified: llvm/trunk/unittests/Support/ConstantRangeTest.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ConstantRangeTest.cpp?rev=193694&r1=193693&r2=193694&view=diff
>> ==============================================================================
>> --- llvm/trunk/unittests/Support/ConstantRangeTest.cpp (original)
>> +++ llvm/trunk/unittests/Support/ConstantRangeTest.cpp Wed Oct 30 
>> 10:36:50 2013
>> @@ -216,6 +216,9 @@ TEST_F(ConstantRangeTest, SExt) {
>>
>>     EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, 140)).signExtend(16),
>>               ConstantRange(APInt(16, -128), APInt(16, 128)));
>> +
>> +  EXPECT_EQ(ConstantRange(APInt(16, 0x0200), APInt(16, 
>> 0x8000)).signExtend(19),
>> +            ConstantRange(APInt(19, 0x0200), APInt(19, 0x8000)));
>>   }
>>
>>   TEST_F(ConstantRangeTest, IntersectWith) { 




More information about the llvm-commits mailing list