This is an archive of the discontinued LLVM Phabricator instance.

[X86] Use RIP-relative addressing for data under large data threshold for medium code model
ClosedPublic

Authored by aeubanks on May 10 2023, 1:23 PM.

Details

Summary

Since those data are assumed to be within the relocation offset limit.

Diff Detail

Event Timeline

aeubanks created this revision.May 10 2023, 1:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2023, 1:23 PM
aeubanks requested review of this revision.May 10 2023, 1:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2023, 1:23 PM
jyknight added inline comments.May 15 2023, 10:21 AM
llvm/lib/Target/X86/X86ISelLowering.cpp
20828 ↗(On Diff #521088)

This function is getting kinda complex. And given we already have classifyLocalReference/classifyGlobalReference and friends, why does this function even need to look at GV and the CodeModel at all? That kinda feels wrong...Shouldn't it be entirely based on the OpFlags?

That is, I'm kinda wondering why this function isn't, in its entirety just

if (Subtarget.isPICStyleRIPRel() && OpFlags == X86II::MO_NO_FLAG)
  return X86ISD::WrapperRIP;

if (OpFlags == X86II::MO_GOTPCREL || OpFlags == X86II::MO_GOTPCREL_NORELAX)
  return X86ISD::WrapperRIP;

return X86ISD::Wrapper;

Or do we actually emit references that are neither GOT nor pc-relative in PIC mode in some circumstances? (Which would, then, imply text relocations...which seems wrong...)

aeubanks updated this revision to Diff 525712.May 25 2023, 11:26 AM

clean up X86TargetLowering::getGlobalWrapperKind

rnk added inline comments.Jun 1 2023, 2:56 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
20937–20939 ↗(On Diff #527559)

I guess James suggested that we avoid looking at GV, which is how we knew we could do the rip-rel LEA previously.

llvm/test/CodeGen/X86/code-model-elf.ll
401

I think the old sequence is better, if we can get it. GCC does something weird:
https://gcc.godbolt.org/z/xPT49jqrT

I think they assume the program is in the low 4GB of the address space if compiled without PIC.

444

This seems undesirable. We should know that because global_fn is code, it is within 2GB of the current PC, so we can use the RIP, which has a smaller encoding (32-bit vs 64-bit).

598

Oh god, the large code model is so inefficient! Even the GOT offsets are potentially 64-bit. O_O

aeubanks updated this revision to Diff 556815.Sep 14 2023, 3:12 PM

rebase, should address remaining comments

rnk accepted this revision.Sep 15 2023, 1:27 PM

lgtm

This revision is now accepted and ready to land.Sep 15 2023, 1:27 PM