[llvm] [Scalarizer][DirectX] support structs return types (PR #111569)

Tex Riddell via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 12:38:17 PDT 2024


================
@@ -699,6 +730,20 @@ bool ScalarizerVisitor::splitCall(CallInst &CI) {
   if (isVectorIntrinsicWithOverloadTypeAtArg(ID, -1))
     Tys.push_back(VS->SplitTy);
 
+  if (AreAllVectorsOfMatchingSize) {
+    for (unsigned I = 1; I < CallType->getNumContainedTypes(); I++) {
+      if (isVectorIntrinsicWithStructReturnOverloadAtField(ID, I)) {
+        std::optional<VectorSplit> CurrVS = getVectorSplit(
+            cast<FixedVectorType>(CallType->getContainedType(I)));
+        // This case does not seem to happen, but it is possible for
+        // VectorSplit.NumPacked >= NumElems. If that happens a VectorSplit
+        // is not returned and we will bailout of handling this call.
+        if (!CurrVS)
+          return false;
+        Tys.push_back(CurrVS->SplitTy);
+      }
----------------
tex3d wrote:

Skipping failure cases for `CurrVS` should happen outside of the if.  Before, this was under a branch checking if the type differed from the last field, so it was only necessary to check this when it changed, but now, we are gating this on whether this field type contributes to the overload type, so the check needs to be moved out of the if.
Also: we still don't bail if `CurrVS->NumPacked != VS->NumPacked`.

```suggestion
      std::optional<VectorSplit> CurrVS = getVectorSplit(
          cast<FixedVectorType>(CallType->getContainedType(I)));
      // When using ScalarizeMinBits, it is possible for
      // VectorSplit.NumPacked >= NumElems. If that happens a VectorSplit
      // is not returned and we will bailout of handling this call.
      // We also bailout if NumPacked does not match.
      if (!CurrVS || CurrVS->NumPacked != VS->NumPacked)
        return false;
      if (isVectorIntrinsicWithStructReturnOverloadAtField(ID, I))
        Tys.push_back(CurrVS->SplitTy);
```

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


More information about the llvm-commits mailing list