[llvm] [RISCV] Return nullptr for PHI defs in VSETVLIInfo::getAVLDefMI (PR #97395)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 02:27:25 PDT 2024
https://github.com/lukel97 updated https://github.com/llvm/llvm-project/pull/97395
>From 742082406b14d0850c3758aa91f04e875667424a Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Tue, 2 Jul 2024 15:47:56 +0800
Subject: [PATCH 1/2] [RISCV] Return nullptr for PHI defs in
VSETVLIInfo::getAVLDefMI
When checking if a VSETVLIInfo is compatible, we call hasEquallyZeroAVL when only the AVL-zeroness is demanded. This will try to lookup the defining MachineInstr (to check if it's an ADDI immediate) via getAVLDefMI, but in it we were asserting that the VSETVLIInfo's AVL wouldn't come from a phi. It turns out this can happen in normal circumstances.
This causes a crash when compiling highway, so this fixes it by relaxing the assertion.
---
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp | 7 ++---
.../RISCV/rvv/vsetvli-insert-crossbb.ll | 27 +++++++++++++++++++
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
index bf693344b070a..7e6eef47c121c 100644
--- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -586,13 +586,14 @@ class VSETVLIInfo {
}
// Most AVLIsReg infos will have a single defining MachineInstr, unless it was
// a PHI node. In that case getAVLVNInfo()->def will point to the block
- // boundary slot. If LiveIntervals isn't available, then nullptr is returned.
+ // boundary slot and this will return nullptr. If LiveIntervals isn't
+ // available, nullptr is also returned.
const MachineInstr *getAVLDefMI(const LiveIntervals *LIS) const {
assert(hasAVLReg());
- if (!LIS)
+ if (!LIS || getAVLVNInfo()->isPHIDef())
return nullptr;
auto *MI = LIS->getInstructionFromIndex(getAVLVNInfo()->def);
- assert(!(getAVLVNInfo()->isPHIDef() && MI));
+ assert(MI);
return MI;
}
diff --git a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
index 68e8f5dd0a406..92c8f9611db49 100644
--- a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
@@ -1062,3 +1062,30 @@ exit:
%c = call <vscale x 2 x i32> @llvm.riscv.vadd.nxv2i32(<vscale x 2 x i32> undef, <vscale x 2 x i32> %a, <vscale x 2 x i32> %d, i64 %vl)
ret <vscale x 2 x i32> %c
}
+
+define void @vlmax_avl_phi(i1 %cmp, ptr %p) {
+; CHECK-LABEL: vlmax_avl_phi:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: andi a0, a0, 1
+; CHECK-NEXT: vsetvli a0, zero, e8, m1, ta, ma
+; CHECK-NEXT: vmv.v.i v8, 0
+; CHECK-NEXT: vsetivli zero, 1, e8, m1, ta, ma
+; CHECK-NEXT: vse8.v v8, (a1)
+; CHECK-NEXT: ret
+entry:
+ br i1 %cmp, label %foo, label %bar
+
+foo:
+ %vl.foo = tail call i64 @llvm.riscv.vsetvlimax.i64(i64 0, i64 0)
+ br label %exit
+
+bar:
+ %vl.bar = tail call i64 @llvm.riscv.vsetvlimax.i64(i64 0, i64 0)
+ br label %exit
+
+exit:
+ %phivl = phi i64 [ %vl.foo, %foo ], [ %vl.bar, %bar ]
+ %1 = tail call <vscale x 8 x i8> @llvm.riscv.vmv.v.x.nxv8i8.i64(<vscale x 8 x i8> poison, i8 0, i64 %phivl)
+ call void @llvm.riscv.vse.nxv8i8(<vscale x 8 x i8> %1, ptr %p, i64 1)
+ ret void
+}
>From 06c461b1cd466de0de2bea6c9a2261dda4cf67c3 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Tue, 2 Jul 2024 17:26:53 +0800
Subject: [PATCH 2/2] Make %vl.foo and %vl.bar different in test
---
.../CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
index 92c8f9611db49..884c756840eb9 100644
--- a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
@@ -1063,11 +1063,17 @@ exit:
ret <vscale x 2 x i32> %c
}
-define void @vlmax_avl_phi(i1 %cmp, ptr %p) {
+define void @vlmax_avl_phi(i1 %cmp, ptr %p, i64 %a, i64 %b) {
; CHECK-LABEL: vlmax_avl_phi:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: andi a0, a0, 1
-; CHECK-NEXT: vsetvli a0, zero, e8, m1, ta, ma
+; CHECK-NEXT: beqz a0, .LBB25_2
+; CHECK-NEXT: # %bb.1: # %foo
+; CHECK-NEXT: vsetvli zero, a2, e8, m1, ta, ma
+; CHECK-NEXT: j .LBB25_3
+; CHECK-NEXT: .LBB25_2: # %bar
+; CHECK-NEXT: vsetvli zero, a3, e8, m1, ta, ma
+; CHECK-NEXT: .LBB25_3: # %exit
; CHECK-NEXT: vmv.v.i v8, 0
; CHECK-NEXT: vsetivli zero, 1, e8, m1, ta, ma
; CHECK-NEXT: vse8.v v8, (a1)
@@ -1076,11 +1082,11 @@ entry:
br i1 %cmp, label %foo, label %bar
foo:
- %vl.foo = tail call i64 @llvm.riscv.vsetvlimax.i64(i64 0, i64 0)
+ %vl.foo = tail call i64 @llvm.riscv.vsetvli.i64(i64 %a, i64 0, i64 0)
br label %exit
bar:
- %vl.bar = tail call i64 @llvm.riscv.vsetvlimax.i64(i64 0, i64 0)
+ %vl.bar = tail call i64 @llvm.riscv.vsetvli.i64(i64 %b, i64 0, i64 0)
br label %exit
exit:
More information about the llvm-commits
mailing list