Skip to content

Commit 62a967d

Browse files
authored
[RISCV] Return nullptr for PHI defs in VSETVLIInfo::getAVLDefMI (#97395)
When checking if a VSETVLIInfo is compatible, we call hasEquallyZeroAVL if 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.
1 parent efefee2 commit 62a967d

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,14 @@ class VSETVLIInfo {
586586
}
587587
// Most AVLIsReg infos will have a single defining MachineInstr, unless it was
588588
// a PHI node. In that case getAVLVNInfo()->def will point to the block
589-
// boundary slot. If LiveIntervals isn't available, then nullptr is returned.
589+
// boundary slot and this will return nullptr. If LiveIntervals isn't
590+
// available, nullptr is also returned.
590591
const MachineInstr *getAVLDefMI(const LiveIntervals *LIS) const {
591592
assert(hasAVLReg());
592-
if (!LIS)
593+
if (!LIS || getAVLVNInfo()->isPHIDef())
593594
return nullptr;
594595
auto *MI = LIS->getInstructionFromIndex(getAVLVNInfo()->def);
595-
assert(!(getAVLVNInfo()->isPHIDef() && MI));
596+
assert(MI);
596597
return MI;
597598
}
598599

llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,3 +1062,36 @@ exit:
10621062
%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)
10631063
ret <vscale x 2 x i32> %c
10641064
}
1065+
1066+
define void @vlmax_avl_phi(i1 %cmp, ptr %p, i64 %a, i64 %b) {
1067+
; CHECK-LABEL: vlmax_avl_phi:
1068+
; CHECK: # %bb.0: # %entry
1069+
; CHECK-NEXT: andi a0, a0, 1
1070+
; CHECK-NEXT: beqz a0, .LBB25_2
1071+
; CHECK-NEXT: # %bb.1: # %foo
1072+
; CHECK-NEXT: vsetvli zero, a2, e8, m1, ta, ma
1073+
; CHECK-NEXT: j .LBB25_3
1074+
; CHECK-NEXT: .LBB25_2: # %bar
1075+
; CHECK-NEXT: vsetvli zero, a3, e8, m1, ta, ma
1076+
; CHECK-NEXT: .LBB25_3: # %exit
1077+
; CHECK-NEXT: vmv.v.i v8, 0
1078+
; CHECK-NEXT: vsetivli zero, 1, e8, m1, ta, ma
1079+
; CHECK-NEXT: vse8.v v8, (a1)
1080+
; CHECK-NEXT: ret
1081+
entry:
1082+
br i1 %cmp, label %foo, label %bar
1083+
1084+
foo:
1085+
%vl.foo = tail call i64 @llvm.riscv.vsetvli.i64(i64 %a, i64 0, i64 0)
1086+
br label %exit
1087+
1088+
bar:
1089+
%vl.bar = tail call i64 @llvm.riscv.vsetvli.i64(i64 %b, i64 0, i64 0)
1090+
br label %exit
1091+
1092+
exit:
1093+
%phivl = phi i64 [ %vl.foo, %foo ], [ %vl.bar, %bar ]
1094+
%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)
1095+
call void @llvm.riscv.vse.nxv8i8(<vscale x 8 x i8> %1, ptr %p, i64 1)
1096+
ret void
1097+
}

0 commit comments

Comments
 (0)