[llvm] r324841 - [X86][SSE] Moved SplitBinaryOpsAndApply earlier so more methods can use it. NFCI.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 11 09:01:43 PST 2018
Author: rksimon
Date: Sun Feb 11 09:01:43 2018
New Revision: 324841
URL: http://llvm.org/viewvc/llvm-project?rev=324841&view=rev
Log:
[X86][SSE] Moved SplitBinaryOpsAndApply earlier so more methods can use it. NFCI.
Modified:
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=324841&r1=324840&r2=324841&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Sun Feb 11 09:01:43 2018
@@ -5048,6 +5048,53 @@ static SDValue insert256BitVector(SDValu
return insertSubVector(Result, Vec, IdxVal, DAG, dl, 256);
}
+// Helper for splitting operands of a binary operation to legal target size and
+// apply a function on each part.
+// Useful for operations that are available on SSE2 in 128-bit, on AVX2 in
+// 256-bit and on AVX512BW in 512-bit.
+// The argument VT is the type used for deciding if/how to split the operands
+// Op0 and Op1. Op0 and Op1 do *not* have to be of type VT.
+// The argument Builder is a function that will be applied on each split psrt:
+// SDValue Builder(SelectionDAG&G, SDLoc, SDValue, SDValue)
+template <typename F>
+SDValue SplitBinaryOpsAndApply(SelectionDAG &DAG, const X86Subtarget &Subtarget,
+ const SDLoc &DL, EVT VT, SDValue Op0,
+ SDValue Op1, F Builder) {
+ assert(Subtarget.hasSSE2() && "Target assumed to support at least SSE2");
+ unsigned NumSubs = 1;
+ if (Subtarget.useBWIRegs()) {
+ if (VT.getSizeInBits() > 512) {
+ NumSubs = VT.getSizeInBits() / 512;
+ assert((VT.getSizeInBits() % 512) == 0 && "Illegal vector size");
+ }
+ } else if (Subtarget.hasAVX2()) {
+ if (VT.getSizeInBits() > 256) {
+ NumSubs = VT.getSizeInBits() / 256;
+ assert((VT.getSizeInBits() % 256) == 0 && "Illegal vector size");
+ }
+ } else {
+ if (VT.getSizeInBits() > 128) {
+ NumSubs = VT.getSizeInBits() / 128;
+ assert((VT.getSizeInBits() % 128) == 0 && "Illegal vector size");
+ }
+ }
+
+ if (NumSubs == 1)
+ return Builder(DAG, DL, Op0, Op1);
+
+ SmallVector<SDValue, 4> Subs;
+ EVT InVT = Op0.getValueType();
+ EVT SubVT = EVT::getVectorVT(*DAG.getContext(), InVT.getScalarType(),
+ InVT.getVectorNumElements() / NumSubs);
+ for (unsigned i = 0; i != NumSubs; ++i) {
+ unsigned Idx = i * SubVT.getVectorNumElements();
+ SDValue LHS = extractSubVector(Op0, Idx, DAG, DL, SubVT.getSizeInBits());
+ SDValue RHS = extractSubVector(Op1, Idx, DAG, DL, SubVT.getSizeInBits());
+ Subs.push_back(Builder(DAG, DL, LHS, RHS));
+ }
+ return DAG.getNode(ISD::CONCAT_VECTORS, DL, VT, Subs);
+}
+
// Return true if the instruction zeroes the unused upper part of the
// destination and accepts mask.
static bool isMaskedZeroUpperBitsvXi1(unsigned int Opcode) {
@@ -34235,53 +34282,6 @@ static SDValue combineTruncateWithSat(SD
return SDValue();
}
-// Helper for splitting operands of a binary operation to legal target size and
-// apply a function on each part.
-// Useful for operations that are available on SSE2 in 128-bit, on AVX2 in
-// 256-bit and on AVX512BW in 512-bit.
-// The argument VT is the type used for deciding if/how to split the operands
-// Op0 and Op1. Op0 and Op1 do *not* have to be of type VT.
-// The argument Builder is a function that will be applied on each split psrt:
-// SDValue Builder(SelectionDAG&G, SDLoc, SDValue, SDValue)
-template <typename F>
-SDValue SplitBinaryOpsAndApply(SelectionDAG &DAG, const X86Subtarget &Subtarget,
- const SDLoc &DL, EVT VT, SDValue Op0,
- SDValue Op1, F Builder) {
- assert(Subtarget.hasSSE2() && "Target assumed to support at least SSE2");
- unsigned NumSubs = 1;
- if (Subtarget.useBWIRegs()) {
- if (VT.getSizeInBits() > 512) {
- NumSubs = VT.getSizeInBits() / 512;
- assert((VT.getSizeInBits() % 512) == 0 && "Illegal vector size");
- }
- } else if (Subtarget.hasAVX2()) {
- if (VT.getSizeInBits() > 256) {
- NumSubs = VT.getSizeInBits() / 256;
- assert((VT.getSizeInBits() % 256) == 0 && "Illegal vector size");
- }
- } else {
- if (VT.getSizeInBits() > 128) {
- NumSubs = VT.getSizeInBits() / 128;
- assert((VT.getSizeInBits() % 128) == 0 && "Illegal vector size");
- }
- }
-
- if (NumSubs == 1)
- return Builder(DAG, DL, Op0, Op1);
-
- SmallVector<SDValue, 4> Subs;
- EVT InVT = Op0.getValueType();
- EVT SubVT = EVT::getVectorVT(*DAG.getContext(), InVT.getScalarType(),
- InVT.getVectorNumElements() / NumSubs);
- for (unsigned i = 0; i != NumSubs; ++i) {
- unsigned Idx = i * SubVT.getVectorNumElements();
- SDValue LHS = extractSubVector(Op0, Idx, DAG, DL, SubVT.getSizeInBits());
- SDValue RHS = extractSubVector(Op1, Idx, DAG, DL, SubVT.getSizeInBits());
- Subs.push_back(Builder(DAG, DL, LHS, RHS));
- }
- return DAG.getNode(ISD::CONCAT_VECTORS, DL, VT, Subs);
-}
-
/// This function detects the AVG pattern between vectors of unsigned i8/i16,
/// which is c = (a + b + 1) / 2, and replace this operation with the efficient
/// X86ISD::AVG instruction.
More information about the llvm-commits
mailing list