[llvm] [RISCV] Sink vector select splat operands (PR #91554)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 21:17:35 PDT 2024
https://github.com/lukel97 created https://github.com/llvm/llvm-project/pull/91554
vmerge.vxm allows us to splat the true operand of a select, so sink it where possible to reduce vector register pressure.
>From d7c1c47d17f6d08df2bc67c815832503105567cf Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Thu, 9 May 2024 11:38:43 +0800
Subject: [PATCH] [RISCV] Sink vector select splat operands
vmerge.vxm allows us to splat the true operand of a select, so sink it where possible to reduce vector register pressure.
---
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 1 +
.../CodeGen/RISCV/rvv/sink-splat-operands.ll | 17 ++++++++---------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 846768f6d631e..1a831a69d8cdb 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -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;
diff --git a/llvm/test/CodeGen/RISCV/rvv/sink-splat-operands.ll b/llvm/test/CodeGen/RISCV/rvv/sink-splat-operands.ll
index 6e902e79896bf..618672344fe73 100644
--- a/llvm/test/CodeGen/RISCV/rvv/sink-splat-operands.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/sink-splat-operands.ll
@@ -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:
More information about the llvm-commits
mailing list