[llvm] r289832 - [lanai] Simplify small section check in LowerGlobalAddress and treat ldata sections specially.

Jacques Pienaar via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 15 08:56:17 PST 2016


Author: jpienaar
Date: Thu Dec 15 10:56:16 2016
New Revision: 289832

URL: http://llvm.org/viewvc/llvm-project?rev=289832&view=rev
Log:
[lanai] Simplify small section check in LowerGlobalAddress and treat ldata sections specially.

Move the check for the code model into isGlobalInSmallSectionImpl and return false (not in small section) for variables placed in sections prefixed with .ldata (workaround for a tool limitation).


Modified:
    llvm/trunk/lib/Target/Lanai/LanaiISelLowering.cpp
    llvm/trunk/lib/Target/Lanai/LanaiTargetObjectFile.cpp
    llvm/trunk/test/CodeGen/Lanai/codemodel.ll

Modified: llvm/trunk/lib/Target/Lanai/LanaiISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Lanai/LanaiISelLowering.cpp?rev=289832&r1=289831&r2=289832&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Lanai/LanaiISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/Lanai/LanaiISelLowering.cpp Thu Dec 15 10:56:16 2016
@@ -1170,8 +1170,7 @@ SDValue LanaiTargetLowering::LowerGlobal
   // If the code model is small or global variable will be placed in the small
   // section, then assume address will fit in 21-bits.
   const GlobalObject *GO = GV->getBaseObject();
-  if (getTargetMachine().getCodeModel() == CodeModel::Small ||
-      (GO && TLOF->isGlobalInSmallSection(GO, getTargetMachine()))) {
+  if (TLOF->isGlobalInSmallSection(GO, getTargetMachine())) {
     SDValue Small = DAG.getTargetGlobalAddress(
         GV, DL, getPointerTy(DAG.getDataLayout()), Offset, LanaiII::MO_NO_FLAG);
     return DAG.getNode(ISD::OR, DL, MVT::i32,

Modified: llvm/trunk/lib/Target/Lanai/LanaiTargetObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Lanai/LanaiTargetObjectFile.cpp?rev=289832&r1=289831&r2=289832&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Lanai/LanaiTargetObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/Lanai/LanaiTargetObjectFile.cpp Thu Dec 15 10:56:16 2016
@@ -50,6 +50,9 @@ static bool isInSmallSection(uint64_t Si
 // section.
 bool LanaiTargetObjectFile::isGlobalInSmallSection(
     const GlobalObject *GO, const TargetMachine &TM) const {
+  if (GO == nullptr)
+    return false;
+
   // We first check the case where global is a declaration, because finding
   // section kind using getKindForGlobal() is only allowed for global
   // definitions.
@@ -72,12 +75,21 @@ bool LanaiTargetObjectFile::isGlobalInSm
 // section. This method does all the work, except for checking the section
 // kind.
 bool LanaiTargetObjectFile::isGlobalInSmallSectionImpl(
-    const GlobalObject *GO, const TargetMachine & /*TM*/) const {
+    const GlobalObject *GO, const TargetMachine &TM) const {
   // Only global variables, not functions.
   const auto *GVA = dyn_cast<GlobalVariable>(GO);
   if (!GVA)
     return false;
 
+  // Global values placed in sections starting with .ldata do not fit in
+  // 21-bits, so always use large memory access for them. FIXME: This is a
+  // workaround for a tool limitation.
+  if (GVA->getSection().startswith(".ldata"))
+    return false;
+
+  if (TM.getCodeModel() == CodeModel::Small)
+    return true;
+
   if (GVA->hasLocalLinkage())
     return false;
 

Modified: llvm/trunk/test/CodeGen/Lanai/codemodel.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Lanai/codemodel.ll?rev=289832&r1=289831&r2=289832&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Lanai/codemodel.ll (original)
+++ llvm/trunk/test/CodeGen/Lanai/codemodel.ll Thu Dec 15 10:56:16 2016
@@ -28,3 +28,17 @@ entry:
 	ret i32 %0
 }
 
+ at y = local_unnamed_addr global i32* null, section ".ldata,block", align 8
+
+define i32 @foo2() nounwind readonly {
+entry:
+; CHECK-SMALL-LABEL:  foo2:
+; CHECK-SMALL: mov hi(y), %r[[REGISTER:[0-9]+]]
+; CHECK-SMALL: or %r[[REGISTER]], lo(y), %r[[REGISTER]]
+; CHECK-LABEL:  foo2:
+; CHECK: mov hi(y), %r[[REGISTER:[0-9]+]]
+; CHECK: or %r[[REGISTER]], lo(y), %r[[REGISTER]]
+  %0 = load i32*, i32** @y, align 8
+  %1 = load i32, i32* %0, align 4
+  ret i32 %1
+}




More information about the llvm-commits mailing list