[llvm-commits] [llvm] r166125 - in /llvm/trunk: lib/CodeGen/SelectionDAG/DAGCombiner.cpp test/CodeGen/X86/extract-concat.ll

David Blaikie dblaikie at gmail.com
Wed Oct 17 15:57:47 PDT 2012


On Wed, Oct 17, 2012 at 1:48 PM, Michael Liao <michael.liao at intel.com> wrote:
> Author: hliao
> Date: Wed Oct 17 15:48:33 2012
> New Revision: 166125
>
> URL: http://llvm.org/viewvc/llvm-project?rev=166125&view=rev
> Log:
> Teach DAG combine to fold (extract_subvec (concat v1, ..) i) to v_i
>
> - If the extracted vector has the same type of all vectored being concatenated
>   together, it should be simplified directly into v_i, where i is the index of
>   the element being extracted.
>
>
> Added:
>     llvm/trunk/test/CodeGen/X86/extract-concat.ll
> Modified:
>     llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=166125&r1=166124&r2=166125&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Wed Oct 17 15:48:33 2012
> @@ -8610,8 +8610,8 @@
>        return SDValue();
>
>      // Only handle cases where both indexes are constants with the same type.
> -    ConstantSDNode *InsIdx = dyn_cast<ConstantSDNode>(N->getOperand(1));
> -    ConstantSDNode *ExtIdx = dyn_cast<ConstantSDNode>(V->getOperand(2));
> +    ConstantSDNode *ExtIdx = dyn_cast<ConstantSDNode>(N->getOperand(1));
> +    ConstantSDNode *InsIdx = dyn_cast<ConstantSDNode>(V->getOperand(2));
>
>      if (InsIdx && ExtIdx &&
>          InsIdx->getValueType(0).getSizeInBits() <= 64 &&
> @@ -8628,6 +8628,21 @@
>      }
>    }
>
> +  if (V->getOpcode() == ISD::CONCAT_VECTORS) {
> +    // Combine:
> +    //    (extract_subvec (concat V1, V2, ...), i)
> +    // Into:
> +    //    Vi if possible
> +    for (unsigned i = 0, e = V->getNumOperands(); i != e; ++i)
> +      if (V->getOperand(i).getValueType() != NVT)
> +        return SDValue();
> +    unsigned Idx = dyn_cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
> +    unsigned NumElems = NVT.getVectorNumElements();
> +    assert((Idx % NumElems) == 0 &&
> +           "IDX in concat is not a multiple of the result vector length.");
> +    return V->getOperand(Idx / NumElems);
> +  }
> +
>    return SDValue();
>  }
>
>
> Added: llvm/trunk/test/CodeGen/X86/extract-concat.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/extract-concat.ll?rev=166125&view=auto
> ==============================================================================
> --- llvm/trunk/test/CodeGen/X86/extract-concat.ll (added)
> +++ llvm/trunk/test/CodeGen/X86/extract-concat.ll Wed Oct 17 15:48:33 2012
> @@ -0,0 +1,17 @@
> +; RUN: llc < %s -mcpu=corei7 -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
> +
> +define void @foo(<4 x float> %in, <4 x i8>* %out) {
> +  %t0 = fptoui <4 x float> %in to <4 x i32>
> +  %t1 = trunc <4 x i32> %t0 to <4 x i16>
> +  %t2 = shufflevector <4 x i16> %t1, <4 x i16> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
> +  %t3 = trunc <8 x i16> %t2 to <8 x i8>
> +  %t4 = shufflevector <8 x i8> %t3, <8 x i8> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
> +  %t5 = insertelement <4 x i8> %t4, i8 -1, i32 3
> +  store <4 x i8> %t5, <4 x i8>* %out
> +  ret void
> +; CHECK: foo
> +; CHECK: cvttps2dq
> +; CHECK-NOT: pextrd
> +; CHECK: pshufb
> +; CHECK: ret
> +}

Seems to be failing for me:

/usr/local/google/home/blaikie/Development/llvm/src/test/CodeGen/X86/extract-concat.ll:13:10:
error: expected string not found in input
; CHECK: cvttps2dq
         ^
<stdin>:23:2: note: scanning from here
 .align 16, 0x90
 ^
<stdin>:29:2: note: possible intended match here
 cvttss2siq %xmm1, %rax
 ^

Please fix or revert at your earliest convenience.

For reference, the total output of the llc command is:

        .file   "<stdin>"
        .section        .rodata.cst16,"aM", at progbits,16
        .align  16
.LCPI0_0:
        .byte   0                       # 0x0
        .byte   4                       # 0x4
        .byte   8                       # 0x8
        .byte   12                      # 0xc
        .byte   128                     # 0x80
        .byte   128                     # 0x80
        .byte   128                     # 0x80
        .byte   128                     # 0x80
        .byte   128                     # 0x80
        .byte   128                     # 0x80
        .byte   128                     # 0x80
        .byte   128                     # 0x80
        .byte   128                     # 0x80
        .byte   128                     # 0x80
        .byte   128                     # 0x80
        .byte   128                     # 0x80
        .text
        .globl  foo
        .align  16, 0x90
        .type   foo, at function
foo:                                    # @foo
        .cfi_startproc
# BB#0:
        pshufd  $1, %xmm0, %xmm1        # xmm1 = xmm0[1,0,0,0]
        cvttss2siq      %xmm1, %rax
        cvttss2siq      %xmm0, %rcx
        movd    %ecx, %xmm1
        pinsrd  $1, %eax, %xmm1
        pshufd  $3, %xmm0, %xmm2        # xmm2 = xmm0[3,0,0,0]
        movhlps %xmm0, %xmm0            # xmm0 = xmm0[1,1]
        cvttss2siq      %xmm0, %rax
        pinsrd  $2, %eax, %xmm1
        cvttss2siq      %xmm2, %rcx
        movl    $255, %eax
        pinsrd  $3, %ecx, %xmm1
        pextrd  $1, %xmm1, %edx
        pextrd  $2, %xmm1, %ecx
        pinsrd  $1, %edx, %xmm1
        pinsrd  $2, %ecx, %xmm1
        pinsrd  $3, %eax, %xmm1
        pshufb  .LCPI0_0(%rip), %xmm1
        movd    %xmm1, (%rdi)
        ret
.Ltmp0:
        .size   foo, .Ltmp0-foo
        .cfi_endproc


        .section        ".note.GNU-stack","", at progbits



More information about the llvm-commits mailing list