[PATCH] D19040: Remove unnecessary load via GOT when accessing globals with PIE in x86_64
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 12 16:24:43 PDT 2016
rnk added a comment.
This needs a new LLVM IR lit test. Take what you have in the comments and add `-S -emit-llvm` to the clang command line, and you'll have the beginning of one. You should probably test stores, loads, and taking the address of such a global. You should probably also exhaustively test the linkage types. The non-ODR linkage types in particular probably can't use this optimization.
================
Comment at: lib/Target/X86/X86Subtarget.cpp:91
@@ +90,3 @@
+ bool isPIEDefinition =
+ GV->hasExactDefinition() && TM.Options.PositionIndependentExecutable;
+
----------------
You don't want `hasExactDefinition`, it will be false for linkonce_odr and weak_odr globals, which can benefit from this more efficient access. I think you want something equivalent to this condition:
TM.Options.PositionIndependentExecutable && !GV->isDeclaration() && !GV->mayBeOverridden()
http://reviews.llvm.org/D19040
More information about the llvm-commits
mailing list