[PATCH] D137688: [CodeGen] Refactor visitSCALAR_TO_VECTOR. NFC.

Han-Kuan Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 8 19:27:52 PST 2022


HanKuanChen created this revision.
HanKuanChen added a reviewer: spatel.
Herald added subscribers: ecnelises, hiraditya.
Herald added a project: All.
HanKuanChen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137688

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp


Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -23525,36 +23525,27 @@
       DAG.isSafeToSpeculativelyExecute(Opcode) && hasOperation(Opcode, VT)) {
     // Match an extract element and get a shuffle mask equivalent.
     SmallVector<int, 8> ShufMask(VT.getVectorNumElements(), -1);
-    auto getShuffleMaskForExtElt = [&](SDValue EE) {
-      if (EE.getOpcode() == ISD::EXTRACT_VECTOR_ELT &&
-          EE.getOperand(0).getValueType() == VT &&
-          isa<ConstantSDNode>(EE.getOperand(1))) {
-        // Mask = {ExtractIndex, undef, undef....}
-        ShufMask[0] = EE.getConstantOperandVal(1);
-        // Make sure the shuffle is legal if we are crossing lanes.
-        return TLI.isShuffleMaskLegal(ShufMask, VT);
-      }
-      return false;
-    };
 
-    // s2v (bo (extelt V, Idx), C) --> shuffle (bo V, C'), {Idx, -1, -1...}
-    if (auto *C = dyn_cast<ConstantSDNode>(Scalar.getOperand(1))) {
-      if (getShuffleMaskForExtElt(Scalar.getOperand(0))) {
-        SDLoc DL(N);
-        SDValue V = Scalar.getOperand(0).getOperand(0);
-        SDValue VecC = DAG.getConstant(C->getAPIntValue(), DL, VT);
-        SDValue VecBO = DAG.getNode(Opcode, DL, VT, V, VecC);
-        return DAG.getVectorShuffle(VT, DL, VecBO, DAG.getUNDEF(VT), ShufMask);
-      }
-    }
-    // s2v (bo C, (extelt V, Idx)) --> shuffle (bo C', V), {Idx, -1, -1...}
-    if (auto *C = dyn_cast<ConstantSDNode>(Scalar.getOperand(0))) {
-      if (getShuffleMaskForExtElt(Scalar.getOperand(1))) {
-        SDLoc DL(N);
-        SDValue V = Scalar.getOperand(1).getOperand(0);
-        SDValue VecC = DAG.getConstant(C->getAPIntValue(), DL, VT);
-        SDValue VecBO = DAG.getNode(Opcode, DL, VT, VecC, V);
-        return DAG.getVectorShuffle(VT, DL, VecBO, DAG.getUNDEF(VT), ShufMask);
+    for (int i = 0; i != 2; ++i) {
+      // s2v (bo (extelt V, Idx), C) --> shuffle (bo V, C'), {Idx, -1, -1...}
+      // s2v (bo C, (extelt V, Idx)) --> shuffle (bo C', V), {Idx, -1, -1...}
+      if (auto *C = dyn_cast<ConstantSDNode>(Scalar.getOperand(1 - i))) {
+        SDValue EE = Scalar.getOperand(i);
+        if (EE.getOpcode() == ISD::EXTRACT_VECTOR_ELT &&
+            EE.getOperand(0).getValueType() == VT &&
+            isa<ConstantSDNode>(EE.getOperand(1))) {
+          // Mask = {ExtractIndex, undef, undef....}
+          ShufMask[0] = EE.getConstantOperandVal(1);
+          // Make sure the shuffle is legal if we are crossing lanes.
+          if (TLI.isShuffleMaskLegal(ShufMask, VT)) {
+            SDLoc DL(N);
+            SDValue V[] = {EE.getOperand(0),
+                           DAG.getConstant(C->getAPIntValue(), DL, VT)};
+            SDValue VecBO = DAG.getNode(Opcode, DL, VT, V[i], V[1 - i]);
+            return DAG.getVectorShuffle(VT, DL, VecBO, DAG.getUNDEF(VT),
+                                        ShufMask);
+          }
+        }
       }
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137688.474145.patch
Type: text/x-patch
Size: 3057 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221109/070d95c1/attachment.bin>


More information about the llvm-commits mailing list