Skip to content

[RISCV] Update evaluateBranch for Xqci #141718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,24 +212,24 @@ class RISCVMCInstrAnalysis : public MCInstrAnalysis {
return true;
}

if (Inst.getOpcode() == RISCV::C_JAL || Inst.getOpcode() == RISCV::C_J) {
switch (Inst.getOpcode()) {
case RISCV::C_J:
case RISCV::C_JAL:
case RISCV::QC_E_J:
case RISCV::QC_E_JAL:
Target = Addr + Inst.getOperand(0).getImm();
return true;
}

if (Inst.getOpcode() == RISCV::JAL) {
case RISCV::JAL:
Target = Addr + Inst.getOperand(1).getImm();
return true;
}

if (Inst.getOpcode() == RISCV::JALR) {
case RISCV::JALR: {
if (auto TargetRegState = getGPRState(Inst.getOperand(1).getReg())) {
Target = *TargetRegState + Inst.getOperand(2).getImm();
return true;
}

return false;
}
}

return false;
}
Expand Down
25 changes: 25 additions & 0 deletions llvm/test/MC/Disassembler/RISCV/branch-targets-xcv.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# RUN: llvm-mc -assemble -triple riscv32 \
# RUN: -mattr=+xcvbi \
# RUN: %s -filetype=obj -o - \
# RUN: | llvm-objdump -d -M no-aliases - \
# RUN: --mattr=+xcvbi \
# RUN: | FileCheck %s

.option exact

# CHECK-LABEL: <label1>:
label1:

# CHECK-NEXT: cv.beqimm a0, 0x1, 0x0 <label1>
cv.beqimm a0, 1, label1
# CHECK-NEXT: cv.beqimm a0, 0x1, 0x10 <label2>
cv.beqimm a0, 1, label2

# CHECK-NEXT: cv.bneimm a0, 0x2, 0x0 <label1>
cv.bneimm a0, 2, label1
# CHECK-NEXT: cv.bneimm a0, 0x2, 0x10 <label2>
cv.bneimm a0, 2, label2


label2:

36 changes: 36 additions & 0 deletions llvm/test/MC/Disassembler/RISCV/branch-targets-xqci.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# RUN: llvm-mc -assemble -triple riscv32 \
# RUN: -mattr=+experimental-xqcilb,+experimental-xqcibi \
# RUN: %s -filetype=obj -o - \
# RUN: | llvm-objdump -d -M no-aliases - \
# RUN: --mattr=+experimental-xqcilb,+experimental-xqcibi \
# RUN: | FileCheck %s

.option exact

# CHECK-LABEL: <label1>:
label1:

# CHECK-NEXT: qc.e.j 0x0 <label1>
qc.e.j label1
# CHECK-NEXT: qc.e.j 0x2c <label2>
qc.e.j label2

# CHECK-NEXT: qc.e.jal 0x0 <label1>
qc.e.jal label1
# CHECK-NEXT: qc.e.jal 0x2c <label2>
qc.e.jal label2

# CHECK-NEXT: qc.beqi a0, 0x1, 0x0 <label1>
qc.beqi a0, 1, label1

# CHECK-NEXT: qc.bnei a0, 0x1, 0x2c <label2>
qc.bnei a0, 1, label2

# CHECK-NEXT: qc.e.beqi a0, 0x2, 0x0 <label1>
qc.e.beqi a0, 2, label1

# CHECK-NEXT: qc.e.bnei a0, 0x2, 0x2c <label2>
qc.e.bnei a0, 2, label2

label2:

Loading