[llvm] 6ff0f69 - [SandboxVec][BottomUpVec] Fix vectorization of vector constants (#129290)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 28 14:37:52 PST 2025
Author: vporpo
Date: 2025-02-28T14:37:48-08:00
New Revision: 6ff0f69fec0ebdc86abf2e6af75f2edcccc2f936
URL: https://github.com/llvm/llvm-project/commit/6ff0f69fec0ebdc86abf2e6af75f2edcccc2f936
DIFF: https://github.com/llvm/llvm-project/commit/6ff0f69fec0ebdc86abf2e6af75f2edcccc2f936.diff
LOG: [SandboxVec][BottomUpVec] Fix vectorization of vector constants (#129290)
This patch fixes the value we generate when we vectorize constants.
Added:
Modified:
llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
llvm/test/Transforms/SandboxVectorizer/bottomup_basic.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
index 726240f708f6a..fe4f73e50687d 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
@@ -230,10 +230,9 @@ Value *BottomUpVec::createPack(ArrayRef<Value *> ToPack, BasicBlock *UserBB) {
// This may also return a Constant if ExtrI is a Constant.
auto *InsertI = InsertElementInst::create(
LastInsert, ExtrI, InsertLaneC, WhereIt, Ctx, "VPack");
- if (!isa<Constant>(InsertI)) {
- LastInsert = InsertI;
+ LastInsert = InsertI;
+ if (!isa<Constant>(InsertI))
WhereIt = std::next(cast<Instruction>(LastInsert)->getIterator());
- }
}
} else {
Constant *InsertLaneC =
diff --git a/llvm/test/Transforms/SandboxVectorizer/bottomup_basic.ll b/llvm/test/Transforms/SandboxVectorizer/bottomup_basic.ll
index 6baffebd65edc..e0c70e4b03dd4 100644
--- a/llvm/test/Transforms/SandboxVectorizer/bottomup_basic.ll
+++ b/llvm/test/Transforms/SandboxVectorizer/bottomup_basic.ll
@@ -416,3 +416,43 @@ define void @instrsInMultipleBundles(ptr noalias %ptr) {
store i8 %add1, ptr %gep1
ret void
}
+
+define void @vectorize_constants(ptr %ptr) {
+; CHECK-LABEL: define void @vectorize_constants(
+; CHECK-SAME: ptr [[PTR:%.*]]) {
+; CHECK-NEXT: [[PTR0:%.*]] = getelementptr i8, ptr [[PTR]], i32 0
+; CHECK-NEXT: [[VECL:%.*]] = load <2 x i8>, ptr [[PTR0]], align 1
+; CHECK-NEXT: [[VEC:%.*]] = add <2 x i8> [[VECL]], <i8 0, i8 1>
+; CHECK-NEXT: store <2 x i8> [[VEC]], ptr [[PTR0]], align 1
+; CHECK-NEXT: ret void
+;
+ %ptr0 = getelementptr i8, ptr %ptr, i32 0
+ %ptr1 = getelementptr i8, ptr %ptr, i32 1
+ %ld0 = load i8, ptr %ptr0
+ %ld1 = load i8, ptr %ptr1
+ %add0 = add i8 %ld0, 0
+ %add1 = add i8 %ld1, 1
+ store i8 %add0, ptr %ptr0
+ store i8 %add1, ptr %ptr1
+ ret void
+}
+
+define void @vectorize_constant_vectors(ptr %ptr) {
+; CHECK-LABEL: define void @vectorize_constant_vectors(
+; CHECK-SAME: ptr [[PTR:%.*]]) {
+; CHECK-NEXT: [[PTR0:%.*]] = getelementptr <2 x i8>, ptr [[PTR]], i32 0
+; CHECK-NEXT: [[VECL:%.*]] = load <4 x i8>, ptr [[PTR0]], align 2
+; CHECK-NEXT: [[VEC:%.*]] = sub <4 x i8> [[VECL]], <i8 0, i8 0, i8 1, i8 1>
+; CHECK-NEXT: store <4 x i8> [[VEC]], ptr [[PTR0]], align 2
+; CHECK-NEXT: ret void
+;
+ %ptr0 = getelementptr <2 x i8>, ptr %ptr, i32 0
+ %ptr1 = getelementptr <2 x i8>, ptr %ptr, i32 1
+ %ld0 = load <2 x i8>, ptr %ptr0
+ %ld1 = load <2 x i8>, ptr %ptr1
+ %sub0 = sub <2 x i8> %ld0, splat(i8 0)
+ %sub1 = sub <2 x i8> %ld1, splat(i8 1)
+ store <2 x i8> %sub0, ptr %ptr0
+ store <2 x i8> %sub1, ptr %ptr1
+ ret void
+}
More information about the llvm-commits
mailing list