[llvm] [X86] Don't respect large data threshold for globals with an explicit section (PR #78348)

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 13:55:34 PST 2024


================
@@ -83,8 +83,14 @@ bool TargetMachine::isLargeGlobalValue(const GlobalValue *GVal) const {
       return true;
   }
 
-  if (getCodeModel() == CodeModel::Medium ||
-      getCodeModel() == CodeModel::Large) {
+  // Respect large data threshold for medium and large code models.
+  // ... But only for globals without an explicit section. If multiple globals
+  // are placed in an explicit section, there's a good chance that the data
+  // threshold will cause the different globals to be inconsistent in whether
+  // they're large or small. Mixing large section flags can cause undesirable
+  // issues like increased relocation pressure.
+  if (!GV->hasSection() && (getCodeModel() == CodeModel::Medium ||
----------------
rnk wrote:

IMO we should handle this by returning false at the end of the `!Name.empty()` block above, where we mark certain known section names as large or not large, and expand on the comment ahead of that block. I think we can also eliminate the checks for `IsPrefix(".bss")` etc, since we are essentially going to return false for all sections other than .lbss/.lrodata/.ldata.

I would update the comment on that block to read something like:

Treat all globals in explicit sections as small, except for the standard large sections of .lbss, .ldata, .lrodata.
This reduces the risk of linking together small and large sections, resulting in small references to large data sections.
Users can mark globals with explicit sections as large using the code_model attribute.

https://github.com/llvm/llvm-project/pull/78348


More information about the llvm-commits mailing list