Skip to content

Commit 71de783

Browse files
jaidTwyetingk
andauthored
[RISCV] Inserting indirect jumps with X7 for Zicfilp (#170683)
`BranchRelxation` uses `RISCVInstrInfo::insertIndirectBranch` to insert an indirect branch if the jump target is out of range. Currently it uses register scavenging to find a free register to use for the indirect target. If Zicfilp is enabled, we need to use X7 so that the jump will be treated as a software guarded branch. Co-authored-by: Yeting Kuo <46629943+yetingk@users.noreply.github.com>
1 parent d8ad3c1 commit 71de783

File tree

3 files changed

+1589
-8
lines changed

3 files changed

+1589
-8
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,8 +1372,11 @@ void RISCVInstrInfo::insertIndirectBranch(MachineBasicBlock &MBB,
13721372
.addMBB(&DestBB, RISCVII::MO_CALL);
13731373

13741374
RS->enterBasicBlockEnd(MBB);
1375+
const TargetRegisterClass *RC = &RISCV::GPRRegClass;
1376+
if (STI.hasStdExtZicfilp())
1377+
RC = &RISCV::GPRX7RegClass;
13751378
Register TmpGPR =
1376-
RS->scavengeRegisterBackwards(RISCV::GPRRegClass, MI.getIterator(),
1379+
RS->scavengeRegisterBackwards(*RC, MI.getIterator(),
13771380
/*RestoreAfter=*/false, /*SpAdj=*/0,
13781381
/*AllowSpill=*/false);
13791382
if (TmpGPR.isValid())
@@ -1383,6 +1386,9 @@ void RISCVInstrInfo::insertIndirectBranch(MachineBasicBlock &MBB,
13831386

13841387
// Pick s11(or s1 for rve) because it doesn't make a difference.
13851388
TmpGPR = STI.hasStdExtE() ? RISCV::X9 : RISCV::X27;
1389+
// Force t2 if Zicfilp is on
1390+
if (STI.hasStdExtZicfilp())
1391+
TmpGPR = RISCV::X7;
13861392

13871393
int FrameIndex = RVFI->getBranchRelaxationScratchFrameIndex();
13881394
if (FrameIndex == -1)

0 commit comments

Comments
 (0)