[Mlir-commits] [mlir] [mlir][XeGPU] Fix crash in getUArch for unsupported architectures (PR #179173)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Feb 1 22:52:50 PST 2026


https://github.com/mugiwaraluffy56 created https://github.com/llvm/llvm-project/pull/179173

## Summary
- Return nullptr from getUArch() instead of crashing with llvm_unreachable when the architecture name is not recognized
- Callers already check for nullptr and handle it gracefully (e.g., returning match failure)

Fixes #179167

## Test plan
- Added test case that runs xegpu subgroup distribute without a target attribute

>From ede29ecf716cc3e0fdc22e7585d432a43f307d1b Mon Sep 17 00:00:00 2001
From: puneeth_aditya_5656 <myakampuneeth at gmail.com>
Date: Mon, 2 Feb 2026 12:22:02 +0530
Subject: [PATCH] [mlir][XeGPU] Fix crash in getUArch for unsupported
 architectures

Return nullptr instead of calling llvm_unreachable when the architecture
name doesn't match any supported architecture. This allows callers to
gracefully handle the missing target case instead of crashing.

Fixes #179167
---
 .../include/mlir/Dialect/XeGPU/uArch/IntelGpuXe2.h |  5 +----
 .../XeGPU/subgroup-distribute-no-target.mlir       | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 4 deletions(-)
 create mode 100644 mlir/test/Dialect/XeGPU/subgroup-distribute-no-target.mlir

diff --git a/mlir/include/mlir/Dialect/XeGPU/uArch/IntelGpuXe2.h b/mlir/include/mlir/Dialect/XeGPU/uArch/IntelGpuXe2.h
index 29e75b57f4a5f..5a1fcb42b53ee 100644
--- a/mlir/include/mlir/Dialect/XeGPU/uArch/IntelGpuXe2.h
+++ b/mlir/include/mlir/Dialect/XeGPU/uArch/IntelGpuXe2.h
@@ -296,11 +296,8 @@ struct BMGuArch : public Xe2Plus {
 inline const uArch *getUArch(llvm::StringRef archName) {
   if (archName.equals_insensitive("pvc"))
     return PVCuArch::getInstance();
-  else if (archName.equals_insensitive("bmg"))
+  if (archName.equals_insensitive("bmg"))
     return BMGuArch::getInstance();
-  else
-    llvm_unreachable("No matching uArch found");
-
   return nullptr;
 }
 
diff --git a/mlir/test/Dialect/XeGPU/subgroup-distribute-no-target.mlir b/mlir/test/Dialect/XeGPU/subgroup-distribute-no-target.mlir
new file mode 100644
index 0000000000000..0df69a14d44f5
--- /dev/null
+++ b/mlir/test/Dialect/XeGPU/subgroup-distribute-no-target.mlir
@@ -0,0 +1,14 @@
+// RUN: mlir-opt -xegpu-subgroup-distribute -split-input-file %s 2>&1 | FileCheck %s
+
+// Test that the pass gracefully handles a GPU module without a target attribute
+// instead of crashing with "UNREACHABLE executed".
+
+// CHECK-LABEL: gpu.module @no_target_module
+// The function body should remain unchanged since no target is attached.
+// CHECK: gpu.func @simple_func
+// CHECK: gpu.return
+gpu.module @no_target_module {
+  gpu.func @simple_func(%arg0: memref<8x16xf16>) {
+    gpu.return
+  }
+}



More information about the Mlir-commits mailing list