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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Feb 6 23:15:54 PST 2026


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

>From d4ffb9e5a43f21e3a169e2b02343405055dff8a0 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
---
 .../mlir/Dialect/XeGPU/uArch/IntelGpuXe2.h    |  5 +--
 .../Transforms/XeGPUPeepHoleOptimizer.cpp     | 10 ++++--
 .../XeGPU/Transforms/XeGPUPropagateLayout.cpp | 36 +++++++++++++++++++
 .../XeGPU/subgroup-distribute-no-target.mlir  | 14 ++++++++
 4 files changed, 58 insertions(+), 7 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/lib/Dialect/XeGPU/Transforms/XeGPUPeepHoleOptimizer.cpp b/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPeepHoleOptimizer.cpp
index 6a3e533fb2df4..eec68706bff6f 100644
--- a/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPeepHoleOptimizer.cpp
+++ b/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPeepHoleOptimizer.cpp
@@ -246,10 +246,14 @@ class XeGPUCreateNdDescOpPattern final
     // Get the target uArch info.
     auto chipStr = xegpu::getChipStr(createNdOp);
     // Check if the chip is supported.
-    assert(
-        chipStr && (chipStr.value() == "pvc" || chipStr.value() == "bmg") &&
-        "Expecting target chip to be pvc or bmg for transpose optimization.");
+    if (!chipStr)
+      return rewriter.notifyMatchFailure(
+          createNdOp, "Missing target attribute for transpose optimization.");
     const uArch *targetuArch = xegpu::uArch::getUArch(chipStr.value());
+    if (!targetuArch)
+      return rewriter.notifyMatchFailure(
+          createNdOp, "Unsupported target chip for transpose optimization. "
+                      "Expecting pvc or bmg.");
 
     auto convertType = tryOptimize(tdescTy, targetuArch);
     if (convertType == tdescTy)
diff --git a/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPropagateLayout.cpp b/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPropagateLayout.cpp
index b46f6c7e751a1..0784383a14be6 100644
--- a/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPropagateLayout.cpp
+++ b/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPropagateLayout.cpp
@@ -599,6 +599,11 @@ void LayoutInfoPropagation::visitPrefetchNdOp(
     auto tdescTy = prefetch.getTensorDescType();
 
     auto uArch = getUArch(getChipStr(prefetch).value_or(""));
+    if (!uArch) {
+      prefetch.emitWarning(
+          "Missing target attribute, unable to assign layout.");
+      return;
+    }
     const auto *uArchInstruction =
         dyn_cast<xegpu::uArch::Subgroup2DBlockPrefetchInstruction>(
             uArch->getInstruction(
@@ -655,6 +660,10 @@ void LayoutInfoPropagation::visitVectorMultiReductionOp(
     return;
   }
   auto uArch = getUArch(xegpu::getChipStr(reduction).value_or(""));
+  if (!uArch) {
+    reduction.emitWarning("Missing target attribute, unable to assign layout.");
+    return;
+  }
   // Given that the result is 1D, the layout of the operand should be 2D with
   // default layout.
   LayoutInfo operandLayout = getDefaultSIMTLayoutInfo(
@@ -772,6 +781,10 @@ void LayoutInfoPropagation::visitDpasOp(
       cTy = dpas.getAccType();
 
     auto uArch = getUArch(getChipStr(dpas).value_or(""));
+    if (!uArch) {
+      dpas.emitWarning("Missing target attribute, unable to assign layout.");
+      return;
+    }
     const int subgroupSize = uArch->getSubgroupSize();
     const auto *uArchInstruction =
         dyn_cast<xegpu::uArch::SubgroupMatrixMultiplyAcc>(uArch->getInstruction(
@@ -951,6 +964,10 @@ void LayoutInfoPropagation::visitStoreNdOp(
     storeLayout = LayoutInfo(anchorLayout);
   } else {
     auto uArch = getUArch(getChipStr(store).value_or(""));
+    if (!uArch) {
+      store.emitWarning("Missing target attribute, unable to assign layout.");
+      return;
+    }
     const auto *uArchInstruction =
         dyn_cast<xegpu::uArch::Subgroup2DBlockStoreInstruction>(
             uArch->getInstruction(
@@ -1142,6 +1159,10 @@ void LayoutInfoPropagation::visitLoadGatherOp(
   LayoutInfo loadLayout;
   LayoutInfo maskLayout;
   auto uArch = getUArch(getChipStr(load).value_or(""));
+  if (!uArch) {
+    load.emitWarning("Missing target attribute, unable to assign layout.");
+    return;
+  }
   const int subgroupSize = uArch->getSubgroupSize();
   xegpu::DistributeLayoutAttr anchorLayout = load.getLayoutAttr();
   if (hasParamsOfLayoutKind(anchorLayout)) {
@@ -1240,6 +1261,11 @@ void LayoutInfoPropagation::visitCreateDescOp(
   if (!descLayout.isAssigned())
     return;
   auto uArch = getUArch(getChipStr(createDesc).value_or(""));
+  if (!uArch) {
+    createDesc.emitWarning(
+        "Missing target attribute, unable to assign layout.");
+    return;
+  }
   // For offset operand propagate 1D default layout.
   LayoutInfo layout = getDefaultSIMTLayoutInfo(createDesc->getContext(), 1,
                                                uArch->getSubgroupSize());
@@ -1256,6 +1282,11 @@ void LayoutInfoPropagation::visitStoreScatterOp(
   LayoutInfo maskLayout;
   xegpu::DistributeLayoutAttr anchorLayout = storeScatter.getLayoutAttr();
   auto uArch = getUArch(getChipStr(storeScatter).value_or(""));
+  if (!uArch) {
+    storeScatter.emitWarning(
+        "Missing target attribute, unable to assign layout.");
+    return;
+  }
   const int subgroupSize = uArch->getSubgroupSize();
 
   if (hasParamsOfLayoutKind(anchorLayout)) {
@@ -1344,6 +1375,11 @@ void LayoutInfoPropagation::visitStoreMatrixOp(
     VectorType payloadTy = llvm::cast<VectorType>(operand.getType());
     assert(payloadTy.getRank() == 2 && "Expecting 2D vector for store matrix.");
     auto uArch = getUArch(getChipStr(storeMatrix).value_or(""));
+    if (!uArch) {
+      storeMatrix.emitWarning(
+          "Missing target attribute, unable to assign layout.");
+      return;
+    }
     SmallVector<int> instData = {1, uArch->getSubgroupSize()};
     if (layoutKind == LayoutKind::InstData)
       layout = LayoutInfo(
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