[Mlir-commits] [mlir] [mlir][xegpu] Fix crash in XeGPUPropagateLayout when module has llvm.func (PR #183899)

Mehdi Amini llvmlistbot at llvm.org
Sat Feb 28 03:31:51 PST 2026


https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/183899

updateFunctionOpInterface() called funcOp.setType(FunctionType::get(...)) on every FunctionOpInterface operation, including llvm.func. However, llvm.func stores its type as LLVMFunctionType, not the standard FunctionType. Calling setType(FunctionType{}) on it corrupts the function_type attribute, and the next call to getFunctionType() (which tries to cast<LLVMFunctionType> the stored attribute) aborts.

Fix by skipping functions whose type is not a standard FunctionType. XeGPU layout propagation only applies to functions using MLIR's FunctionType; other function types (like LLVMFunctionType) are not expected to carry XeGPU layouts.

Fixes #177846

>From 59819c637887d7142c4f68e6e58ca388d5ca774b Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Sat, 28 Feb 2026 03:26:10 -0800
Subject: [PATCH] [mlir][xegpu] Fix crash in XeGPUPropagateLayout when module
 has llvm.func

updateFunctionOpInterface() called funcOp.setType(FunctionType::get(...))
on every FunctionOpInterface operation, including llvm.func. However,
llvm.func stores its type as LLVMFunctionType, not the standard
FunctionType. Calling setType(FunctionType{}) on it corrupts the
function_type attribute, and the next call to getFunctionType() (which
tries to cast<LLVMFunctionType> the stored attribute) aborts.

Fix by skipping functions whose type is not a standard FunctionType.
XeGPU layout propagation only applies to functions using MLIR's
FunctionType; other function types (like LLVMFunctionType) are not
expected to carry XeGPU layouts.

Fixes #177846
---
 .../XeGPU/Transforms/XeGPUPropagateLayout.cpp       |  6 ++++++
 .../XeGPU/xegpu-propagate-layout-invalid.mlir       | 13 +++++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 mlir/test/Dialect/XeGPU/xegpu-propagate-layout-invalid.mlir

diff --git a/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPropagateLayout.cpp b/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPropagateLayout.cpp
index 10cd65b080405..313c60a9028db 100644
--- a/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPropagateLayout.cpp
+++ b/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPropagateLayout.cpp
@@ -1500,6 +1500,12 @@ updateControlFlowOps(mlir::OpBuilder &builder,
 static LogicalResult updateFunctionOpInterface(mlir::OpBuilder &builder,
                                                mlir::FunctionOpInterface funcOp,
                                                GetLayoutFnTy getLayoutOfValue) {
+  // Only process functions whose type is a standard MLIR FunctionType.
+  // Functions using a different type representation (e.g. llvm.func with
+  // LLVMFunctionType) are not targets for XeGPU layout propagation, and
+  // calling setType(FunctionType{}) on them would corrupt their type.
+  if (!isa<FunctionType>(funcOp.getFunctionType()))
+    return success();
   SmallVector<Type> newArgTypes;
   // Update the function arguments.
   for (BlockArgument arg : funcOp.getArguments()) {
diff --git a/mlir/test/Dialect/XeGPU/xegpu-propagate-layout-invalid.mlir b/mlir/test/Dialect/XeGPU/xegpu-propagate-layout-invalid.mlir
new file mode 100644
index 0000000000000..ded8a627f9f6a
--- /dev/null
+++ b/mlir/test/Dialect/XeGPU/xegpu-propagate-layout-invalid.mlir
@@ -0,0 +1,13 @@
+// RUN: mlir-opt --xegpu-propagate-layout %s | FileCheck %s
+
+// Regression test for https://github.com/llvm/llvm-project/issues/177846:
+// --xegpu-propagate-layout must not crash when the module contains an
+// llvm.func declaration. updateFunctionOpInterface called setType(FunctionType)
+// on an llvm.func (whose type is LLVMFunctionType), corrupting its
+// function_type attribute; the subsequent getFunctionType() then
+// triggered cast<LLVMFunctionType> on a FunctionType and aborted.
+
+// CHECK-LABEL: llvm.func @some_function()
+module {
+  llvm.func @some_function()
+}



More information about the Mlir-commits mailing list