[llvm] r345731 - [Hexagon] Make sure not to use GP-relative addressing with PIC

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 31 08:54:31 PDT 2018


Author: kparzysz
Date: Wed Oct 31 08:54:31 2018
New Revision: 345731

URL: http://llvm.org/viewvc/llvm-project?rev=345731&view=rev
Log:
[Hexagon] Make sure not to use GP-relative addressing with PIC

Make sure that -relocation-model=pic prevents use of GP-relative
addressing modes.

Added:
    llvm/trunk/test/CodeGen/Hexagon/pic-sdata.ll
Modified:
    llvm/trunk/lib/Target/Hexagon/HexagonSplitConst32AndConst64.cpp
    llvm/trunk/lib/Target/Hexagon/HexagonTargetObjectFile.cpp
    llvm/trunk/lib/Target/Hexagon/HexagonTargetObjectFile.h

Modified: llvm/trunk/lib/Target/Hexagon/HexagonSplitConst32AndConst64.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonSplitConst32AndConst64.cpp?rev=345731&r1=345730&r2=345731&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonSplitConst32AndConst64.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonSplitConst32AndConst64.cpp Wed Oct 31 08:54:31 2018
@@ -63,7 +63,7 @@ bool HexagonSplitConst32AndConst64::runO
   auto &HST = Fn.getSubtarget<HexagonSubtarget>();
   auto &HTM = static_cast<const HexagonTargetMachine&>(Fn.getTarget());
   auto &TLOF = *HTM.getObjFileLowering();
-  if (HST.useSmallData() && TLOF.isSmallDataEnabled())
+  if (HST.useSmallData() && TLOF.isSmallDataEnabled(HTM))
     return false;
 
   const TargetInstrInfo *TII = HST.getInstrInfo();

Modified: llvm/trunk/lib/Target/Hexagon/HexagonTargetObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonTargetObjectFile.cpp?rev=345731&r1=345730&r2=345731&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonTargetObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonTargetObjectFile.cpp Wed Oct 31 08:54:31 2018
@@ -199,6 +199,11 @@ MCSection *HexagonTargetObjectFile::getE
 /// section.
 bool HexagonTargetObjectFile::isGlobalInSmallSection(const GlobalObject *GO,
       const TargetMachine &TM) const {
+  if (!isSmallDataEnabled(TM)) {
+    LLVM_DEBUG(dbgs() << "Small data is not available.\n");
+    return false;
+  }
+
   // Only global variables, not functions.
   LLVM_DEBUG(dbgs() << "Checking if value is in small-data, -G"
                     << SmallDataThreshold << ": \"" << GO->getName() << "\": ");
@@ -263,8 +268,9 @@ bool HexagonTargetObjectFile::isGlobalIn
   return true;
 }
 
-bool HexagonTargetObjectFile::isSmallDataEnabled() const {
-  return SmallDataThreshold > 0;
+bool HexagonTargetObjectFile::isSmallDataEnabled(const TargetMachine &TM)
+    const {
+  return SmallDataThreshold > 0 && !TM.isPositionIndependent();
 }
 
 unsigned HexagonTargetObjectFile::getSmallDataSize() const {

Modified: llvm/trunk/lib/Target/Hexagon/HexagonTargetObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonTargetObjectFile.h?rev=345731&r1=345730&r2=345731&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonTargetObjectFile.h (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonTargetObjectFile.h Wed Oct 31 08:54:31 2018
@@ -29,7 +29,7 @@ namespace llvm {
     bool isGlobalInSmallSection(const GlobalObject *GO,
                                 const TargetMachine &TM) const;
 
-    bool isSmallDataEnabled() const;
+    bool isSmallDataEnabled(const TargetMachine &TM) const;
 
     unsigned getSmallDataSize() const;
 

Added: llvm/trunk/test/CodeGen/Hexagon/pic-sdata.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Hexagon/pic-sdata.ll?rev=345731&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Hexagon/pic-sdata.ll (added)
+++ llvm/trunk/test/CodeGen/Hexagon/pic-sdata.ll Wed Oct 31 08:54:31 2018
@@ -0,0 +1,37 @@
+; RUN: llc -march=hexagon -hexagon-small-data-threshold=8 -relocation-model=static < %s | FileCheck --check-prefixes=CHECK,STATIC %s
+; RUN: llc -march=hexagon -hexagon-small-data-threshold=8 -relocation-model=pic < %s | FileCheck --check-prefixes=CHECK,PIC %s
+
+; If a global has a specified section, it should probably be placed in that
+; section, but with PIC any accesses to globals in small data should still
+; go through GOT.
+
+ at g0 = global i32 zeroinitializer
+ at g1 = global i32 zeroinitializer, section ".sdata"
+
+; CHECK-LABEL: f0:
+; STATIC: memw(gp+#g0)
+; PIC: r[[R0:[0-9]+]] = add(pc,##_GLOBAL_OFFSET_TABLE_ at PCREL)
+; PIC: = memw(r[[R0]]+##g0 at GOT)
+define i32 @f0() #0 {
+  %v0 = load i32, i32* @g0
+  ret i32 %v0
+}
+
+; CHECK-LABEL: f1:
+; STATIC: memw(gp+#g1)
+; PIC: r[[R1:[0-9]+]] = add(pc,##_GLOBAL_OFFSET_TABLE_ at PCREL)
+; PIC: = memw(r[[R1]]+##g1 at GOT)
+define i32 @f1() #0 {
+  %v0 = load i32, i32* @g1
+  ret i32 %v0
+}
+
+; CHECK-LABEL: f2:
+; STATIC: CONST64(#123456789012345678)
+; PIC: r0 = ##-1506741426
+; PIC: r1 = ##28744523
+define i64 @f2() #0 {
+  ret i64 123456789012345678
+}
+
+attributes #0 = { nounwind "target-cpu"="hexagonv60" }




More information about the llvm-commits mailing list