Skip to content

Commit d70cf14

Browse files
michaelmaitlandMaheshRavishankar
authored andcommitted
[RISCV][VLOPT] Don't reduce the VL is the same as CommonVL
This fixes llvm#123862.
1 parent 40367f2 commit d70cf14

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,13 @@ bool RISCVVLOptimizer::tryReduceVL(MachineInstr &OrigMI) {
13201320
}
13211321

13221322
if (CommonVL->isImm()) {
1323+
if (CommonVL->isImm() && VLOp.isImm() &&
1324+
VLOp.getImm() == CommonVL->getImm()) {
1325+
LLVM_DEBUG(dbgs() << " VL is already reduced to" << VLOp << " for "
1326+
<< MI << "\n");
1327+
continue;
1328+
}
1329+
13231330
LLVM_DEBUG(dbgs() << " Reduce VL from " << VLOp << " to "
13241331
<< CommonVL->getImm() << " for " << MI << "\n");
13251332
VLOp.ChangeToImmediate(CommonVL->getImm());

llvm/test/CodeGen/RISCV/rvv/vl-opt.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,14 @@ define <vscale x 4 x i32> @dont_optimize_tied_def(<vscale x 4 x i32> %a, <vscale
150150
ret <vscale x 4 x i32> %2
151151
}
152152

153+
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) {
154+
; CHECK-LABEL: same_vl_imm:
155+
; CHECK: # %bb.0:
156+
; CHECK-NEXT: vsetivli zero, 4, e32, m2, ta, ma
157+
; CHECK-NEXT: vadd.vv v8, v10, v12
158+
; CHECK-NEXT: vadd.vv v8, v8, v10
159+
; CHECK-NEXT: ret
160+
%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, iXLen 4)
161+
%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, iXLen 4)
162+
ret <vscale x 4 x i32> %w
163+
}

0 commit comments

Comments
 (0)