[all-commits] [llvm/llvm-project] 429f39: [LoongArch] Select VSUBI for add with negative spl...
hev via All-commits
all-commits at lists.llvm.org
Mon Apr 13 23:15:43 PDT 2026
Branch: refs/heads/users/hev/vsubi
Home: https://github.com/llvm/llvm-project
Commit: 429f39f637616133e30b399a29cbaa924288bf18
https://github.com/llvm/llvm-project/commit/429f39f637616133e30b399a29cbaa924288bf18
Author: WANG Rui <wangrui at loongson.cn>
Date: 2026-04-14 (Tue, 14 Apr 2026)
Changed paths:
M llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
M llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
M llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td
M llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td
M llvm/test/CodeGen/LoongArch/lasx/ir-instruction/sub.ll
M llvm/test/CodeGen/LoongArch/lsx/ir-instruction/sub.ll
Log Message:
-----------
[LoongArch] Select VSUBI for add with negative splat immediates
Currently, vector add with a negative splat immediate is lowered as a
vector splat followed by a register-register add, e.g.:
```
vrepli.b $vr1, -1
vadd.b $vr0, $vr0, $vr1
```
This misses the opportunity to use the more efficient VSUBI instruction
with a positive immediate.
This patch introduces `selectVSplatImmNeg` to detect negative splat
immediates whose negated value fits in a 5-bit unsigned immediate. New
patterns `(Pat{Vr,Xr}Nimm5)` are added to match:
```
add v, splat(-imm) --> vsubi v, v, imm
```
This avoids materializing the splat constant and reduces the instruction
count.
```
add <16 x i8> %a, splat (i8 -1)
=>
vsubi.bu $vr0, $vr0, 1
```
The transformation is applied for both LSX and LASX vector types.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list