Skip to content

Commit 31f47dd

Browse files
authored
[RISCV] Update evaluateBranch for Xqci (#141718)
This implements RISCVMCInstrAnalysis::evaluateBranch for the two Xqci pc-relative jumps, which were otherwise not being displayed correctly when disassembling. This also adds tests for all Xqci branches, and also the Core-V branches as they work, but did not have coverage.
1 parent 9c6a442 commit 31f47dd

File tree

3 files changed

+69
-8
lines changed

3 files changed

+69
-8
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,24 +212,24 @@ class RISCVMCInstrAnalysis : public MCInstrAnalysis {
212212
return true;
213213
}
214214

215-
if (Inst.getOpcode() == RISCV::C_JAL || Inst.getOpcode() == RISCV::C_J) {
215+
switch (Inst.getOpcode()) {
216+
case RISCV::C_J:
217+
case RISCV::C_JAL:
218+
case RISCV::QC_E_J:
219+
case RISCV::QC_E_JAL:
216220
Target = Addr + Inst.getOperand(0).getImm();
217221
return true;
218-
}
219-
220-
if (Inst.getOpcode() == RISCV::JAL) {
222+
case RISCV::JAL:
221223
Target = Addr + Inst.getOperand(1).getImm();
222224
return true;
223-
}
224-
225-
if (Inst.getOpcode() == RISCV::JALR) {
225+
case RISCV::JALR: {
226226
if (auto TargetRegState = getGPRState(Inst.getOperand(1).getReg())) {
227227
Target = *TargetRegState + Inst.getOperand(2).getImm();
228228
return true;
229229
}
230-
231230
return false;
232231
}
232+
}
233233

234234
return false;
235235
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# RUN: llvm-mc -assemble -triple riscv32 \
2+
# RUN: -mattr=+xcvbi \
3+
# RUN: %s -filetype=obj -o - \
4+
# RUN: | llvm-objdump -d -M no-aliases - \
5+
# RUN: --mattr=+xcvbi \
6+
# RUN: | FileCheck %s
7+
8+
.option exact
9+
10+
# CHECK-LABEL: <label1>:
11+
label1:
12+
13+
# CHECK-NEXT: cv.beqimm a0, 0x1, 0x0 <label1>
14+
cv.beqimm a0, 1, label1
15+
# CHECK-NEXT: cv.beqimm a0, 0x1, 0x10 <label2>
16+
cv.beqimm a0, 1, label2
17+
18+
# CHECK-NEXT: cv.bneimm a0, 0x2, 0x0 <label1>
19+
cv.bneimm a0, 2, label1
20+
# CHECK-NEXT: cv.bneimm a0, 0x2, 0x10 <label2>
21+
cv.bneimm a0, 2, label2
22+
23+
24+
label2:
25+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# RUN: llvm-mc -assemble -triple riscv32 \
2+
# RUN: -mattr=+experimental-xqcilb,+experimental-xqcibi \
3+
# RUN: %s -filetype=obj -o - \
4+
# RUN: | llvm-objdump -d -M no-aliases - \
5+
# RUN: --mattr=+experimental-xqcilb,+experimental-xqcibi \
6+
# RUN: | FileCheck %s
7+
8+
.option exact
9+
10+
# CHECK-LABEL: <label1>:
11+
label1:
12+
13+
# CHECK-NEXT: qc.e.j 0x0 <label1>
14+
qc.e.j label1
15+
# CHECK-NEXT: qc.e.j 0x2c <label2>
16+
qc.e.j label2
17+
18+
# CHECK-NEXT: qc.e.jal 0x0 <label1>
19+
qc.e.jal label1
20+
# CHECK-NEXT: qc.e.jal 0x2c <label2>
21+
qc.e.jal label2
22+
23+
# CHECK-NEXT: qc.beqi a0, 0x1, 0x0 <label1>
24+
qc.beqi a0, 1, label1
25+
26+
# CHECK-NEXT: qc.bnei a0, 0x1, 0x2c <label2>
27+
qc.bnei a0, 1, label2
28+
29+
# CHECK-NEXT: qc.e.beqi a0, 0x2, 0x0 <label1>
30+
qc.e.beqi a0, 2, label1
31+
32+
# CHECK-NEXT: qc.e.bnei a0, 0x2, 0x2c <label2>
33+
qc.e.bnei a0, 2, label2
34+
35+
label2:
36+

0 commit comments

Comments
 (0)