<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/211135>211135</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [openmp][cmake] openmp/module GPU-triple regex misses amdgpu-amd-amdhsa, silently dropping -nogpulib -flto
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          sbryngelson
      </td>
    </tr>
</table>

<pre>
    `openmp/module/CMakeLists.txt:29` gates the GPU-only Fortran compile options on

```cmake
if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx")
 target_compile_options(libomp-mod PRIVATE
 $<$<COMPILE_LANGUAGE:Fortran>:-nogpulib -flto>)
endif ()
```

while `openmp/CMakeLists.txt:176-177`, which selects host-vs-device layout for the same build, tests `"^amdgpu|^amdgcn|^nvptx|^spirv64"` against both `LLVM_DEFAULT_TARGET_TRIPLE` and `CMAKE_CXX_COMPILER_TARGET`.

All four offload cache files (`offload/cmake/caches/{Offload,FlangOffload,AMDGPUBot,AMDGPULibcBot}.cmake`) use the triple `amdgpu-amd-amdhsa`, which `^amdgcn` does not match. So in the configurations upstream itself recommends for AMDGPU offload, `-nogpulib -flto` are silently not applied to `libomp-mod`.

`amdgcn` is the legacy arch spelling but `Triple::normalize` preserves it (`clang --target=amdgcn-amd-amdhsa -print-target-triple` returns `amdgcn-amd-amdhsa`), so both spellings genuinely reach CMake and the existing `^amdgcn` clause is not dead code. Only `amdgpu-amd-amdhsa` is missed.

PR attached. It computes the test once in `openmp/CMakeLists.txt` and uses it at both sites, rather than duplicating a widened regex. Two reasons: the conditions differ, not just the patterns, so copying the regex alone leaves a build that sets `CMAKE_CXX_COMPILER_TARGET` without `LLVM_DEFAULT_TARGET_TRIPLE` still taking the device path in `openmp/` while `libomp-mod` misses the flags; and `libomp-mod` compiles Fortran, so `CMAKE_Fortran_COMPILER_TARGET` is the variable that actually matters and neither site consults it today.

Roughly five other sites have the same `amdgcn`-only pattern and are left for a follow-up: `offload/CMakeLists.txt:30`, `flang-rt/CMakeLists.txt:126`, `flang-rt/lib/runtime/CMakeLists.txt:317`, `flang-rt/cmake/modules/AddFlangRT.cmake:298`, `cmake/Modules/GetToolchainDirs.cmake:118`. The last governs the `finclude/flang/<triple>/` module path.

This affects performance-critical applications on large AMD GPU supercomputers, including [MFC](https://github.com/MFlowCode/MFC).

All numbers above come from the validated reproducers included with this report and are independently reproducible; they stand on their own.

This was found and root-caused with the assistance of AI tools.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8Vl1v4zoO_TXKC5HAsRuneciDm49use1O0Zu5uG-FbNG2ZmTJkORksr9-QclJO51ugcw0jimKPDw8JHdONhpxzRZ3bLGd8MG3xq5dac-6QeWMnpRGnNcsT0yPuutZuu-MGBSydL954j_xUTrvZv6XZ1mRrlieQMM9OvAtwv3z96nR6gx7Y73lGirT9VIhmN5Lox0YzZKCPnkSP1XHfyJLClkDS29ZmrL0hi3vHh__fnrd7vbF98fD66F4ud8dXg8vD8-PO7bcsjSFp-Kw-dfuL6ATix3vRFNpttywxU4fe_8rOFqxpADPbYP-dQzkdQyEpbdKlqbrp50R8Pzy8Hdx2JE5XZ9t4v-bb0_PD4-718fiP_ffi_sdy4oxL5bRw1Sbph-ULGFaK2_ox3AnanFJZ_U-15j6qSVA3uP7B6zzZT6dL5d0JN3AqZVVCw4VVt5Ba5yfHt1U4FFWCIqfzeChNjYUwPEOoRykEnTSo_MOgpsLSv0QUfoTsfDV9dIe8xuyzxPgDZfaeSiNb8nNF1Uhay3IaPNU_Hv3uvnnn9cRv5fRlOXJLEJQKAW1GSyYulaGC6h41SLUUqELuOXJ-Ial-8iQdB9sHEv3bHn37fJ2s1dcN2-PxdP2_vn7nfHX74-yrOh5uZ1FT4TGCgaHATBvZR_LEdGZ8k7Qv9bx3-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