[llvm] [SystemZ] Fix Operand Retrieval for Vector Reduction Intrinsic in `shouldExpandReduction` (PR #88874)

Dominik Steenken via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 16 04:48:41 PDT 2024


================
@@ -1323,25 +1324,43 @@ SystemZTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
 }
 
 bool SystemZTTIImpl::shouldExpandReduction(const IntrinsicInst *II) const {
-  // Always expand on Subtargets without vector instructions
+  // Always expand on Subtargets without vector instructions.
   if (!ST->hasVector())
     return true;
 
-  // Always expand for operands that do not fill one vector reg
-  auto *Type = cast<FixedVectorType>(II->getOperand(0)->getType());
-  unsigned NumElts = Type->getNumElements();
-  unsigned ScalarSize = Type->getScalarSizeInBits();
+  // Find the type of the vector operand of the intrinsic
+  // This assumes that each vector reduction intrinsic only
+  // has one vector operand.
+  FixedVectorType *VType = 0x0;
+  for (unsigned I = 0; I < II->getNumOperands(); ++I) {
+    auto *T = II->getOperand(I)->getType();
+    if (T->isVectorTy()) {
+      VType = cast<FixedVectorType>(T);
+      break;
+    }
+  }
+
----------------
dominik-steenken wrote:

I was going off the list of intrinsics [here](https://llvm.org/docs/LangRef.html#llvm-vector-reduce-add-intrinsic). According to that, all of the reduction intrinsics either have a single vector as an operand, or a scalar and a vector. So any vector found should be the only vector.
However, if we want to be robust towards future intrinsic additions, we might want to handle this diffferently? However, once there are more than one vector operand, how would we generically decide which one the vector that is supposed to be reduced is?

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


More information about the llvm-commits mailing list