[llvm] 796af0c - [SLP] Move getInsertIndex function, NFC.
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 14 06:24:10 PDT 2022
Author: Alexey Bataev
Date: 2022-09-14T06:22:52-07:00
New Revision: 796af0c02728830a8d36952909dbe11ccb3af8f6
URL: https://github.com/llvm/llvm-project/commit/796af0c02728830a8d36952909dbe11ccb3af8f6
DIFF: https://github.com/llvm/llvm-project/commit/796af0c02728830a8d36952909dbe11ccb3af8f6.diff
LOG: [SLP] Move getInsertIndex function, NFC.
Part of D110978.
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index a58b4bef0e6b3..43774bb6fca29 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -284,6 +284,40 @@ static bool isCommutative(Instruction *I) {
return false;
}
+/// \returns inserting index of InsertElement or InsertValue instruction,
+/// using Offset as base offset for index.
+static Optional<unsigned> getInsertIndex(const Value *InsertInst,
+ unsigned Offset = 0) {
+ int Index = Offset;
+ if (const auto *IE = dyn_cast<InsertElementInst>(InsertInst)) {
+ if (const auto *CI = dyn_cast<ConstantInt>(IE->getOperand(2))) {
+ auto *VT = cast<FixedVectorType>(IE->getType());
+ if (CI->getValue().uge(VT->getNumElements()))
+ return None;
+ Index *= VT->getNumElements();
+ Index += CI->getZExtValue();
+ return Index;
+ }
+ return None;
+ }
+
+ const auto *IV = cast<InsertValueInst>(InsertInst);
+ Type *CurrentType = IV->getType();
+ for (unsigned I : IV->indices()) {
+ if (const auto *ST = dyn_cast<StructType>(CurrentType)) {
+ Index *= ST->getNumElements();
+ CurrentType = ST->getElementType(I);
+ } else if (const auto *AT = dyn_cast<ArrayType>(CurrentType)) {
+ Index *= AT->getNumElements();
+ CurrentType = AT->getElementType();
+ } else {
+ return None;
+ }
+ Index += I;
+ }
+ return Index;
+}
+
/// Checks if the given value is actually an undefined constant vector.
static bool isUndefVector(const Value *V) {
if (isa<UndefValue>(V))
@@ -739,40 +773,6 @@ static void inversePermutation(ArrayRef<unsigned> Indices,
Mask[Indices[I]] = I;
}
-/// \returns inserting index of InsertElement or InsertValue instruction,
-/// using Offset as base offset for index.
-static Optional<unsigned> getInsertIndex(const Value *InsertInst,
- unsigned Offset = 0) {
- int Index = Offset;
- if (const auto *IE = dyn_cast<InsertElementInst>(InsertInst)) {
- if (const auto *CI = dyn_cast<ConstantInt>(IE->getOperand(2))) {
- auto *VT = cast<FixedVectorType>(IE->getType());
- if (CI->getValue().uge(VT->getNumElements()))
- return None;
- Index *= VT->getNumElements();
- Index += CI->getZExtValue();
- return Index;
- }
- return None;
- }
-
- const auto *IV = cast<InsertValueInst>(InsertInst);
- Type *CurrentType = IV->getType();
- for (unsigned I : IV->indices()) {
- if (const auto *ST = dyn_cast<StructType>(CurrentType)) {
- Index *= ST->getNumElements();
- CurrentType = ST->getElementType(I);
- } else if (const auto *AT = dyn_cast<ArrayType>(CurrentType)) {
- Index *= AT->getNumElements();
- CurrentType = AT->getElementType();
- } else {
- return None;
- }
- Index += I;
- }
- return Index;
-}
-
/// Reorders the list of scalars in accordance with the given \p Mask.
static void reorderScalars(SmallVectorImpl<Value *> &Scalars,
ArrayRef<int> Mask) {
More information about the llvm-commits
mailing list