[llvm] [LV] Teach LoopVectorizationLegality about struct vector calls (PR #119221)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 14:12:31 PST 2025


================
@@ -942,11 +954,25 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
       if (CI && !VFDatabase::getMappings(*CI).empty())
         VecCallVariantsFound = true;
 
+      auto CanWidenInstruction = [this](Instruction const &Inst) {
+        Type *InstTy = Inst.getType();
+        if (isa<StructType>(InstTy)) {
+          if (!isa<CallInst>(Inst) || !canWidenCallReturnType(InstTy))
+            return false;
+          // TODO: Remove the `StructVecCallFound` flag once vectorizing calls
+          // with struct returns is supported.
+          StructVecCallFound = true;
+          // For now, we only recognize struct values returned from calls where
+          // all users are extractvalue as vectorizable.
+          return all_of(Inst.users(), IsaPred<ExtractValueInst>);
+        }
+        return canVectorizeTy(InstTy);
----------------
fhahn wrote:

might be slightly clearer to handle simpler case first and then the struct types, with an explanation

```suggestion
        if (!isa<StructType>(InstTy))
           return canVectorizeTy(InstTy);
           
           // Struct types are only allowed on calls, if all element types can be widened.
           ....
        ...
```

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


More information about the llvm-commits mailing list