[Openmp-commits] [openmp] [OpenMP] Avoid using CPU-specific flags on GPU (PR #159053)

Tulio Magno Quites Machado Filho via Openmp-commits openmp-commits at lists.llvm.org
Tue Sep 16 05:10:16 PDT 2025


https://github.com/tuliom created https://github.com/llvm/llvm-project/pull/159053

Since commit be6f110bc08fd5fb622485b50e30619936acc124 we lost a few workarounds that prevented CPU-specific flags to leak from CXXFLAGS to a binary targetting GPUs causing errors and/or warnings.

Re-add those workarounds and expand them with -mtune, -mbranch-protection and -fcf-protection.

>From ba4bb1fbd4e876a60a5b34770d720bfc6331cd89 Mon Sep 17 00:00:00 2001
From: Tulio Magno Quites Machado Filho <tuliom at redhat.com>
Date: Mon, 15 Sep 2025 17:10:23 -0300
Subject: [PATCH] [OpenMP] Avoid using CPU-specific flags for GPU

Since commit be6f110bc08fd5fb622485b50e30619936acc124 we lost a few
workarounds that prevented CPU-specific flags to leak from CXXFLAGS to a
binary targetting GPUs causing errors and/or warnings.

Re-add those workarounds and expand them with -mtune,
-mbranch-protection and -fcf-protection.
---
 openmp/device/CMakeLists.txt | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/openmp/device/CMakeLists.txt b/openmp/device/CMakeLists.txt
index ded961adcce1f..76e05d5cb3cb0 100644
--- a/openmp/device/CMakeLists.txt
+++ b/openmp/device/CMakeLists.txt
@@ -36,6 +36,13 @@ list(APPEND compile_options -Wno-unknown-cuda-version)
 if(LLVM_DEFAULT_TARGET_TRIPLE)
   list(APPEND compile_options --target=${LLVM_DEFAULT_TARGET_TRIPLE})
 endif()
+# Ensure that CPU-related parameters won't be brought in.
+string(REGEX REPLACE "-mcpu[^ \t\r\n]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+string(REGEX REPLACE "-march[^ \t\r\n]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+string(REGEX REPLACE "-mtune[^ \t\r\n]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+string(REGEX REPLACE "-mbranch-protection[^ \t\r\n]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+string(REGEX REPLACE "-fcf-protection[^ \t\r\n]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+list(APPEND compile_options -Wno-unused-command-line-argument)
 
 # We disable the slp vectorizer during the runtime optimization to avoid
 # vectorized accesses to the shared state. Generally, those are "good" but



More information about the Openmp-commits mailing list