[llvm] [AArch64] Use GISel for optnone functions (PR #174746)

Ryan Cowan via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 17 02:22:27 PST 2026


================
@@ -387,12 +387,19 @@ AArch64TargetMachine::AArch64TargetMachine(const Target &T, const Triple &TT,
     // for the tiny code model, the maximum TLS size is 1MiB (< 16MiB)
     this->Options.TLSSize = 24;
 
-  // Enable GlobalISel at or below EnableGlobalISelAt0, unless this is
-  // MachO/CodeModel::Large, which GlobalISel does not support.
-  if (static_cast<int>(getOptLevel()) <= EnableGlobalISelAtO &&
+  const bool TargetSupportsGISel =
       TT.getArch() != Triple::aarch64_32 &&
       TT.getEnvironment() != Triple::GNUILP32 &&
-      !(getCodeModel() == CodeModel::Large && TT.isOSBinFormatMachO())) {
+      !(getCodeModel() == CodeModel::Large && TT.isOSBinFormatMachO());
+
+  const bool GlobalISelFlag =
+      getCGPassBuilderOption().EnableGlobalISelOption.value_or(false);
+
+  // Enable GlobalISel at or below EnableGlobalISelAt0, unless this is
+  // MachO/CodeModel::Large, which GlobalISel does not support.
+  if (TargetSupportsGISel &&
+      (static_cast<int>(getOptLevel()) <= EnableGlobalISelAtO ||
+       (!GlobalISelFlag && !Options.EnableGlobalISel))) {
----------------
HolyMolyCowMan wrote:

> I'm not questioning that, but using globalisel when it's explicitly disabled seems dubious?

I completely agree. There is a tricky interplay between TargetPassConfig & the Target Machine here.

TargetPassConfig first does the following:
```
  else if (EnableGlobalISelOption == cl::BOU_TRUE ||
           (TM->Options.EnableGlobalISel &&
            EnableGlobalISelOption != cl::BOU_FALSE))
    Selector = SelectorType::GlobalISel;
```

and then:

```
} else if (Selector == SelectorType::GlobalISel) {
    TM->setFastISel(false);
    TM->setGlobalISel(true);
  }
```

this means that by the time the AArch64TargetMachine section is run, Options.EnableGlobalISel should have been set correctly. I think this is where the error is, I forgot about FastISel, so I assumed that if there was no CLI flag and GlobalISel wasn't enabled, we must have been using SDAG. In which case we should enable GlobalISel to include it in the pipeline.

There should probably be a check there that EnableGlobalISelAtO is not -1 & possibly a check for fastisel too?

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


More information about the llvm-commits mailing list