Skip to content

Commit

Permalink
[RISCV] Fix doPRE not checking for ignored AVLs
Browse files Browse the repository at this point in the history
This fixes a crash introduced in 011a653
that showed up when compiling with -mrvv-vector-bits=zvl. Beforehand, if a
basic block only contained vmv.s.x the AVL register in VSETVLIInfo would
have been NoRegister since it ignores VL.

In doPRE if AvailableInfo had a register AVL we checked that it dominated,
but coincidentally this failed for NoRegister. Now that the ignored AVL
case is separated out, check for it and bail.

As a side note, it turns out 011a653 is
less NFC than it seems as we can now do PRE on blocks where AvailableInfo's
AVL is VLMAX.
  • Loading branch information
lukel97 committed Apr 26, 2024
1 parent 65fb80b commit 7840fa9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,11 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
return;
}

// If the AVL isn't used in its predecessors then bail, since we have no AVL
// to insert a vsetvli with.
if (AvailableInfo.hasAVLIgnored())
return;

// Model the effect of changing the input state of the block MBB to
// AvailableInfo. We're looking for two issues here; one legality,
// one profitability.
Expand Down
13 changes: 13 additions & 0 deletions llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
ret void
}

define void @pre_undemanded_vl() {
ret void
}

declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>)

declare <vscale x 1 x i64> @llvm.riscv.vadd.nxv1i64.nxv1i64.i64(<vscale x 1 x i64>, <vscale x 1 x i64>, <vscale x 1 x i64>, i64) #1
Expand Down Expand Up @@ -1041,3 +1045,12 @@ body: |
PseudoRET
...
---
name: pre_undemanded_vl
body: |
bb.0:
PseudoBR %bb.1
bb.1:
%x:gpr = PseudoVMV_X_S undef $noreg, 6
PseudoBR %bb.1
...

0 comments on commit 7840fa9

Please sign in to comment.