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

Jakob Stoklund Olesen stoklund at 2pi.dk
Mon Jan 17 09:45:24 PST 2011


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.

/jakob





More information about the llvm-commits mailing list