Skip to content

[MLIR][LLVM] Lift alignstack attribute ptr type restriction #133195

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
Mar 27, 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
10 changes: 8 additions & 2 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4032,15 +4032,21 @@ LogicalResult LLVMDialect::verifyParameterAttribute(Operation *op,
// Check an integer attribute that is attached to a pointer value.
if (name == LLVMDialect::getAlignAttrName() ||
name == LLVMDialect::getDereferenceableAttrName() ||
name == LLVMDialect::getDereferenceableOrNullAttrName() ||
name == LLVMDialect::getStackAlignmentAttrName()) {
name == LLVMDialect::getDereferenceableOrNullAttrName()) {
if (failed(checkIntegerAttrType()))
return failure();
if (verifyValueType && failed(checkPointerType()))
return failure();
return success();
}

// Check an integer attribute that is attached to a pointer value.
if (name == LLVMDialect::getStackAlignmentAttrName()) {
if (failed(checkIntegerAttrType()))
return failure();
return success();
}

// Check a unit attribute that can be attached to arbitrary types.
if (name == LLVMDialect::getNoUndefAttrName() ||
name == LLVMDialect::getInRegAttrName() ||
Expand Down
23 changes: 23 additions & 0 deletions mlir/test/Dialect/LLVMIR/call-param.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: mlir-opt %s -split-input-file | FileCheck %s

llvm.func local_unnamed_addr @testfn(!llvm.array<2 x f32> {llvm.alignstack = 8 : i64})
llvm.func internal @g(%arg0: !llvm.array<2 x f32>) attributes {dso_local} {
// CHECK-LABEL: @g
// CHECK: llvm.call @testfn(%arg0) : (!llvm.array<2 x f32> {llvm.alignstack = 8 : i64}) -> ()
llvm.call @testfn(%arg0) : (!llvm.array<2 x f32> {llvm.alignstack = 8 : i64}) -> ()
llvm.return
}
llvm.func local_unnamed_addr @testfn2(!llvm.struct<(i8, i8)> {llvm.alignstack = 8 : i64})
llvm.func internal @h(%arg0: !llvm.struct<(i8, i8)>) attributes {dso_local} {
// CHECK-LABEL: @h
// CHECK: llvm.call @testfn2(%arg0) : (!llvm.struct<(i8, i8)> {llvm.alignstack = 8 : i64}) -> ()
llvm.call @testfn2(%arg0) : (!llvm.struct<(i8, i8)> {llvm.alignstack = 8 : i64}) -> ()
llvm.return
}
llvm.func local_unnamed_addr @testfn3(i32 {llvm.alignstack = 8 : i64})
llvm.func internal @i(%arg0: i32) attributes {dso_local} {
// CHECK-LABEL: @i
// CHECK: llvm.call @testfn3(%arg0) : (i32 {llvm.alignstack = 8 : i64}) -> ()
llvm.call @testfn3(%arg0) : (i32 {llvm.alignstack = 8 : i64}) -> ()
llvm.return
}
5 changes: 0 additions & 5 deletions mlir/test/Dialect/LLVMIR/parameter-attrs-invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ llvm.func @invalid_returned_attr_type(%0 : i32 {llvm.returned = !llvm.ptr})

// -----

// expected-error@below {{"llvm.alignstack" attribute attached to non-pointer LLVM type}}
llvm.func @invalid_alignstack_arg_type(%0 : i32 {llvm.alignstack = 10 : i32})

// -----

// expected-error@below {{"llvm.alignstack" should be an integer attribute}}
llvm.func @invalid_alignstack_attr_type(%0 : i32 {llvm.alignstack = "foo"})

Expand Down
24 changes: 24 additions & 0 deletions mlir/test/Target/LLVMIR/llvmir.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2842,3 +2842,27 @@ llvm.func @call_alias_func() {

// CHECK-LABEL: @call_alias_func
// CHECK: call void dso_local_equivalent @alias_func()

// -----

llvm.func local_unnamed_addr @testfn(!llvm.array<2 x f32> {llvm.alignstack = 8 : i64})
llvm.func internal @g(%arg0: !llvm.array<2 x f32>) attributes {dso_local} {
// CHECK-LABEL: @g
// CHECK: call void @testfn([2 x float] alignstack(8) %0)
llvm.call @testfn(%arg0) : (!llvm.array<2 x f32> {llvm.alignstack = 8 : i64}) -> ()
llvm.return
}
llvm.func local_unnamed_addr @testfn2(!llvm.struct<(i8, i8)> {llvm.alignstack = 8 : i64})
llvm.func internal @h(%arg0: !llvm.struct<(i8, i8)>) attributes {dso_local} {
// CHECK-LABEL: @h
// CHECK: call void @testfn2({ i8, i8 } alignstack(8) %0)
llvm.call @testfn2(%arg0) : (!llvm.struct<(i8, i8)> {llvm.alignstack = 8 : i64}) -> ()
llvm.return
}
llvm.func local_unnamed_addr @testfn3(i32 {llvm.alignstack = 8 : i64})
llvm.func internal @i(%arg0: i32) attributes {dso_local} {
// CHECK-LABEL: @i
// CHECK: call void @testfn3(i32 alignstack(8) %0)
llvm.call @testfn3(%arg0) : (i32 {llvm.alignstack = 8 : i64}) -> ()
llvm.return
}