[llvm] [SandboxVec][BottomUpVec] Fix vectorization of vector constants (PR #129290)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 28 11:28:10 PST 2025
https://github.com/vporpo created https://github.com/llvm/llvm-project/pull/129290
This patch fixes the value we generate when we vectorize constants.
>From da73880d1ded31fcb7dc040302ab8a8f44e36037 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Tue, 11 Feb 2025 13:14:52 -0800
Subject: [PATCH] [SandboxVec][BottomUpVec] Fix vectorization of vector
constants
This patch fixes the value we generate when we vectorize constants.
---
.../SandboxVectorizer/Passes/BottomUpVec.cpp | 5 +--
.../SandboxVectorizer/bottomup_basic.ll | 40 +++++++++++++++++++
2 files changed, 42 insertions(+), 3 deletions(-)
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