[llvm-commits] [llvm] r123621 - in /llvm/trunk: lib/CodeGen/SelectionDAG/TargetLowering.cpp test/CodeGen/X86/ctpop-combine.ll

Benjamin Kramer benny.kra at googlemail.com
Mon Jan 17 10:04:41 PST 2011


On 17.01.2011, at 18:45, Jakob Stoklund Olesen wrote:

> 
> On Jan 17, 2011, at 4:04 AM, Benjamin Kramer wrote:
> 
>> Author: d0k
>> Date: Mon Jan 17 06:04:57 2011
>> New Revision: 123621
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=123621&view=rev
>> Log:
>> Add a DAGCombine to turn (ctpop x) u< 2 into (x & x-1) == 0.
>> 
>> This shaves off 4 popcounts from the hacked 186.crafty source.
>> 
>> This is enabled even when a native popcount instruction is available. The
>> combined code is one operation longer but it should be faster nevertheless.
> 
> Nice!
> 
>> +    SDValue CTPOP = N0;
>> +    // Look through truncs that don't change the value of a ctpop.
>> +    if (N0.hasOneUse() && N0.getOpcode() == ISD::TRUNCATE)
>> +      CTPOP = N0.getOperand(0);
>> +
>> +    if (CTPOP.hasOneUse() && CTPOP.getOpcode() == ISD::CTPOP &&
>> +        (N0 == CTPOP || N0.getValueType().getSizeInBits() >=
>> +                        Log2_32_Ceil(CTPOP.getValueType().getSizeInBits()))) {
> 
> There is an off-by-one error here. An i5 can't hold the value of a ctpop(i32) whose range is 0-32.
> 
> More importantly, ctpop(i256) truncated to i8 is not a noop.

Oops! Thanks for the review, fixed in r123664.



More information about the llvm-commits mailing list