Skip to content

[RISCV,GISel] Unconditionally use MO_PLT for calls #72355

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
Nov 15, 2023
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
20 changes: 2 additions & 18 deletions llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,24 +496,8 @@ bool RISCVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
// TODO: Support tail calls.
Info.IsTailCall = false;

// If the callee is a GlobalAddress or ExternalSymbol and cannot be assumed as
// DSOLocal, then use MO_PLT. Otherwise use MO_CALL.
if (Info.Callee.isGlobal()) {
const GlobalValue *GV = Info.Callee.getGlobal();
unsigned OpFlags = RISCVII::MO_CALL;
if (!getTLI()->getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(),
GV))
OpFlags = RISCVII::MO_PLT;

Info.Callee.setTargetFlags(OpFlags);
} else if (Info.Callee.isSymbol()) {
unsigned OpFlags = RISCVII::MO_CALL;
if (!getTLI()->getTargetMachine().shouldAssumeDSOLocal(
*MF.getFunction().getParent(), nullptr))
OpFlags = RISCVII::MO_PLT;

Info.Callee.setTargetFlags(OpFlags);
}
// Select the recommended relocation type R_RISCV_CALL_PLT.
Info.Callee.setTargetFlags(RISCVII::MO_PLT);

MachineInstrBuilder Call =
MIRBuilder
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/calls.ll
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,14 @@ define void @test_call_local() {
; RV32I-LABEL: name: test_call_local
; RV32I: bb.1.entry:
; RV32I-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def $x2, implicit $x2
; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @dso_local_function, csr_ilp32_lp64, implicit-def $x1
; RV32I-NEXT: PseudoCALL target-flags(riscv-plt) @dso_local_function, csr_ilp32_lp64, implicit-def $x1
; RV32I-NEXT: ADJCALLSTACKUP 0, 0, implicit-def $x2, implicit $x2
; RV32I-NEXT: PseudoRET
;
; RV64I-LABEL: name: test_call_local
; RV64I: bb.1.entry:
; RV64I-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def $x2, implicit $x2
; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @dso_local_function, csr_ilp32_lp64, implicit-def $x1
; RV64I-NEXT: PseudoCALL target-flags(riscv-plt) @dso_local_function, csr_ilp32_lp64, implicit-def $x1
; RV64I-NEXT: ADJCALLSTACKUP 0, 0, implicit-def $x2, implicit $x2
; RV64I-NEXT: PseudoRET
entry:
Expand Down