[PATCH] D84833: Implement indirect branch generation in position independent code for the RISC-V target
msizanoen1 via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 29 08:06:29 PDT 2020
msizanoen1 updated this revision to Diff 281597.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84833/new/
https://reviews.llvm.org/D84833
Files:
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
llvm/test/CodeGen/RISCV/branch-relaxation.ll
Index: llvm/test/CodeGen/RISCV/branch-relaxation.ll
===================================================================
--- llvm/test/CodeGen/RISCV/branch-relaxation.ll
+++ llvm/test/CodeGen/RISCV/branch-relaxation.ll
@@ -1,7 +1,11 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=riscv32 -verify-machineinstrs -filetype=obj < %s \
; RUN: -o /dev/null 2>&1
+; RUN: llc -mtriple=riscv32 -relocation-model=pic -verify-machineinstrs \
+; RUN: -filetype=obj < %s -o /dev/null 2>&1
; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s | FileCheck %s
+; RUN: llc -mtriple=riscv32 -relocation-model=pic -verify-machineinstrs < %s \
+; RUN: | FileCheck %s
define void @relax_bcc(i1 %a) nounwind {
; CHECK-LABEL: relax_bcc:
@@ -32,8 +36,7 @@
; CHECK-NEXT: andi a0, a0, 1
; CHECK-NEXT: bnez a0, .LBB1_1
; CHECK-NEXT: # %bb.3:
-; CHECK-NEXT: lui a0, %hi(.LBB1_2)
-; CHECK-NEXT: jalr zero, %lo(.LBB1_2)(a0)
+; CHECK-NEXT: jump .LBB1_2, a0
; CHECK-NEXT: .LBB1_1: # %iftrue
; CHECK-NEXT: #APP
; CHECK-NEXT: #NO_APP
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -384,10 +384,6 @@
MachineFunction *MF = MBB.getParent();
MachineRegisterInfo &MRI = MF->getRegInfo();
- const auto &TM = static_cast<const RISCVTargetMachine &>(MF->getTarget());
-
- if (TM.isPositionIndependent())
- report_fatal_error("Unable to insert indirect branch");
if (!isInt<32>(BrOffset))
report_fatal_error(
@@ -399,15 +395,13 @@
Register ScratchReg = MRI.createVirtualRegister(&RISCV::GPRRegClass);
auto II = MBB.end();
- MachineInstr &LuiMI = *BuildMI(MBB, II, DL, get(RISCV::LUI), ScratchReg)
- .addMBB(&DestBB, RISCVII::MO_HI);
- BuildMI(MBB, II, DL, get(RISCV::PseudoBRIND))
- .addReg(ScratchReg, RegState::Kill)
- .addMBB(&DestBB, RISCVII::MO_LO);
+ MachineInstr &MI = *BuildMI(MBB, II, DL, get(RISCV::PseudoJump))
+ .addReg(ScratchReg, RegState::Define | RegState::Dead)
+ .addMBB(&DestBB);
RS->enterBasicBlockEnd(MBB);
unsigned Scav = RS->scavengeRegisterBackwards(RISCV::GPRRegClass,
- LuiMI.getIterator(), false, 0);
+ MI.getIterator(), false, 0);
MRI.replaceRegWith(ScratchReg, Scav);
MRI.clearVirtRegs();
RS->setRegUsed(Scav);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84833.281597.patch
Type: text/x-patch
Size: 2590 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200729/5c24cdd6/attachment.bin>
More information about the llvm-commits
mailing list