[llvm] [NVPTX] Make i16x2 a native type and add supported vec instructions (PR #65432)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 6 15:45:14 PDT 2023


================
@@ -2347,7 +2413,26 @@ SDValue NVPTXTargetLowering::LowerFROUND64(SDValue Op,
   return DAG.getNode(ISD::SELECT, SL, VT, IsLarge, A, RoundedA);
 }
 
-
+static SDValue LowerVectorArith(SDValue Op, SelectionDAG &DAG) {
+  SDLoc DL(Op);
+  if (Op.getValueType() != MVT::v2i16)
+    return Op;
+  EVT EltVT = Op.getValueType().getVectorElementType();
+  SmallVector<SDValue> VecElements;
+  for (int I = 0, E = Op.getValueType().getVectorNumElements(); I < E; I++) {
+    SmallVector<SDValue> ScalarArgs;
+    for (int J = 0, NumOp = Op.getNumOperands(); J < NumOp; J++) {
+      SDValue Ext =
+          DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Op->getOperand(J),
+                      DAG.getIntPtrConstant(I, DL));
+      ScalarArgs.push_back(Ext);
+    }
+    VecElements.push_back(DAG.getNode(Op.getOpcode(), DL, EltVT, ScalarArgs));
----------------
Artem-B wrote:

Nit. I'm very tempted to suggest coalescing the loop into something like this:
```
llvm::transform(Op.ops(), back_inserter(ScalarArgs), [&](auto O){
  return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, O->getOperand(J),  DAG.getIntPtrConstant(I, DL))
})
```
That may be pushing it too far, but the inner per-operand loop itself does look like a prime candidate for replacement  with a `range for` as we do not use `J` for anything other than getting the operand.

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


More information about the llvm-commits mailing list