Skip to content

[mlir][gpu] Fix bug with GPU hardware intrinsic global location #144923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm-debuginfo.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}