[Mlir-commits] [mlir] [mlir][gpu] Fix bug with GPU hardware intrinsic global location (PR #144923)
Adam Straw
llvmlistbot at llvm.org
Thu Jun 19 12:28:13 PDT 2025
https://github.com/adstraw updated https://github.com/llvm/llvm-project/pull/144923
>From 469487a81b2342fd6152093bf63da27c3157a720 Mon Sep 17 00:00:00 2001
From: Adam Straw <astraw at nvidia.com>
Date: Thu, 19 Jun 2025 09:21:11 -0700
Subject: [PATCH] [mlir][gpu] Fix bug with GPU hardware intrinsic global
location
---
mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h | 7 ++++++-
.../test/Conversion/GPUToNVVM/gpu-to-nvvm-debuginfo.mlir | 9 +++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h b/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
index 34150c4d13085..64cf09e600b88 100644
--- a/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
+++ b/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
@@ -164,7 +164,12 @@ struct OpToFuncCallLowering : public ConvertOpToLLVMPattern<SourceOp> {
auto parentFunc = op->getParentOfType<FunctionOpInterface>();
assert(parentFunc && "expected there to be a parent function");
OpBuilder b(parentFunc);
- return b.create<LLVMFuncOp>(op->getLoc(), funcName, funcType);
+
+ // Create a valid global location removing any metadata attached to the
+ // location as debug info metadata inside of a function cannot be used
+ // outside of that function.
+ auto globalloc = op->getLoc()->findInstanceOfOrUnknown<FileLineColLoc>();
+ return b.create<LLVMFuncOp>(globalloc, funcName, funcType);
}
StringRef getFunctionName(Type type, SourceOp op) const {
diff --git a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm-debuginfo.mlir b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm-debuginfo.mlir
index 08c5800fe93b3..5304abfb09a1e 100644
--- a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm-debuginfo.mlir
+++ b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm-debuginfo.mlir
@@ -23,3 +23,12 @@ gpu.module @test_module_1 {
gpu.return
}
}
+
+// Check that debug info metadata from the function is removed from the global location.
+gpu.module @test_module_2 {
+ // CHECK-DAG: llvm.func @__nv_abs(i32) -> i32 loc([[LOC]])
+ func.func @gpu_abs_with_loc(%arg_i32 : i32) -> (i32) {
+ %result32 = math.absi %arg_i32 : i32 loc(fused<#di_subprogram>[#loc])
+ func.return %result32 : i32
+ }
+}
More information about the Mlir-commits
mailing list