[llvm] [RISCV] Use LiveIntervals to determine if AVL dominates when coalescing (PR #118285)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 2 03:37:12 PST 2024
https://github.com/lukel97 created https://github.com/llvm/llvm-project/pull/118285
In order to coalesce a vsetvli with a register AVL into a previous vsetvli, we need to make sure that the AVL register is reachable at the previous vsetvli.
Back in pre-RA vsetvli insertion we just checked to see if the two virtual registers were the same virtual register, and then this was hacked around in the move. We can instead use live intervals to check that the reaching definition is the same at both instructions.
On its own this doesn't have much of an impact, but helps a lot in #118283 and enables coalescing in about 60 of the test cases from that PR.
>From ae29ef9f869bdf6f4243d09072bdd9089d8a7d24 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Mon, 2 Dec 2024 19:30:13 +0800
Subject: [PATCH] [RISCV] Use LiveIntervals to determine if AVL dominates when
coalescing
In order to coalesce a vsetvli with a register AVL into a previous vsetvli, we need to make sure that the AVL register is reachable at the previous vsetvli.
Back in pre-RA vsetvli insertion we just checked to see if the two virtual registers were the same virtual register, and then this was hacked around in the move. We can instead use live intervals to check that the reaching definition is the same at both instructions.
On its own this doesn't have much of an impact, but helps a lot in #118283 and enables coalescing in about 60 of the test cases from that PR.
---
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp | 15 ++++++++-------
llvm/test/CodeGen/RISCV/rvv/compressstore.ll | 13 ++++++-------
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
index 052b4a61298223..93f9bf5ceba138 100644
--- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -1619,14 +1619,15 @@ bool RISCVInsertVSETVLI::canMutatePriorConfig(
}
auto &AVL = MI.getOperand(1);
- auto &PrevAVL = PrevMI.getOperand(1);
- // If the AVL is a register, we need to make sure MI's AVL dominates PrevMI.
- // For now just check that PrevMI uses the same virtual register.
- if (AVL.isReg() && AVL.getReg() != RISCV::X0 &&
- (!MRI->hasOneDef(AVL.getReg()) || !PrevAVL.isReg() ||
- PrevAVL.getReg() != AVL.getReg()))
- return false;
+ // If the AVL is a register, we need to make sure its definition is the same
+ // at PrevMI as it was at MI.
+ if (AVL.isReg() && AVL.getReg() != RISCV::X0) {
+ VNInfo *VNI = getVNInfoFromReg(AVL.getReg(), MI, LIS);
+ VNInfo *PrevVNI = getVNInfoFromReg(AVL.getReg(), PrevMI, LIS);
+ if (!VNI || !PrevVNI || VNI->id != PrevVNI->id)
+ return false;
+ }
}
assert(PrevMI.getOperand(2).isImm() && MI.getOperand(2).isImm());
diff --git a/llvm/test/CodeGen/RISCV/rvv/compressstore.ll b/llvm/test/CodeGen/RISCV/rvv/compressstore.ll
index bfb2d0a3accc44..a407cd048ffe3f 100644
--- a/llvm/test/CodeGen/RISCV/rvv/compressstore.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/compressstore.ll
@@ -652,15 +652,14 @@ define void @test_compresstore_v64i32(ptr %p, <64 x i1> %mask, <64 x i32> %data)
; RV64-NEXT: vse32.v v24, (a0)
; RV64-NEXT: vsetivli zero, 4, e8, mf2, ta, ma
; RV64-NEXT: vslidedown.vi v8, v0, 4
-; RV64-NEXT: vsetvli zero, zero, e32, m2, ta, ma
-; RV64-NEXT: vmv.x.s a2, v0
; RV64-NEXT: vsetvli zero, a1, e32, m8, ta, ma
+; RV64-NEXT: vmv.x.s a1, v0
; RV64-NEXT: vcompress.vm v24, v16, v8
-; RV64-NEXT: vcpop.m a1, v8
-; RV64-NEXT: cpopw a2, a2
-; RV64-NEXT: slli a2, a2, 2
-; RV64-NEXT: add a0, a0, a2
-; RV64-NEXT: vsetvli zero, a1, e32, m8, ta, ma
+; RV64-NEXT: vcpop.m a2, v8
+; RV64-NEXT: cpopw a1, a1
+; RV64-NEXT: slli a1, a1, 2
+; RV64-NEXT: add a0, a0, a1
+; RV64-NEXT: vsetvli zero, a2, e32, m8, ta, ma
; RV64-NEXT: vse32.v v24, (a0)
; RV64-NEXT: ret
;
More information about the llvm-commits
mailing list