Skip to content

Commit 1687aa2

Browse files
[RISCV][VLOPT] Don't reduce the VL is the same as CommonVL (#123878)
This fixes the slowdown in #123862.
1 parent 340706f commit 1687aa2

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,12 @@ bool RISCVVLOptimizer::tryReduceVL(MachineInstr &MI) {
13131313
return false;
13141314
}
13151315

1316+
if (CommonVL->isIdenticalTo(VLOp)) {
1317+
LLVM_DEBUG(
1318+
dbgs() << " Abort due to CommonVL == VLOp, no point in reducing.\n");
1319+
return false;
1320+
}
1321+
13161322
if (CommonVL->isImm()) {
13171323
LLVM_DEBUG(dbgs() << " Reduce VL from " << VLOp << " to "
13181324
<< CommonVL->getImm() << " for " << MI << "\n");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: llc -mtriple=riscv64 -mattr=+v -riscv-enable-vl-optimizer \
2+
; RUN: -verify-machineinstrs -debug-only=riscv-vl-optimizer -o - 2>&1 %s | FileCheck %s
3+
4+
; REQUIRES: asserts
5+
6+
; GitHub Issue #123862 provided a case where the riscv-vl-optimizer pass was
7+
; very slow. It was found that that case benefited greatly from aborting due
8+
; to CommonVL == VLOp. Adding the case provided in the issue would show up
9+
; as a long running test instead of a test failure. We would likley have a hard
10+
; time figuring if that case had a regression. So instead, we check this output
11+
; which was responsible for speeding it up.
12+
13+
define <vscale x 4 x i32> @same_vl_imm(<vscale x 4 x i32> %passthru, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
14+
; CHECK: User VL is: 4
15+
; CHECK-NEXT: Abort due to CommonVL == VLOp, no point in reducing.
16+
%v = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, i64 4)
17+
%w = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %v, <vscale x 4 x i32> %a, i64 4)
18+
ret <vscale x 4 x i32> %w
19+
}
20+
21+
define <vscale x 4 x i32> @same_vl_reg(<vscale x 4 x i32> %passthru, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, i64 %vl) {
22+
; CHECK: User VL is: %3:gprnox0
23+
; CHECK-NEXT: Abort due to CommonVL == VLOp, no point in reducing.
24+
%v = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, i64 %vl)
25+
%w = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %v, <vscale x 4 x i32> %a, i64 %vl)
26+
ret <vscale x 4 x i32> %w
27+
}

0 commit comments

Comments
 (0)