Skip to content

[SandboxVec][BottomUpVec] Fix vectorization of vector constants #129290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2025

Conversation

vporpo
Copy link
Contributor

@vporpo vporpo commented Feb 28, 2025

This patch fixes the value we generate when we vectorize constants.

This patch fixes the value we generate when we vectorize constants.
@llvmbot
Copy link
Member

llvmbot commented Feb 28, 2025

@llvm/pr-subscribers-vectorizers

@llvm/pr-subscribers-llvm-transforms

Author: vporpo (vporpo)

Changes

This patch fixes the value we generate when we vectorize constants.


Full diff: https://github.com/llvm/llvm-project/pull/129290.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp (+2-3)
  • (modified) llvm/test/Transforms/SandboxVectorizer/bottomup_basic.ll (+40)
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
+}

@vporpo vporpo merged commit 6ff0f69 into llvm:main Feb 28, 2025
14 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 28, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-gcc-ubuntu running on sie-linux-worker3 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/13769

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: tools/llvm-exegesis/RISCV/rvv/reduction.test' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p670 -benchmark-phase=assemble-measured-code --mode=latency --opcode-name=PseudoVWREDSUMU_VS_M8_E32 --min-instructions=100 |     /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/tools/llvm-exegesis/RISCV/rvv/reduction.test
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p670 -benchmark-phase=assemble-measured-code --mode=latency --opcode-name=PseudoVWREDSUMU_VS_M8_E32 --min-instructions=100
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/tools/llvm-exegesis/RISCV/rvv/reduction.test
�[1m/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/tools/llvm-exegesis/RISCV/rvv/reduction.test:7:14: �[0m�[0;1;31merror: �[0m�[1mCHECK-NOT: excluded string found in input
�[0m# CHECK-NOT: V[[REG:[0-9]+]] V[[REG]] V{{[0-9]+}}M8 V[[REG]]
�[0;1;32m             ^
�[0m�[1m<stdin>:5:31: �[0m�[0;1;30mnote: �[0m�[1mfound here
�[0m - 'PseudoVWREDSUMU_VS_M8_E32 V1 V1 V0M8 V16 i_0xffffffffffffffff i_0x5 i_0x0'
�[0;1;32m                              ^~~~~~~~~~~~~
�[0m�[1m<stdin>:5:32: �[0m�[0;1;30mnote: �[0m�[1mcaptured var "REG"
�[0m - 'PseudoVWREDSUMU_VS_M8_E32 V1 V1 V0M8 V16 i_0xffffffffffffffff i_0x5 i_0x0'
�[0;1;32m                               ^
�[0m
Input file: <stdin>
Check file: /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/tools/llvm-exegesis/RISCV/rvv/reduction.test

-dump-input=help explains the following input dump.

Input was:
<<<<<<
�[1m�[0m�[0;1;30m         1: �[0m�[1m�[0;1;46m--- �[0m
�[0;1;30m         2: �[0m�[1m�[0;1;46mmode: latency �[0m
�[0;1;30m         3: �[0m�[1m�[0;1;46mkey: �[0m
�[0;1;30m         4: �[0m�[1m�[0;1;46m �[0minstructions:�[0;1;46m �[0m
�[0;1;32mcheck:5      ^~~~~~~~~~~~~
�[0m�[0;1;30m         5: �[0m�[1m�[0;1;46m - '�[0mPseudoVWREDSUMU_VS_M8_E32�[0;1;46m V1 V1 V0M8 V16 i_0xffffffffffffffff i_0x5 i_0x0' �[0m
�[0;1;32mnext:6          ^~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;31mnot:7'0                                   !~~~~~~~~~~~~                                     error: no match expected
�[0m�[0;1;31mnot:7'1                                    !                                                captured var "REG"
�[0m�[0;1;30m         6: �[0m�[1m�[0;1;46m config: 'vtype = {AVL: VLMAX, SEW: e32, Policy: tu/mu}' �[0m
�[0;1;30m         7: �[0m�[1m�[0;1;46m register_initial_values: �[0m
�[0;1;30m         8: �[0m�[1m�[0;1;46m - 'V1=0x0' �[0m
�[0;1;30m         9: �[0m�[1m�[0;1;46m - 'V0M8=0x0' �[0m
�[0;1;30m        10: �[0m�[1m�[0;1;46m - 'V16=0x0' �[0m
�[0;1;30m        11: �[0m�[1m�[0;1;46mcpu_name: sifive-p670 �[0m
�[0;1;30m        12: �[0m�[1m�[0;1;46mllvm_triple: riscv64 �[0m
�[0;1;30m        13: �[0m�[1m�[0;1;46mmin_instructions: 100 �[0m
�[0;1;30m        14: �[0m�[1m�[0;1;46mmeasurements: [] �[0m
�[0;1;30m        15: �[0m�[1m�[0;1;46merror: actual measurements skipped. �[0m
�[0;1;30m        16: �[0m�[1m�[0;1;46minfo: Repeating a single implicitly serial instruction �[0m
�[0;1;30m        17: �[0m�[1m�[0;1;46massembled_snippet: 57733009D70008C2D70008C2D70008C2D70008C28280 �[0m
�[0;1;30m        18: �[0m�[1m�[0;1;46m... �[0m
�[0;1;30m        19: �[0m�[1m�[0;1;46m�[0m
�[0;1;32meof:7       ^
�[0m>>>>>>
...

jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
…#129290)

This patch fixes the value we generate when we vectorize constants.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants