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

Current usage of alignstack is restricted to LLVM pointer types, whereas
when it's used in parameters it's possible to use it for other types,
see examples like `{i8, i8}, [2 x float], etc` in `llvm/test/CodeGen`.
This PR lifts the restriction and add testcases.
This commit is contained in:
Bruno Cardoso Lopes 2025-03-27 10:28:37 -07:00 committed by GitHub
parent c6406c8dba
commit 08aedf7201
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 55 additions and 7 deletions

View File

@ -4032,8 +4032,7 @@ 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()))
@ -4041,6 +4040,13 @@ LogicalResult LLVMDialect::verifyParameterAttribute(Operation *op,
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() ||

View File

@ -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
}

View File

@ -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"})

View File

@ -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
}