[llvm] r258690 - [DemandedBits] Fix computation of demanded bits for ICmps

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 25 11:45:28 PST 2016


Go ahead and merge with utils/release/merge.sh.

On Mon, Jan 25, 2016 at 6:56 AM, James Molloy <james at jamesmolloy.co.uk> wrote:
> Hi Hans,
>
> This fixes a latent bug which will be present in 3.8, and potentially
> affects a case in Spec CPU 2006. It is low risk and an obvious bugfix.
>
> Could I please nominate this for inclusion in 3.8?
>
> James
>
>
> On Mon, 25 Jan 2016 at 14:53 James Molloy via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>>
>> Author: jamesm
>> Date: Mon Jan 25 08:49:36 2016
>> New Revision: 258690
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=258690&view=rev
>> Log:
>> [DemandedBits] Fix computation of demanded bits for ICmps
>>
>> The computation of ICmp demanded bits is independent of the individual
>> operand being evaluated. We simply return a mask consisting of the minimum
>> leading zeroes of both operands.
>>
>> We were incorrectly passing "I" to ComputeKnownBits - this should be
>> "UserI->getOperand(0)". In cases where we were evaluating the 1th operand,
>> we were taking the minimum leading zeroes of it and itself.
>>
>> This should fix PR26266.
>>
>> Modified:
>>     llvm/trunk/lib/Analysis/DemandedBits.cpp
>>     llvm/trunk/test/Analysis/DemandedBits/basic.ll
>>
>> Modified: llvm/trunk/lib/Analysis/DemandedBits.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DemandedBits.cpp?rev=258690&r1=258689&r2=258690&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Analysis/DemandedBits.cpp (original)
>> +++ llvm/trunk/lib/Analysis/DemandedBits.cpp Mon Jan 25 08:49:36 2016
>> @@ -244,7 +244,7 @@ void DemandedBits::determineLiveOperandB
>>      break;
>>    case Instruction::ICmp:
>>      // Count the number of leading zeroes in each operand.
>> -    ComputeKnownBits(BitWidth, I, UserI->getOperand(1));
>> +    ComputeKnownBits(BitWidth, UserI->getOperand(0),
>> UserI->getOperand(1));
>>      auto NumLeadingZeroes = std::min(KnownZero.countLeadingOnes(),
>>                                       KnownZero2.countLeadingOnes());
>>      AB = ~APInt::getHighBitsSet(BitWidth, NumLeadingZeroes);
>>
>> Modified: llvm/trunk/test/Analysis/DemandedBits/basic.ll
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/DemandedBits/basic.ll?rev=258690&r1=258689&r2=258690&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/test/Analysis/DemandedBits/basic.ll (original)
>> +++ llvm/trunk/test/Analysis/DemandedBits/basic.ll Mon Jan 25 08:49:36
>> 2016
>> @@ -24,11 +24,20 @@ define i1 @test_icmp1(i32 %a, i32 %b) {
>>
>>  ; CHECK-LABEL: 'test_icmp2'
>>  ; CHECK-DAG: DemandedBits: 0x1 for   %3 = icmp eq i32 %1, %2
>> -; CHECK-DAG: DemandedBits: 0xFF for   %1 = and i32 %a, 255
>> -; CHECK-DAG: DemandedBits: 0xF for   %2 = ashr i32 %1, 4
>> +; CHECK-DAG: DemandedBits: 0xFFF for   %1 = and i32 %a, 255
>> +; CHECK-DAG: DemandedBits: 0xFF for   %2 = ashr i32 %1, 4
>>  define i1 @test_icmp2(i32 %a, i32 %b) {
>>    %1 = and i32 %a, 255
>>    %2 = ashr i32 %1, 4
>>    %3 = icmp eq i32 %1, %2
>>    ret i1 %3
>>  }
>> +
>> +; CHECK-LABEL: 'test_icmp3'
>> +; CHECK-DAG: DemandedBits: 0xFFFFFFFF for   %1 = and i32 %a, 255
>> +; CHECK-DAG: DemandedBits: 0x1 for   %2 = icmp eq i32 -1, %1
>> +define i1 @test_icmp3(i32 %a) {
>> +  %1 = and i32 %a, 255
>> +  %2 = icmp eq i32 -1, %1
>> +  ret i1 %2
>> +}
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list