[PATCH] D154114: [SLP] Provide an universal interface for FixedVectorType::get. NFC.
Han-Kuan Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 30 04:58:26 PDT 2023
HanKuanChen added a comment.
@aeubanks @nikic I will not add this in the commit message. It is too long.
Let's say we have a IR like this
%in1 = getelementptr inbounds i32, ptr %in0, i64 1
%in2 = getelementptr inbounds i32, ptr %in0, i64 2
%in3 = getelementptr inbounds i32, ptr %in0, i64 3
%v0 = load i32, ptr %in0, align 4
%v1 = load i32, ptr %in1, align 4
%v2 = load i32, ptr %in2, align 4
%v3 = load i32, ptr %in3, align 4
SLP can make this into `load <4 x i32>, ptr %in0, align 4`. Using `FixedVectorType::get(i32, 4)` works well.
For revec, we have a IR like this
%in1 = getelementptr inbounds i32, ptr %in0, i64 4
%in2 = getelementptr inbounds i32, ptr %in0, i64 8
%in3 = getelementptr inbounds i32, ptr %in0, i64 12
%v0 = load <4 x i32>, ptr %in0, align 4
%v1 = load <4 x i32>, ptr %in1, align 4
%v2 = load <4 x i32>, ptr %in2, align 4
%v3 = load <4 x i32>, ptr %in3, align 4
SLP can make this into `load <16 x i32>, ptr %in0, align 4`. But using `FixedVectorType::get(<4 x i32>, 4)` is incorrect. The actually function call should be `FixedVectorType::get(i32, 16)`.
To make scalar to vector and vector to vector work together, you need
unsigned NumElements = 1;
if (auto *VecTy = dyn_cast<FixedVectorType>(ScalarTy))
NumElements = VecTy->getNumElements();
FixedVectorType *VecTy = FixedVectorType::get(ScalarTy->getScalarType(), VF * NumElements);
If `FixedVectorType::get` occurs only few times, do in this way is better. But the fact is we need a function to wrap it.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154114/new/
https://reviews.llvm.org/D154114
More information about the llvm-commits
mailing list