[PATCH] [RFC][PATCH] Minor opt to access pointers to globals via pcrel GOT entries

Rafael Ávila de Espíndola rafael.espindola at gmail.com
Tue Feb 3 14:48:10 PST 2015


================
Comment at: include/llvm/Target/TargetLoweringObjectFile.h:166
@@ +165,3 @@
+  virtual const MCExpr *
+    getIndirectSymViaGOTPCRel(const MCSymbol *Sym) const {
+    return nullptr;
----------------
Indentation looks funny. Please clang-format before commit.

================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:340
@@ -338,1 +339,3 @@
 
+    // Skip the emission of global proxies.
+    if (GlobalGOTEquivs.count(getSymbol(GV)))
----------------
Say that emitGlobalGOTEquivs will emit them if needed.

================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:918
@@ +917,3 @@
+  if (!GV->hasUnnamedAddr() || !GV->hasInitializer() || !GV->isConstant() ||
+      !GV->isDiscardableIfUnused() || !GV->getType()->isPointerTy() ||
+      !dyn_cast<GlobalValue>(GV->getOperand(0)))
----------------
All global Variables have pointer type.

================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:919
@@ +918,3 @@
+      !GV->isDiscardableIfUnused() || !GV->getType()->isPointerTy() ||
+      !dyn_cast<GlobalValue>(GV->getOperand(0)))
+    return false;
----------------
s/dyn_cast/isa/


================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:932
@@ +931,3 @@
+// globals variable act like a global variable "proxy", or GOT equivalents,
+// i.e., it's only used to hold the address of the latter. One (very) minor
+// optimization is to replace accesses to these proxies by using the GOT entry
----------------
not sure there is a point is saying it is "(very) minor" :-)

================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:937
@@ +936,3 @@
+// finally replace references to them by pc relative accesses to GOT entries.
+void AsmPrinter::computeGlobalGOTEquivs(Module &M) {
+  if (!getObjFileLowering().supportIndirectSymViaGOTPCRel())
----------------
High level question: Do we need to do the early pass over all variables?

Couldn't emitGlobalConstantImpl do the check and add "got equivalent candidates"?

================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:2081
@@ +2080,3 @@
+  int64_t BaseSymOff = -Offset;
+  if (BaseSym != &MV.getSymB()->getSymbol() || MV.getConstant() != BaseSymOff)
+    return;
----------------
I am not sure I understand why the  MV.getConstant() != BaseSymOff restriction is necessary.

If we have
-------------------------
.globl  _proxy
_proxy:
 .quad   _foo

 .globl  _delta
_delta:
 .long   _proxy-_delta + 42
------------------------------------

It can be converted to
-----------------------------
.globl  _delta
_delta:
 .long   _foo at GOTPCREL + 42
----------------------------

no? It works on ELF at least.




================
Comment at: test/MC/X86/cstexpr-gotpcrel.ll:1
@@ +1,2 @@
+; RUN: llc -mtriple=x86_64-apple-darwin %s -o - | FileCheck %s
+
----------------
It would be nice to add code coverage on the cases where the optimization fails (use in instructions for example).

http://reviews.llvm.org/D6922

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list