Skip to content

Conversation

@adstraw
Copy link
Contributor

@adstraw adstraw commented Jun 19, 2025

Bug description: Hardware intrinsic functions created during GPU conversion to NVVM may contain debug info metadata from the original function which cannot be used out of that function.

@llvmbot
Copy link
Member

llvmbot commented Jun 19, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-gpu

Author: Adam Straw (adstraw)

Changes

Bug description: Hardware intrinsic functions created during GPU conversion to NVVM may contain debug info metadata from the original function which cannot be used out of that function.


Full diff: https://github.com/llvm/llvm-project/pull/144923.diff

2 Files Affected:

  • (modified) mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h (+2-1)
  • (modified) mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm-debuginfo.mlir (+9)
diff --git a/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h b/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
index 34150c4d13085..a4ef98b7a9195 100644
--- a/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
+++ b/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
@@ -164,7 +164,8 @@ 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);
+    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
+  }
+}

@adstraw
Copy link
Contributor Author

adstraw commented Jun 19, 2025

@River707 please review

@adstraw adstraw force-pushed the straw-gpu-hw-intrin branch from 16057b1 to 7a5c0e2 Compare June 19, 2025 19:23
@github-actions
Copy link

github-actions bot commented Jun 19, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@adstraw adstraw force-pushed the straw-gpu-hw-intrin branch from 7a5c0e2 to 469487a Compare June 19, 2025 19:28
@River707 River707 merged commit da0c21b into llvm:main Jun 23, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants