Skip to content

Commit

Permalink
[RISCV] Sink vector select splat operands (llvm#91554)
Browse files Browse the repository at this point in the history
vmerge.vxm allows us to splat the true operand of a select, so sink it
where possible to reduce vector register pressure.
  • Loading branch information
lukel97 authored May 10, 2024
1 parent db78ee0 commit d24eaef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,7 @@ bool RISCVTargetLowering::canSplatOperand(unsigned Opcode, int Operand) const {
case Instruction::SDiv:
case Instruction::URem:
case Instruction::SRem:
case Instruction::Select:
return Operand == 1;
default:
return false;
Expand Down
17 changes: 8 additions & 9 deletions llvm/test/CodeGen/RISCV/rvv/sink-splat-operands.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5427,19 +5427,18 @@ for.cond.cleanup: ; preds = %vector.body
define void @sink_splat_select(ptr nocapture %a, i32 signext %x) {
; CHECK-LABEL: sink_splat_select:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: lui a2, 1
; CHECK-NEXT: add a2, a0, a2
; CHECK-NEXT: li a3, 42
; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, ma
; CHECK-NEXT: vmv.v.x v8, a1
; CHECK-NEXT: lui a1, 1
; CHECK-NEXT: add a1, a0, a1
; CHECK-NEXT: li a2, 42
; CHECK-NEXT: .LBB117_1: # %vector.body
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
; CHECK-NEXT: vle32.v v9, (a0)
; CHECK-NEXT: vmseq.vx v0, v9, a2
; CHECK-NEXT: vmerge.vvm v9, v9, v8, v0
; CHECK-NEXT: vse32.v v9, (a0)
; CHECK-NEXT: vle32.v v8, (a0)
; CHECK-NEXT: vmseq.vx v0, v8, a3
; CHECK-NEXT: vmerge.vxm v8, v8, a1, v0
; CHECK-NEXT: vse32.v v8, (a0)
; CHECK-NEXT: addi a0, a0, 16
; CHECK-NEXT: bne a0, a1, .LBB117_1
; CHECK-NEXT: bne a0, a2, .LBB117_1
; CHECK-NEXT: # %bb.2: # %for.cond.cleanup
; CHECK-NEXT: ret
entry:
Expand Down

0 comments on commit d24eaef

Please sign in to comment.