Skip to content

Commit d24eaef

Browse files
authored
[RISCV] Sink vector select splat operands (#91554)
vmerge.vxm allows us to splat the true operand of a select, so sink it where possible to reduce vector register pressure.
1 parent db78ee0 commit d24eaef

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,7 @@ bool RISCVTargetLowering::canSplatOperand(unsigned Opcode, int Operand) const {
20192019
case Instruction::SDiv:
20202020
case Instruction::URem:
20212021
case Instruction::SRem:
2022+
case Instruction::Select:
20222023
return Operand == 1;
20232024
default:
20242025
return false;

llvm/test/CodeGen/RISCV/rvv/sink-splat-operands.ll

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5427,19 +5427,18 @@ for.cond.cleanup: ; preds = %vector.body
54275427
define void @sink_splat_select(ptr nocapture %a, i32 signext %x) {
54285428
; CHECK-LABEL: sink_splat_select:
54295429
; CHECK: # %bb.0: # %entry
5430+
; CHECK-NEXT: lui a2, 1
5431+
; CHECK-NEXT: add a2, a0, a2
5432+
; CHECK-NEXT: li a3, 42
54305433
; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, ma
5431-
; CHECK-NEXT: vmv.v.x v8, a1
5432-
; CHECK-NEXT: lui a1, 1
5433-
; CHECK-NEXT: add a1, a0, a1
5434-
; CHECK-NEXT: li a2, 42
54355434
; CHECK-NEXT: .LBB117_1: # %vector.body
54365435
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
5437-
; CHECK-NEXT: vle32.v v9, (a0)
5438-
; CHECK-NEXT: vmseq.vx v0, v9, a2
5439-
; CHECK-NEXT: vmerge.vvm v9, v9, v8, v0
5440-
; CHECK-NEXT: vse32.v v9, (a0)
5436+
; CHECK-NEXT: vle32.v v8, (a0)
5437+
; CHECK-NEXT: vmseq.vx v0, v8, a3
5438+
; CHECK-NEXT: vmerge.vxm v8, v8, a1, v0
5439+
; CHECK-NEXT: vse32.v v8, (a0)
54415440
; CHECK-NEXT: addi a0, a0, 16
5442-
; CHECK-NEXT: bne a0, a1, .LBB117_1
5441+
; CHECK-NEXT: bne a0, a2, .LBB117_1
54435442
; CHECK-NEXT: # %bb.2: # %for.cond.cleanup
54445443
; CHECK-NEXT: ret
54455444
entry:

0 commit comments

Comments
 (0)