[clang] [Clang][SYCL] Suggest the IGCA target for -Xarch_<Intel GPU> (PR #249094)
Srividya Sundaram via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 4 16:04:23 PST 2026
https://github.com/srividya-sundaram updated https://github.com/llvm/llvm-project/pull/249094
>From 45631f047811d94311643fdfebfe45678045173e Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Fri, 4 Dec 2026 14:25:22 -0800
Subject: [PATCH 1/2] [Clang][SYCL] Suggest the IGCA target for -Xarch_<Intel
GPU>
-Xarch_ matches the device compile, which is named after the IGCA target, so
-Xarch_<Intel GPU> never applies. Warn with the IGCA target to use instead of
only reporting the argument as unused.
---
clang/docs/ReleaseNotes.md | 4 ++++
.../include/clang/Basic/DiagnosticDriverKinds.td | 4 ++++
clang/lib/Driver/Driver.cpp | 16 ++++++++++++++++
clang/test/Driver/sycl-intel-gpu-arch.cpp | 10 +++++++++-
4 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index a08b457ffcf518..e89fc5d0840c6b 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -2010,6 +2010,10 @@ The `alpha.cplusplus.UseAfterLifetimeEnd` checker was renamed to `alpha.core.Use
#### Improvements
+- `-Xarch_<Intel GPU>` now warns with the IGCA target to use instead, e.g.
+ `-Xarch_igca_40r` for `-Xarch_xe-bmg-g21`, since the device compile for an
+ Intel GPU is named after its IGCA target.
+
### Clang IR Improvements
- Clang builds now build ClangIR support by default. Clang IR is expected to work with most Linux/X86-64 workloads. Normal builds are unchanged, however those who wish to test out the experimental `-fclangir` flag can now do so with a Clang build.
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index c7966b295a0b0b..f8df3db57e720b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -506,6 +506,10 @@ def warn_drv_preprocessed_input_file_unused : Warning<
def warn_drv_unused_argument : Warning<
"argument unused during compilation: '%0'">,
InGroup<UnusedCommandLineArgument>;
+def warn_drv_xarch_intel_gpu : Warning<
+ "'-Xarch_%0' names an Intel GPU, which is compiled for its IGCA target "
+ "'%1'; use '-Xarch_%1' instead">,
+ InGroup<UnusedCommandLineArgument>;
def warn_drv_unused_x : Warning<
"'-x %0' after last input file has no effect">,
InGroup<UnusedCommandLineArgument>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5857b84c875fe0..1987e576ebbe01 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4183,6 +4183,22 @@ Driver::getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
C.addIGCADevice(&TC, Target, Arch);
}
Archs = std::move(Targets);
+
+ // -Xarch_ matches the device compile, which is named after the IGCA
+ // target, so -Xarch_<Intel GPU> never applies. If that IGCA target is
+ // compiled, suggest it instead of the plain "unused" warning. Claiming the
+ // argument makes the warning appear once, as this runs for each device
+ // toolchain.
+ for (Arg *A : Args.filtered(options::OPT_Xarch__)) {
+ OffloadArch XArch = StringToOffloadArch(A->getValue(0));
+ if (A->isClaimed() || !XArch.isIntelGPU())
+ continue;
+ StringRef Target = OffloadArchToVirtualArchString(XArch);
+ if (!Archs.contains(Target))
+ continue;
+ A->claim();
+ Diag(diag::warn_drv_xarch_intel_gpu) << A->getValue(0) << Target;
+ }
}
SmallVector<StringRef> Sorted(Archs.begin(), Archs.end());
diff --git a/clang/test/Driver/sycl-intel-gpu-arch.cpp b/clang/test/Driver/sycl-intel-gpu-arch.cpp
index 768a96f907fc97..93b805e99b651a 100644
--- a/clang/test/Driver/sycl-intel-gpu-arch.cpp
+++ b/clang/test/Driver/sycl-intel-gpu-arch.cpp
@@ -50,11 +50,19 @@
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl \
// RUN: --offload-arch=xe-pvc -Xarch_igca_20ca -DFOO -Xarch_xe-pvc -DBAR \
// RUN: -c %s 2>&1 | FileCheck -check-prefixes=CHK-XARCH %s
-// CHK-XARCH: warning: argument unused during compilation: '-Xarch_xe-pvc -DBAR'
+// CHK-XARCH: warning: '-Xarch_xe-pvc' names an Intel GPU, which is compiled for its IGCA target 'igca_20ca'; use '-Xarch_igca_20ca' instead
+// CHK-XARCH-NOT: argument unused during compilation
// CHK-XARCH-NOT: "-D" "BAR"
// CHK-XARCH: "-cc1" "-triple" "spirv64-unknown-unknown"{{.*}} "-D" "FOO"
// CHK-XARCH-NOT: "-D" "BAR"
+/// If the Intel GPU's IGCA target isn't compiled, there is nothing to suggest,
+/// so the argument is reported as unused.
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl \
+// RUN: --offload-arch=xe-mtl-u -Xarch_xe-pvc -DBAR -c %s 2>&1 \
+// RUN: | FileCheck -check-prefixes=CHK-XARCH-OTHER %s
+// CHK-XARCH-OTHER: warning: argument unused during compilation: '-Xarch_xe-pvc -DBAR'
+
/// Static libraries are searched for the IGCA target of an Intel GPU, once for
/// Intel GPUs that share it.
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl \
>From 170f18a737fba3f51c1522d610d4a016aca4c665 Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Fri, 4 Dec 2026 16:04:12 -0800
Subject: [PATCH 2/2] [Clang][SYCL] Address self review: clearer warning, read
the value once
---
clang/include/clang/Basic/DiagnosticDriverKinds.td | 4 ++--
clang/lib/Driver/Driver.cpp | 5 +++--
clang/test/Driver/sycl-intel-gpu-arch.cpp | 2 +-
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index f8df3db57e720b..80f54a4c020b44 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -507,8 +507,8 @@ def warn_drv_unused_argument : Warning<
"argument unused during compilation: '%0'">,
InGroup<UnusedCommandLineArgument>;
def warn_drv_xarch_intel_gpu : Warning<
- "'-Xarch_%0' names an Intel GPU, which is compiled for its IGCA target "
- "'%1'; use '-Xarch_%1' instead">,
+ "'-Xarch_%0' names an Intel GPU, but its device code is compiled for IGCA "
+ "target '%1'; use '-Xarch_%1' instead">,
InGroup<UnusedCommandLineArgument>;
def warn_drv_unused_x : Warning<
"'-x %0' after last input file has no effect">,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1987e576ebbe01..a9892b9c09a431 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4190,14 +4190,15 @@ Driver::getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
// argument makes the warning appear once, as this runs for each device
// toolchain.
for (Arg *A : Args.filtered(options::OPT_Xarch__)) {
- OffloadArch XArch = StringToOffloadArch(A->getValue(0));
+ StringRef XArchName = A->getValue(0);
+ OffloadArch XArch = StringToOffloadArch(XArchName);
if (A->isClaimed() || !XArch.isIntelGPU())
continue;
StringRef Target = OffloadArchToVirtualArchString(XArch);
if (!Archs.contains(Target))
continue;
A->claim();
- Diag(diag::warn_drv_xarch_intel_gpu) << A->getValue(0) << Target;
+ Diag(diag::warn_drv_xarch_intel_gpu) << XArchName << Target;
}
}
diff --git a/clang/test/Driver/sycl-intel-gpu-arch.cpp b/clang/test/Driver/sycl-intel-gpu-arch.cpp
index 93b805e99b651a..acd2eb0811faa0 100644
--- a/clang/test/Driver/sycl-intel-gpu-arch.cpp
+++ b/clang/test/Driver/sycl-intel-gpu-arch.cpp
@@ -50,7 +50,7 @@
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl \
// RUN: --offload-arch=xe-pvc -Xarch_igca_20ca -DFOO -Xarch_xe-pvc -DBAR \
// RUN: -c %s 2>&1 | FileCheck -check-prefixes=CHK-XARCH %s
-// CHK-XARCH: warning: '-Xarch_xe-pvc' names an Intel GPU, which is compiled for its IGCA target 'igca_20ca'; use '-Xarch_igca_20ca' instead
+// CHK-XARCH: warning: '-Xarch_xe-pvc' names an Intel GPU, but its device code is compiled for IGCA target 'igca_20ca'; use '-Xarch_igca_20ca' instead
// CHK-XARCH-NOT: argument unused during compilation
// CHK-XARCH-NOT: "-D" "BAR"
// CHK-XARCH: "-cc1" "-triple" "spirv64-unknown-unknown"{{.*}} "-D" "FOO"
More information about the cfe-commits
mailing list