[llvm] [X86][AVX] Match v4f64 blend from shuffle of scalar values. (PR #135753)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 26 03:54:03 PDT 2025


================
@@ -8743,6 +8745,43 @@ static SDValue lowerBuildVectorToBitOp(BuildVectorSDNode *Op, const SDLoc &DL,
   return LowerShift(Res, Subtarget, DAG);
 }
 
+/// Attempt to lower a BUILD_VECTOR of scalar values to a shuffle of splats
+/// representing a blend.
+static SDValue lowerBuildVectorAsBlend(BuildVectorSDNode *BVOp, SDLoc const &DL,
+                                       X86Subtarget const &Subtarget,
+                                       SelectionDAG &DAG) {
+  MVT VT = BVOp->getSimpleValueType(0u);
+  auto const NumElems = VT.getVectorNumElements();
+
+  if (Subtarget.hasAVX() && VT == MVT::v4f64) {
+    // Collect unique operands.
+    auto UniqueOps = SmallSet<SDValue, 16u>();
+    for (auto &Op : BVOp->ops()) {
+      if (isIntOrFPConstant(Op) || Op.get()->isUndef())
+        return {};
+      UniqueOps.insert(Op);
+    }
+    // Candidate BUILD_VECTOR must have 2 unique operands.
+    if (UniqueOps.size() != 2u)
+      return {};
+    // Create shuffle mask.
+    auto Op0 = BVOp->getOperand(0u);
+    auto Mask = std::vector<int>();
+    Mask.reserve(NumElems);
+    for (auto I = 0u; I < NumElems; ++I) {
+      auto &Op = BVOp->getOperand(I);
+      Mask.push_back(Op == Op0 ? I : I + NumElems);
+    }
+    // Create shuffle of splats.
+    UniqueOps.erase(Op0);
+    auto NewOp0 = DAG.getSplatBuildVector(VT, DL, Op0);
+    auto NewOp1 = DAG.getSplatBuildVector(VT, DL, *UniqueOps.begin());
----------------
RKSimon wrote:

auto -> SDValue

https://github.com/llvm/llvm-project/pull/135753


More information about the llvm-commits mailing list