[llvm] 0e72c3d - [NFC] Lockdown instructions of vspltisw for addition of vector of 1s (#160476)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 26 20:53:02 PDT 2025


Author: Himadhith
Date: 2025-09-27T09:22:58+05:30
New Revision: 0e72c3da2aa9e6a8da8b1fb4c91f651293ed8f54

URL: https://github.com/llvm/llvm-project/commit/0e72c3da2aa9e6a8da8b1fb4c91f651293ed8f54
DIFF: https://github.com/llvm/llvm-project/commit/0e72c3da2aa9e6a8da8b1fb4c91f651293ed8f54.diff

LOG: [NFC] Lockdown instructions of vspltisw for addition of vector of 1s (#160476)

This NFC patch looks to lock down the instruction generated for the
operation of `A + vector {1, 1, 1, 1}` in which the current code emits
`vspltisw`.
It can be made better with the use of a `2 cycle` instruction `xxleqv`
over the current `4 cycle vspltisw`.

---------

Co-authored-by: himadhith <himadhith.v at ibm.com>

Added: 
    llvm/test/CodeGen/PowerPC/vector-all-ones.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/CodeGen/PowerPC/vector-all-ones.ll b/llvm/test/CodeGen/PowerPC/vector-all-ones.ll
new file mode 100644
index 0000000000000..e4c93adcf50a6
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/vector-all-ones.ll
@@ -0,0 +1,23 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -verify-machineinstrs -O3 -mcpu=pwr9 -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:     -ppc-asm-full-reg-names --ppc-vsr-nums-as-vr < %s | FileCheck %s
+
+; RUN: llc -verify-machineinstrs -O3 -mcpu=pwr9 -mtriple=powerpc64-ibm-aix \
+; RUN:     -ppc-asm-full-reg-names --ppc-vsr-nums-as-vr < %s | FileCheck %s
+
+; RUN: llc -verify-machineinstrs -O3 -mcpu=pwr9 -mtriple=powerpc-ibm-aix \
+; RUN:     -ppc-asm-full-reg-names --ppc-vsr-nums-as-vr < %s | FileCheck %s
+
+; Currently the generated code uses `vspltisw` to generate vector of 1s followed by add operation.
+; This pattern is expected to be optimized in a future patch by using `xxleqv` to generate vector of -1s
+; followed by subtraction operation.
+define dso_local noundef <4 x i32> @test1(<4 x i32> %a) {
+; CHECK-LABEL: test1:
+; CHECK:       # %bb.0: # %entry
+; CHECK-NEXT:    vspltisw v3, 1
+; CHECK-NEXT:    vadduwm v2, v2, v3
+; CHECK-NEXT:    blr
+entry:
+  %add = add <4 x i32> %a, splat (i32 1)
+  ret <4 x i32> %add
+}


        


More information about the llvm-commits mailing list