[llvm] [LV] Teach LoopVectorizationLegality about struct vector calls (PR #119221)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 6 09:50:42 PST 2025
================
@@ -942,11 +954,24 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
if (CI && !VFDatabase::getMappings(*CI).empty())
VecCallVariantsFound = true;
+ auto CanWidenInstruction = [this](Instruction const &Inst) {
+ Type *InstTy = Inst.getType();
+ if (isa<CallInst>(Inst) && isa<StructType>(InstTy) &&
+ canWidenCallReturnType(InstTy)) {
+ // 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 VectorType::isValidElementType(InstTy) || InstTy->isVoidTy();
----------------
david-arm wrote:
It's a shame this can't just call `canVectorizeTy` here, since it's duplicating the logic in that function. I'm not sure what you think, but you could just write this as:
```
return !isa<StructType>(InstTy) && canVectorizeTy(StructTy);
```
Alternatively, you could restructure the wider logic a bit to something like this:
```
Type *InstTy = Inst.getType();
if (isa<StructType>(InstTy)) {
if (!isaCallInst>(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);
```
Any thoughts?
https://github.com/llvm/llvm-project/pull/119221
More information about the llvm-commits
mailing list