Skip to content

Commit a793329

Browse files
frasercrmcktstellar
authored andcommitted
[RISCV] Fix reporting of incorrect commutable operand indices
This patch fixes an issue where RISCV's `findCommutedOpIndices` would incorrectly return the pseudo `CommuteAnyOperandIndex` as a commutable operand index, rather than fixing a specific index. Reviewed By: rogfer01 Differential Revision: https://reviews.llvm.org/D108206 (cherry picked from commit 5b06cba)
1 parent c9afa3a commit a793329

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ bool RISCVInstrInfo::findCommutedOpIndices(const MachineInstr &MI,
12231223
// Both of operands are not fixed. Set one of commutable
12241224
// operands to the tied source.
12251225
CommutableOpIdx1 = 1;
1226-
} else if (SrcOpIdx1 == CommutableOpIdx1) {
1226+
} else if (SrcOpIdx1 == CommuteAnyOperandIndex) {
12271227
// Only one of the operands is not fixed.
12281228
CommutableOpIdx1 = SrcOpIdx2;
12291229
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -march=riscv64 -mattr=+experimental-v -run-pass=simple-register-coalescing %s -o - 2>&1 | FileCheck %s
3+
4+
# This test used to crash in the register coalescer when the target would
5+
# return the out-of-bounds CommuteAnyOperandIndex for one of its commutable
6+
# operand indices.
7+
8+
--- |
9+
target triple = "riscv64"
10+
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
11+
12+
define void @commuted_op_indices() {
13+
unreachable
14+
}
15+
...
16+
---
17+
name: commuted_op_indices
18+
tracksRegLiveness: true
19+
registers:
20+
- { id: 0, class: vr, preferred-register: '' }
21+
- { id: 1, class: vrnov0, preferred-register: '' }
22+
- { id: 2, class: vrnov0, preferred-register: '' }
23+
- { id: 3, class: vr, preferred-register: '' }
24+
body: |
25+
bb.0:
26+
liveins: $v0, $v1, $v2
27+
; CHECK-LABEL: name: commuted_op_indices
28+
; CHECK: liveins: $v0, $v1, $v2
29+
; CHECK: [[COPY:%[0-9]+]]:vr = COPY $v0
30+
; CHECK: [[COPY1:%[0-9]+]]:vrnov0 = COPY $v1
31+
; CHECK: [[COPY2:%[0-9]+]]:vrnov0 = COPY $v2
32+
; CHECK: [[PseudoVNMSUB_VV_M1_:%[0-9]+]]:vr = PseudoVNMSUB_VV_M1 [[PseudoVNMSUB_VV_M1_]], [[COPY1]], [[COPY2]], $x0, 6, 1, implicit $vl, implicit $vtype
33+
; CHECK: [[COPY2:%[0-9]+]]:vr = COPY [[PseudoVNMSUB_VV_M1_]]
34+
; CHECK: dead [[COPY2]]:vr = PseudoVSLL_VI_M1 [[COPY2]], 11, $noreg, 6, implicit $vl, implicit $vtype
35+
; CHECK: $v0 = COPY [[PseudoVNMSUB_VV_M1_]]
36+
; CHECK: PseudoRET implicit $v0
37+
%0:vr = COPY $v0
38+
%1:vrnov0 = COPY $v1
39+
%2:vrnov0 = COPY $v2
40+
%0:vr = PseudoVNMSUB_VV_M1 %0, %1, killed %2, $x0, 6, 1, implicit $vl, implicit $vtype
41+
%3:vr = COPY %0
42+
%3:vr = PseudoVSLL_VI_M1 %3, 11, $noreg, 6, implicit $vl, implicit $vtype
43+
$v0 = COPY %0
44+
PseudoRET implicit $v0
45+
...

0 commit comments

Comments
 (0)