[llvm] [X86][GISEL] Lower Vector shuffle (PR #201055)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 2 01:23:54 PDT 2026
https://github.com/mahesh-attarde created https://github.com/llvm/llvm-project/pull/201055
Fixes https://github.com/llvm/llvm-project/issues/180713
This patch introduces vector shuffle lowering for X86 target, initial support includes zeroable shuffles and true floating point shuffle.
>From 953b088bbf79417ef9e83cec23e437a2760bfd95 Mon Sep 17 00:00:00 2001
From: "Attarde, Mahesh" <mahesh.attarde at intel.com>
Date: Tue, 2 Jun 2026 01:20:26 -0700
Subject: [PATCH] [X86][GISEL] Add Vector shuffle lowering
---
.../lib/Target/X86/GISel/X86LegalizerInfo.cpp | 226 ++++++++++++++++++
llvm/lib/Target/X86/GISel/X86LegalizerInfo.h | 3 +
llvm/lib/Target/X86/X86ISelLowering.cpp | 9 +-
llvm/lib/Target/X86/X86InstrGISel.td | 8 +
llvm/lib/Target/X86/X86ShuffleUtils.h | 56 +++++
llvm/test/CodeGen/X86/isel-vector_shuffle.ll | 43 ++++
llvm/test/CodeGen/X86/isel-zero_shuffle.ll | 168 +++++++++++++
7 files changed, 508 insertions(+), 5 deletions(-)
create mode 100644 llvm/lib/Target/X86/X86ShuffleUtils.h
create mode 100644 llvm/test/CodeGen/X86/isel-vector_shuffle.ll
create mode 100644 llvm/test/CodeGen/X86/isel-zero_shuffle.ll
diff --git a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
index d6df8cb97cfc8..4f0550e51baea 100644
--- a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
+++ b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "X86LegalizerInfo.h"
+#include "X86ShuffleUtils.h"
#include "X86Subtarget.h"
#include "X86TargetMachine.h"
#include "llvm/CodeGen/GlobalISel/GenericMachineInstrs.h"
@@ -24,6 +25,7 @@
#include "llvm/IR/IntrinsicsX86.h"
#include "llvm/IR/Type.h"
+#define DEBUG_TYPE "x86-legalizer-info"
using namespace llvm;
using namespace TargetOpcode;
using namespace LegalizeActions;
@@ -581,6 +583,26 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
{v8s64, v2s64},
{v8s64, v4s64}});
+ getActionDefinitionsBuilder(G_SHUFFLE_VECTOR)
+ .customFor(HasSSE2, {{v16s8, v16s8},
+ {v8s16, v8s16},
+ {v4s32, v4s32},
+ {v2s64, v2s64},
+ {v4s32, v4s32},
+ {v2s64, v2s64}})
+ .customFor(HasAVX, {{v32s8, v32s8},
+ {v16s16, v16s16},
+ {v8s32, v8s32},
+ {v4s64, v4s64},
+ {v8s32, v8s32},
+ {v4s64, v4s64}})
+ .customFor(HasAVX512, {{v64s8, v64s8},
+ {v32s16, v32s16},
+ {v16s32, v16s32},
+ {v8s64, v8s64},
+ {v16s32, v16s32},
+ {v8s64, v8s64}});
+
// todo: vectors and address spaces
getActionDefinitionsBuilder(G_SELECT)
.legalFor({{s16, s32}, {s32, s32}, {p0, s32}})
@@ -621,6 +643,8 @@ bool X86LegalizerInfo::legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI,
return false;
case TargetOpcode::G_BUILD_VECTOR:
return legalizeBuildVector(MI, MRI, Helper);
+ case TargetOpcode::G_SHUFFLE_VECTOR:
+ return legalizeShuffleVector(MI, MRI, Helper);
case TargetOpcode::G_FPTOUI:
return legalizeFPTOUI(MI, MRI, Helper);
case TargetOpcode::G_UITOFP:
@@ -1009,3 +1033,205 @@ bool X86LegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper,
MachineInstr &MI) const {
return true;
}
+
+/// Compute whether each element of a shuffle is zeroable.
+///
+/// A "zeroable" vector shuffle element is one which can be lowered to zero.
+/// Either it is an undef element in the shuffle mask, the element of the input
+/// referenced is undef, or the element of the input referenced is known to be
+/// zero. Many x86 shuffles can zero lanes cheaply and we often want to handle
+/// as many lanes with this technique as possible to simplify the remaining
+/// shuffle.
+static void computeZeroableShuffleElements(ArrayRef<int> Mask, Register V1,
+ Register V2,
+ MachineRegisterInfo &MRI,
+ APInt &KnownUndef,
+ APInt &KnownZero) {
+ int Size = Mask.size();
+ KnownUndef = KnownZero = APInt::getZero(Size);
+
+ // TODO: Add pick Throught bitcast
+
+ bool V1IsZero = false;
+ bool V2IsZero = false;
+
+ auto *V1Def = MRI.getVRegDef(V1);
+ auto *V2Def = MRI.getVRegDef(V2);
+
+ // Check if V1 is a build vector of all zeros
+ if (auto *BV1 = dyn_cast<GBuildVector>(V1Def)) {
+ V1IsZero = isBuildVectorAllOnes(*BV1, MRI);
+ }
+ // Check if V2 is a build vector of all zeros
+ if (auto *BV2 = dyn_cast<GBuildVector>(V2Def)) {
+ V2IsZero = isBuildVectorAllZeros(*BV2, MRI);
+ }
+
+ for (int i = 0; i < Size; ++i) {
+ int M = Mask[i];
+
+ // Handle the easy cases.
+ if (M < 0) {
+ KnownUndef.setBit(i);
+ continue;
+ }
+
+ // Check if element comes from an all-zero vector
+ if ((M >= 0 && M < Size && V1IsZero) || (M >= Size && V2IsZero)) {
+ KnownZero.setBit(i);
+ continue;
+ }
+
+ // Determine shuffle input and normalize the mask
+ Register V = M < Size ? V1 : V2;
+ M %= Size;
+
+ // Check if source is undef
+ MachineInstr *VDef = MRI.getVRegDef(V);
+ if (VDef->getOpcode() == TargetOpcode::G_IMPLICIT_DEF) {
+ KnownUndef.setBit(i);
+ continue;
+ }
+
+ // Check BUILD_VECTOR for individual UNDEF/ZERO elements
+ if (auto *BV = dyn_cast<GBuildVector>(VDef)) {
+ if (M < (int)BV->getNumSources()) {
+ Register SrcReg = BV->getSourceReg(M);
+ MachineInstr *SrcDef = MRI.getVRegDef(SrcReg);
+
+ // Check if this specific element is undef
+ if (SrcDef->getOpcode() == TargetOpcode::G_IMPLICIT_DEF) {
+ KnownUndef.setBit(i);
+ continue;
+ }
+
+ // Check if this specific element is zero
+ auto ValAndVReg = getIConstantVRegValWithLookThrough(SrcReg, MRI);
+ if (ValAndVReg && ValAndVReg->Value == 0) {
+ KnownZero.setBit(i);
+ continue;
+ }
+
+ // Check for floating point zero
+ auto FPValAndVReg = getFConstantVRegValWithLookThrough(SrcReg, MRI);
+ if (FPValAndVReg && FPValAndVReg->Value.isZero()) {
+ KnownZero.setBit(i);
+ continue;
+ }
+ }
+ }
+ }
+}
+
+/// Handle lowering of 2-lane 64-bit floating point shuffles.
+///
+/// This is the basis function for the 2-lane 64-bit shuffles as we have full
+/// support for floating point shuffles but not integer shuffles. These
+/// instructions will incur a domain crossing penalty on some chips though so
+/// it is better to avoid lowering through this for integer vectors where
+/// possible.
+static bool lowerV2F64Shuffle(const X86Subtarget &Subtarget, MachineInstr &MI,
+ MachineRegisterInfo &MRI, LegalizerHelper &Helper,
+ ArrayRef<int> Mask, Register Dst, Register Src1,
+ Register Src2) {
+ LLVM_DEBUG(dbgs() << "Lowering v2f64 shuffle: " << MI);
+ assert(Mask.size() == 2 && "Unexpected mask size for v2 shuffle!");
+ // TODO Src2 is Undef
+ assert(Mask[0] >= 0 && "No undef lanes in multi-input v2 shuffles!");
+ assert(Mask[1] >= 0 && "No undef lanes in multi-input v2 shuffles!");
+ assert(Mask[0] < 2 && "We sort V1 to be the first input.");
+ assert(Mask[1] >= 2 && "We sort V2 to be the second input.");
+
+ // Calculate SHUFPD immediate: bit 0 from Mask[0], bit 1 from (Mask[1] - 2)
+ unsigned SHUFPDMask = (Mask[0] == 1) | (((Mask[1] - 2) == 1) << 1);
+
+ auto SHUFPDInst = Helper.MIRBuilder.buildInstr(X86::G_X86_SHUFP)
+ .addDef(Dst)
+ .addUse(Src1)
+ .addUse(Src2)
+ .addImm(SHUFPDMask);
+
+ MI.eraseFromParent();
+ return true;
+}
+
+static bool lower128BitShuffle(MachineInstr &MI, MachineRegisterInfo &MRI,
+ LegalizerHelper &Helper, ArrayRef<int> Mask,
+ Register Dst, Register Src1, Register Src2) {
+ // TODO: we need Extended LLT for BF16 shuffle.
+ return lowerV2F64Shuffle(
+ Helper.MIRBuilder.getMF().getSubtarget<X86Subtarget>(), MI, MRI, Helper,
+ Mask, Dst, Src1, Src2);
+}
+
+bool X86LegalizerInfo::legalizeShuffleVector(MachineInstr &MI,
+ MachineRegisterInfo &MRI,
+ LegalizerHelper &Helper) const {
+ MachineIRBuilder &MIRBuilder = Helper.MIRBuilder;
+ MachineFunction &MF = MIRBuilder.getMF();
+ const auto &ShuffleVec = cast<GShuffleVector>(MI);
+
+ Register Dst = ShuffleVec.getReg(0);
+ Register Src1 = ShuffleVec.getSrc1Reg();
+ ArrayRef<int> Mask = ShuffleVec.getMask();
+
+ LLT DstTy = MRI.getType(Dst);
+ LLT SrcTy = MRI.getType(Src1);
+
+ unsigned NumElts = DstTy.getNumElements();
+ unsigned EltSize = DstTy.getScalarSizeInBits();
+ unsigned VecSize = DstTy.getSizeInBits();
+ unsigned NumSrcElts = SrcTy.getNumElements();
+
+ Register Src2 = ShuffleVec.getSrc2Reg();
+ bool Src2IsUndef = getOpcodeDef<GImplicitDef>(Src2, MRI) != nullptr;
+ bool Src1IsUndef = getOpcodeDef<GImplicitDef>(Src1, MRI) != nullptr;
+
+ if (Src2IsUndef && Src1IsUndef) {
+ // Both sources are undef, just return an undef vector.
+ auto UndefVec = MIRBuilder.buildUndef(DstTy);
+ MIRBuilder.buildCopy(Dst, UndefVec);
+ MI.eraseFromParent();
+ return true;
+ }
+
+ // Case 1: Check for non-undef masks pointing at an undef vector and make the
+ // masks undef as well. This makes it easier to match the shuffle based solely
+ // on the mask.
+ if (Src2IsUndef && x86shufutils::hasMaskIndexOutOfBounds(Mask, NumElts)) {
+ SmallVector<int, 8> NewMask;
+ x86shufutils::getCanonicalizeMask(Mask, NumElts, NewMask);
+ auto NewShuf = MIRBuilder.buildShuffleVector(DstTy, Src1, Src2, NewMask);
+ MRI.replaceRegWith(Dst, NewShuf.getReg(0));
+ MI.eraseFromParent();
+ return true;
+ }
+
+ // For Source2 != undef, make sure shuffle mask is legal.
+ int MaskUpperLimit = Mask.size() * (Src2IsUndef ? 1 : 2);
+ assert(x86shufutils::isLegalMask(Mask, NumElts, MaskUpperLimit) &&
+ "Out of bounds shuffle index");
+
+ // Case 2: We actually see shuffles that are entirely re-arrangements of a set
+ // of zero inputs. This mostly happens while decomposing complex shuffles into
+ // simple ones. Directly lower these as a buildvector of zeros.
+ APInt KnownUndef, KnownZero;
+ computeZeroableShuffleElements(Mask, Src1, Src2, MRI, KnownUndef, KnownZero);
+
+ APInt Zeroable = KnownUndef | KnownZero;
+ if (Zeroable.isAllOnes()) {
+ // All elements are zeroable - return zero vector
+ auto Zero = MIRBuilder.buildConstant(LLT::scalar(EltSize), 0);
+ SmallVector<Register, 16> Zeros(NumElts, Zero.getReg(0));
+ auto ZeroVec = MIRBuilder.buildBuildVector(DstTy, Zeros);
+ MRI.replaceRegWith(Dst, ZeroVec.getReg(0));
+ MI.eraseFromParent();
+ return true;
+ }
+ bool Src2IsZero =
+ !Src2IsUndef && isBuildVectorAllZeros(*MRI.getVRegDef(Src2), MRI);
+ // TODO:
+ if (DstTy.getSizeInBits() == 128)
+ return lower128BitShuffle(MI, MRI, Helper, Mask, Dst, Src1, Src2);
+ llvm_unreachable("Unexpected shuffle type");
+}
diff --git a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.h b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.h
index 09c727c8e8685..b422009c5a9b7 100644
--- a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.h
+++ b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.h
@@ -60,6 +60,9 @@ class X86LegalizerInfo : public LegalizerInfo {
bool legalizeSETROUNDING(MachineInstr &MI, MachineRegisterInfo &MRI,
LegalizerHelper &Helper) const;
+
+ bool legalizeShuffleVector(MachineInstr &MI, MachineRegisterInfo &MRI,
+ LegalizerHelper &Helper) const;
};
} // namespace llvm
#endif
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 5a1171b2b4ee6..2a2bfec1981bb 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -18,6 +18,7 @@
#include "X86InstrBuilder.h"
#include "X86IntrinsicsInfo.h"
#include "X86MachineFunctionInfo.h"
+#include "X86ShuffleUtils.h"
#include "X86TargetMachine.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallSet.h"
@@ -18895,11 +18896,9 @@ static SDValue lowerVECTOR_SHUFFLE(SDValue Op, const X86Subtarget &Subtarget,
// undef as well. This makes it easier to match the shuffle based solely on
// the mask.
if (V2IsUndef &&
- any_of(OrigMask, [NumElements](int M) { return M >= NumElements; })) {
- SmallVector<int, 8> NewMask(OrigMask);
- for (int &M : NewMask)
- if (M >= NumElements)
- M = -1;
+ x86shufutils::hasMaskIndexOutOfBounds(OrigMask, NumElements)) {
+ SmallVector<int, 8> NewMask;
+ x86shufutils::getCanonicalizeMask(OrigMask, NumElements, NewMask);
return DAG.getVectorShuffle(VT, DL, V1, V2, NewMask);
}
diff --git a/llvm/lib/Target/X86/X86InstrGISel.td b/llvm/lib/Target/X86/X86InstrGISel.td
index b0c6bb6f61ad8..1266c0577c078 100644
--- a/llvm/lib/Target/X86/X86InstrGISel.td
+++ b/llvm/lib/Target/X86/X86InstrGISel.td
@@ -41,7 +41,15 @@ def G_FLDCW16 : X86GenericInstruction {
let mayLoad = true;
}
+def G_X86_SHUFP : X86GenericInstruction {
+ let OutOperandList = (outs type0:$dst);
+ let InOperandList = (ins type0:$src1, type0:$src2, untyped_imm_0:$imm);
+ let hasSideEffects = false;
+}
+
def : GINodeEquiv<G_FILD, X86fild>;
def : GINodeEquiv<G_FIST, X86fp_to_mem>;
def : GINodeEquiv<G_FNSTCW16, X86fp_cwd_get16>;
def : GINodeEquiv<G_FLDCW16, X86fp_cwd_set16>;
+
+def : GINodeEquiv<G_X86_SHUFP, X86Shufp>;
\ No newline at end of file
diff --git a/llvm/lib/Target/X86/X86ShuffleUtils.h b/llvm/lib/Target/X86/X86ShuffleUtils.h
new file mode 100644
index 0000000000000..36cfdbc2b414c
--- /dev/null
+++ b/llvm/lib/Target/X86/X86ShuffleUtils.h
@@ -0,0 +1,56 @@
+//===-- X86ShuffleUtils.h -----------------------------------------*- C++-*-==//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+/// \file
+/// This file declares utility functions used in X86 shuffles
+/// It is designed for X86ISelowering and X86LegalizerInfo, intends to factor
+/// out common code without DAG and GIR dependencies.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_X86_X86SHUFFLEUTILS_H
+#define LLVM_LIB_TARGET_X86_X86SHUFFLEUTILS_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
+
+namespace x86shufutils {
+
+using namespace llvm;
+
+// This function checks if the shuffle mask has indices that are out of bounds
+// for the vector type.
+static inline bool hasMaskIndexOutOfBounds(const ArrayRef<int> Mask,
+ const unsigned NumElts) {
+ return llvm::any_of(Mask, [NumElts](int M) { return M >= (int)NumElts; });
+}
+
+// This function canonicalizes masks with out-of-bounds indices by setting
+// indices to -1 for all indices which are out of bounds in vector type.
+static inline void getCanonicalizeMask(const ArrayRef<int> Mask,
+ const unsigned NumElts,
+ SmallVectorImpl<int> &NewMask) {
+ for (int M : Mask) {
+ if (M >= (int)NumElts)
+ NewMask.push_back(-1);
+ else
+ NewMask.push_back(M);
+ }
+}
+
+// This function validates mask for legal values.
+// If source 2 is undef, max legal index is size of mask vector
+// else max legal index is size of mask vector * 2 since shuffle can select
+// from both source vectors
+static inline bool isLegalMask(const ArrayRef<int> Mask, const unsigned NumElts,
+ const unsigned MaskUpperLimit) {
+ return llvm::all_of(
+ Mask, [&](int M) { return -1 <= M && (unsigned)M < MaskUpperLimit; });
+}
+} // namespace x86shufutils
+
+#endif // LLVM_LIB_TARGET_X86_X86SHUFFLEUTILS_H
\ No newline at end of file
diff --git a/llvm/test/CodeGen/X86/isel-vector_shuffle.ll b/llvm/test/CodeGen/X86/isel-vector_shuffle.ll
new file mode 100644
index 0000000000000..eab7baaa6bd1d
--- /dev/null
+++ b/llvm/test/CodeGen/X86/isel-vector_shuffle.ll
@@ -0,0 +1,43 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+sse2 -verify-machineinstrs | FileCheck %s --check-prefixes=X64,SDAG-X64-SSE2
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+avx -verify-machineinstrs | FileCheck %s --check-prefixes=X64,SDAG-X64-AVX
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 -verify-machineinstrs | FileCheck %s --check-prefixes=X64,SDAG-X64-AVX2
+
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+sse2 -global-isel -verify-machineinstrs | FileCheck %s --check-prefixes=X64,GISEL-X64-SSE2
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+avx -global-isel -verify-machineinstrs | FileCheck %s --check-prefixes=X64,GISEL-X64-AVX
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 -global-isel -verify-machineinstrs | FileCheck %s --check-prefixes=X64,GISEL-X64-AVX2
+
+
+define <2 x double> @shuffle_op2_double(<2 x double> %a, <2 x double> %b) {
+; SDAG-X64-SSE2-LABEL: shuffle_op2_double:
+; SDAG-X64-SSE2: # %bb.0:
+; SDAG-X64-SSE2-NEXT: movlhps {{.*#+}} xmm0 = xmm0[0],xmm1[0]
+; SDAG-X64-SSE2-NEXT: retq
+;
+; SDAG-X64-AVX-LABEL: shuffle_op2_double:
+; SDAG-X64-AVX: # %bb.0:
+; SDAG-X64-AVX-NEXT: vmovlhps {{.*#+}} xmm0 = xmm0[0],xmm1[0]
+; SDAG-X64-AVX-NEXT: retq
+;
+; SDAG-X64-AVX2-LABEL: shuffle_op2_double:
+; SDAG-X64-AVX2: # %bb.0:
+; SDAG-X64-AVX2-NEXT: vmovlhps {{.*#+}} xmm0 = xmm0[0],xmm1[0]
+; SDAG-X64-AVX2-NEXT: retq
+;
+; GISEL-X64-SSE2-LABEL: shuffle_op2_double:
+; GISEL-X64-SSE2: # %bb.0:
+; GISEL-X64-SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[0,1]
+; GISEL-X64-SSE2-NEXT: retq
+;
+; GISEL-X64-AVX-LABEL: shuffle_op2_double:
+; GISEL-X64-AVX: # %bb.0:
+; GISEL-X64-AVX-NEXT: vshufpd {{.*#+}} xmm0 = xmm0[0],xmm1[0]
+; GISEL-X64-AVX-NEXT: retq
+;
+; GISEL-X64-AVX2-LABEL: shuffle_op2_double:
+; GISEL-X64-AVX2: # %bb.0:
+; GISEL-X64-AVX2-NEXT: vshufpd {{.*#+}} xmm0 = xmm0[0],xmm1[0]
+; GISEL-X64-AVX2-NEXT: retq
+ %result = shufflevector <2 x double> %a, <2 x double> %b, <2 x i32> <i32 0, i32 2>
+ ret <2 x double> %result
+}
diff --git a/llvm/test/CodeGen/X86/isel-zero_shuffle.ll b/llvm/test/CodeGen/X86/isel-zero_shuffle.ll
new file mode 100644
index 0000000000000..0e67899d708c5
--- /dev/null
+++ b/llvm/test/CodeGen/X86/isel-zero_shuffle.ll
@@ -0,0 +1,168 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+sse2 -verify-machineinstrs | FileCheck %s --check-prefixes=X64,SDAG-X64-SSE2
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+avx -verify-machineinstrs | FileCheck %s --check-prefixes=X64,SDAG-X64-AVX
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 -verify-machineinstrs | FileCheck %s --check-prefixes=X64,SDAG-X64-AVX2
+
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+sse2 -global-isel -verify-machineinstrs | FileCheck %s --check-prefixes=X64,GISEL-X64-SSE2
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+avx -global-isel -verify-machineinstrs | FileCheck %s --check-prefixes=X64,GISEL-X64-AVX
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 -global-isel -verify-machineinstrs | FileCheck %s --check-prefixes=X64,GISEL-X64-AVX2
+
+define <2 x double> @shuffle_all_poison_mask(<2 x double> %a, <2 x double> %b) {
+; X64-LABEL: shuffle_all_poison_mask:
+; X64: # %bb.0:
+; X64-NEXT: retq
+ %result = shufflevector <2 x double> %a, <2 x double> %b, <2 x i32> <i32 poison, i32 poison>
+ ret <2 x double> %result
+}
+
+define <2 x double> @shuffle_v2_zero(<2 x double> %a) {
+; SDAG-X64-SSE2-LABEL: shuffle_v2_zero:
+; SDAG-X64-SSE2: # %bb.0:
+; SDAG-X64-SSE2-NEXT: xorps %xmm0, %xmm0
+; SDAG-X64-SSE2-NEXT: retq
+;
+; SDAG-X64-AVX-LABEL: shuffle_v2_zero:
+; SDAG-X64-AVX: # %bb.0:
+; SDAG-X64-AVX-NEXT: vxorps %xmm0, %xmm0, %xmm0
+; SDAG-X64-AVX-NEXT: retq
+;
+; SDAG-X64-AVX2-LABEL: shuffle_v2_zero:
+; SDAG-X64-AVX2: # %bb.0:
+; SDAG-X64-AVX2-NEXT: vxorps %xmm0, %xmm0, %xmm0
+; SDAG-X64-AVX2-NEXT: retq
+;
+; GISEL-X64-SSE2-LABEL: shuffle_v2_zero:
+; GISEL-X64-SSE2: # %bb.0:
+; GISEL-X64-SSE2-NEXT: movaps {{.*#+}} xmm0 = [?]
+; GISEL-X64-SSE2-NEXT: retq
+;
+; GISEL-X64-AVX-LABEL: shuffle_v2_zero:
+; GISEL-X64-AVX: # %bb.0:
+; GISEL-X64-AVX-NEXT: vmovaps {{.*#+}} xmm0 = [?]
+; GISEL-X64-AVX-NEXT: retq
+;
+; GISEL-X64-AVX2-LABEL: shuffle_v2_zero:
+; GISEL-X64-AVX2: # %bb.0:
+; GISEL-X64-AVX2-NEXT: vmovaps {{.*#+}} xmm0 = [?]
+; GISEL-X64-AVX2-NEXT: retq
+ %result = shufflevector <2 x double> %a, <2 x double> zeroinitializer, <2 x i32> <i32 2, i32 3>
+ ret <2 x double> %result
+}
+
+define <2 x double> @shuffle_v1_undef(<2 x double> %b) {
+; SDAG-X64-SSE2-LABEL: shuffle_v1_undef:
+; SDAG-X64-SSE2: # %bb.0:
+; SDAG-X64-SSE2-NEXT: retq
+;
+; SDAG-X64-AVX-LABEL: shuffle_v1_undef:
+; SDAG-X64-AVX: # %bb.0:
+; SDAG-X64-AVX-NEXT: retq
+;
+; SDAG-X64-AVX2-LABEL: shuffle_v1_undef:
+; SDAG-X64-AVX2: # %bb.0:
+; SDAG-X64-AVX2-NEXT: retq
+;
+; GISEL-X64-SSE2-LABEL: shuffle_v1_undef:
+; GISEL-X64-SSE2: # %bb.0:
+; GISEL-X64-SSE2-NEXT: movaps {{.*#+}} xmm0 = [?]
+; GISEL-X64-SSE2-NEXT: retq
+;
+; GISEL-X64-AVX-LABEL: shuffle_v1_undef:
+; GISEL-X64-AVX: # %bb.0:
+; GISEL-X64-AVX-NEXT: vmovaps {{.*#+}} xmm0 = [?]
+; GISEL-X64-AVX-NEXT: retq
+;
+; GISEL-X64-AVX2-LABEL: shuffle_v1_undef:
+; GISEL-X64-AVX2: # %bb.0:
+; GISEL-X64-AVX2-NEXT: vmovaps {{.*#+}} xmm0 = [?]
+; GISEL-X64-AVX2-NEXT: retq
+ %result = shufflevector <2 x double> undef, <2 x double> %b, <2 x i32> <i32 0, i32 1>
+ ret <2 x double> %result
+}
+
+define <2 x double> @shuffle_undef_and_zero() {
+; SDAG-X64-SSE2-LABEL: shuffle_undef_and_zero:
+; SDAG-X64-SSE2: # %bb.0:
+; SDAG-X64-SSE2-NEXT: xorps %xmm0, %xmm0
+; SDAG-X64-SSE2-NEXT: retq
+;
+; SDAG-X64-AVX-LABEL: shuffle_undef_and_zero:
+; SDAG-X64-AVX: # %bb.0:
+; SDAG-X64-AVX-NEXT: vxorps %xmm0, %xmm0, %xmm0
+; SDAG-X64-AVX-NEXT: retq
+;
+; SDAG-X64-AVX2-LABEL: shuffle_undef_and_zero:
+; SDAG-X64-AVX2: # %bb.0:
+; SDAG-X64-AVX2-NEXT: vxorps %xmm0, %xmm0, %xmm0
+; SDAG-X64-AVX2-NEXT: retq
+;
+; GISEL-X64-SSE2-LABEL: shuffle_undef_and_zero:
+; GISEL-X64-SSE2: # %bb.0:
+; GISEL-X64-SSE2-NEXT: movaps {{.*#+}} xmm0 = [?]
+; GISEL-X64-SSE2-NEXT: retq
+;
+; GISEL-X64-AVX-LABEL: shuffle_undef_and_zero:
+; GISEL-X64-AVX: # %bb.0:
+; GISEL-X64-AVX-NEXT: vmovaps {{.*#+}} xmm0 = [?]
+; GISEL-X64-AVX-NEXT: retq
+;
+; GISEL-X64-AVX2-LABEL: shuffle_undef_and_zero:
+; GISEL-X64-AVX2: # %bb.0:
+; GISEL-X64-AVX2-NEXT: vmovaps {{.*#+}} xmm0 = [?]
+; GISEL-X64-AVX2-NEXT: retq
+ %result = shufflevector <2 x double> undef, <2 x double> zeroinitializer, <2 x i32> <i32 0, i32 2>
+ ret <2 x double> %result
+}
+
+; define <2 x double> @shuffle_poison_mask_and_zero(<2 x double> %a) {
+; %result = shufflevector <2 x double> %a, <2 x double> zeroinitializer, <2 x i32> <i32 poison, i32 3>
+; ret <2 x double> %result
+; }
+
+; define <2 x double> @shuffle_build_vector_fp_zeros(<2 x double> %a) {
+; %bv = insertelement <2 x double> poison, double 0.0, i32 0
+; %bv2 = insertelement <2 x double> %bv, double 0.0, i32 1
+; %result = shufflevector <2 x double> %a, <2 x double> %bv2, <2 x i32> <i32 2, i32 3>
+; ret <2 x double> %result
+; }
+
+; define <2 x double> @shuffle_build_vector_undef_elts(<2 x double> %a) {
+; %bv = insertelement <2 x double> poison, double undef, i32 0
+; %bv2 = insertelement <2 x double> %bv, double undef, i32 1
+; %result = shufflevector <2 x double> %a, <2 x double> %bv2, <2 x i32> <i32 2, i32 3>
+; ret <2 x double> %result
+; }
+
+define <2 x double> @shuffle_partial_zero(<2 x double> %a) {
+; SDAG-X64-SSE2-LABEL: shuffle_partial_zero:
+; SDAG-X64-SSE2: # %bb.0:
+; SDAG-X64-SSE2-NEXT: movq {{.*#+}} xmm0 = xmm0[0],zero
+; SDAG-X64-SSE2-NEXT: retq
+;
+; SDAG-X64-AVX-LABEL: shuffle_partial_zero:
+; SDAG-X64-AVX: # %bb.0:
+; SDAG-X64-AVX-NEXT: vmovq {{.*#+}} xmm0 = xmm0[0],zero
+; SDAG-X64-AVX-NEXT: retq
+;
+; SDAG-X64-AVX2-LABEL: shuffle_partial_zero:
+; SDAG-X64-AVX2: # %bb.0:
+; SDAG-X64-AVX2-NEXT: vmovq {{.*#+}} xmm0 = xmm0[0],zero
+; SDAG-X64-AVX2-NEXT: retq
+;
+; GISEL-X64-SSE2-LABEL: shuffle_partial_zero:
+; GISEL-X64-SSE2: # %bb.0:
+; GISEL-X64-SSE2-NEXT: shufpd {{.*#+}} xmm0 = xmm0[0],mem[0]
+; GISEL-X64-SSE2-NEXT: retq
+;
+; GISEL-X64-AVX-LABEL: shuffle_partial_zero:
+; GISEL-X64-AVX: # %bb.0:
+; GISEL-X64-AVX-NEXT: vshufpd {{.*#+}} xmm0 = xmm0[0],mem[0]
+; GISEL-X64-AVX-NEXT: retq
+;
+; GISEL-X64-AVX2-LABEL: shuffle_partial_zero:
+; GISEL-X64-AVX2: # %bb.0:
+; GISEL-X64-AVX2-NEXT: vshufpd {{.*#+}} xmm0 = xmm0[0],mem[0]
+; GISEL-X64-AVX2-NEXT: retq
+ %result = shufflevector <2 x double> %a, <2 x double> zeroinitializer, <2 x i32> <i32 0, i32 2>
+ ret <2 x double> %result
+}
More information about the llvm-commits
mailing list