[llvm] r273704 - Use shouldAssumeDSOLocal in isOffsetFoldingLegal.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 24 11:48:37 PDT 2016


Author: rafael
Date: Fri Jun 24 13:48:36 2016
New Revision: 273704

URL: http://llvm.org/viewvc/llvm-project?rev=273704&view=rev
Log:
Use shouldAssumeDSOLocal in isOffsetFoldingLegal.

This makes it slightly more powerful for dynamic-no-pic.

Added:
    llvm/trunk/test/CodeGen/X86/ga-offset2.ll
Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=273704&r1=273703&r2=273704&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp Fri Jun 24 13:48:36 2016
@@ -311,17 +311,22 @@ TargetLowering::getPICJumpTableRelocBase
 
 bool
 TargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
-  // Assume that everything is safe in static mode.
-  if (getTargetMachine().getRelocationModel() == Reloc::Static)
-    return true;
+  const TargetMachine &TM = getTargetMachine();
+  Reloc::Model RM = TM.getRelocationModel();
+  const GlobalValue *GV = GA->getGlobal();
+  const Triple &TargetTriple = TM.getTargetTriple();
 
-  // In dynamic-no-pic mode, assume that known defined values are safe.
-  if (getTargetMachine().getRelocationModel() == Reloc::DynamicNoPIC &&
-      GA && GA->getGlobal()->isStrongDefinitionForLinker())
-    return true;
+  // If the address is not even local to this DSO we will have to load it from
+  // a got and then add the offset.
+  if (!shouldAssumeDSOLocal(RM, TargetTriple, *GV->getParent(), GV))
+    return false;
 
-  // Otherwise assume nothing is safe.
-  return false;
+  // If the code is position independent we will have to add a base register.
+  if (RM == Reloc::PIC_)
+    return false;
+
+  // Otherwise we can do it.
+  return true;
 }
 
 //===----------------------------------------------------------------------===//

Added: llvm/trunk/test/CodeGen/X86/ga-offset2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/ga-offset2.ll?rev=273704&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/ga-offset2.ll (added)
+++ llvm/trunk/test/CodeGen/X86/ga-offset2.ll Fri Jun 24 13:48:36 2016
@@ -0,0 +1,10 @@
+; RUN: llc < %s -mtriple=i686-apple-darwin -relocation-model=dynamic-no-pic | FileCheck %s
+
+ at var = external hidden global i32
+ at p = external hidden global i32*
+
+define void @f() {
+; CHECK:  movl    $_var+40, _p
+  store i32* getelementptr (i32, i32* @var, i64 10), i32** @p
+  ret void
+}




More information about the llvm-commits mailing list