Skip to content

Commit

Permalink
[X86][AVX] createVariablePermute - fix v2i64/v2f64 VPERMILPD index cr…
Browse files Browse the repository at this point in the history
…eation.

The input indices vector will put the index in bit0, but VPERMILPD actually selects off bit1 - so we need to scale accordingly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327159 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
RKSimon committed Mar 9, 2018
1 parent 9ae21b3 commit c805ab0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7963,6 +7963,8 @@ SDValue createVariablePermute(MVT VT, SDValue SrcVec, SDValue IndicesVec,
case MVT::v2f64:
case MVT::v2i64:
if (Subtarget.hasAVX()) {
// VPERMILPD selects using bit#1 of the index vector, so scale IndicesVec.
IndicesVec = DAG.getNode(ISD::ADD, DL, IndicesVT, IndicesVec, IndicesVec);
Opcode = X86ISD::VPERMILPV;
ShuffleVT = MVT::v2f64;
}
Expand Down
2 changes: 2 additions & 0 deletions test/CodeGen/X86/var-permute-128.ll
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ define <2 x i64> @var_shuffle_v2i64(<2 x i64> %v, <2 x i64> %indices) nounwind {
;
; AVX-LABEL: var_shuffle_v2i64:
; AVX: # %bb.0:
; AVX-NEXT: vpaddq %xmm1, %xmm1, %xmm1
; AVX-NEXT: vpermilpd %xmm1, %xmm0, %xmm0
; AVX-NEXT: retq
%index0 = extractelement <2 x i64> %indices, i32 0
Expand Down Expand Up @@ -221,6 +222,7 @@ define <2 x double> @var_shuffle_v2f64(<2 x double> %v, <2 x i64> %indices) noun
;
; AVX-LABEL: var_shuffle_v2f64:
; AVX: # %bb.0:
; AVX-NEXT: vpaddq %xmm1, %xmm1, %xmm1
; AVX-NEXT: vpermilpd %xmm1, %xmm0, %xmm0
; AVX-NEXT: retq
%index0 = extractelement <2 x i64> %indices, i32 0
Expand Down

0 comments on commit c805ab0

Please sign in to comment.