Skip to content

Commit 08aedf7

Browse files
[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.
1 parent c6406c8 commit 08aedf7

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4032,15 +4032,21 @@ LogicalResult LLVMDialect::verifyParameterAttribute(Operation *op,
40324032
// Check an integer attribute that is attached to a pointer value.
40334033
if (name == LLVMDialect::getAlignAttrName() ||
40344034
name == LLVMDialect::getDereferenceableAttrName() ||
4035-
name == LLVMDialect::getDereferenceableOrNullAttrName() ||
4036-
name == LLVMDialect::getStackAlignmentAttrName()) {
4035+
name == LLVMDialect::getDereferenceableOrNullAttrName()) {
40374036
if (failed(checkIntegerAttrType()))
40384037
return failure();
40394038
if (verifyValueType && failed(checkPointerType()))
40404039
return failure();
40414040
return success();
40424041
}
40434042

4043+
// Check an integer attribute that is attached to a pointer value.
4044+
if (name == LLVMDialect::getStackAlignmentAttrName()) {
4045+
if (failed(checkIntegerAttrType()))
4046+
return failure();
4047+
return success();
4048+
}
4049+
40444050
// Check a unit attribute that can be attached to arbitrary types.
40454051
if (name == LLVMDialect::getNoUndefAttrName() ||
40464052
name == LLVMDialect::getInRegAttrName() ||
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: mlir-opt %s -split-input-file | FileCheck %s
2+
3+
llvm.func local_unnamed_addr @testfn(!llvm.array<2 x f32> {llvm.alignstack = 8 : i64})
4+
llvm.func internal @g(%arg0: !llvm.array<2 x f32>) attributes {dso_local} {
5+
// CHECK-LABEL: @g
6+
// CHECK: llvm.call @testfn(%arg0) : (!llvm.array<2 x f32> {llvm.alignstack = 8 : i64}) -> ()
7+
llvm.call @testfn(%arg0) : (!llvm.array<2 x f32> {llvm.alignstack = 8 : i64}) -> ()
8+
llvm.return
9+
}
10+
llvm.func local_unnamed_addr @testfn2(!llvm.struct<(i8, i8)> {llvm.alignstack = 8 : i64})
11+
llvm.func internal @h(%arg0: !llvm.struct<(i8, i8)>) attributes {dso_local} {
12+
// CHECK-LABEL: @h
13+
// CHECK: llvm.call @testfn2(%arg0) : (!llvm.struct<(i8, i8)> {llvm.alignstack = 8 : i64}) -> ()
14+
llvm.call @testfn2(%arg0) : (!llvm.struct<(i8, i8)> {llvm.alignstack = 8 : i64}) -> ()
15+
llvm.return
16+
}
17+
llvm.func local_unnamed_addr @testfn3(i32 {llvm.alignstack = 8 : i64})
18+
llvm.func internal @i(%arg0: i32) attributes {dso_local} {
19+
// CHECK-LABEL: @i
20+
// CHECK: llvm.call @testfn3(%arg0) : (i32 {llvm.alignstack = 8 : i64}) -> ()
21+
llvm.call @testfn3(%arg0) : (i32 {llvm.alignstack = 8 : i64}) -> ()
22+
llvm.return
23+
}

mlir/test/Dialect/LLVMIR/parameter-attrs-invalid.mlir

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@ llvm.func @invalid_returned_attr_type(%0 : i32 {llvm.returned = !llvm.ptr})
157157

158158
// -----
159159

160-
// expected-error@below {{"llvm.alignstack" attribute attached to non-pointer LLVM type}}
161-
llvm.func @invalid_alignstack_arg_type(%0 : i32 {llvm.alignstack = 10 : i32})
162-
163-
// -----
164-
165160
// expected-error@below {{"llvm.alignstack" should be an integer attribute}}
166161
llvm.func @invalid_alignstack_attr_type(%0 : i32 {llvm.alignstack = "foo"})
167162

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,3 +2842,27 @@ llvm.func @call_alias_func() {
28422842

28432843
// CHECK-LABEL: @call_alias_func
28442844
// CHECK: call void dso_local_equivalent @alias_func()
2845+
2846+
// -----
2847+
2848+
llvm.func local_unnamed_addr @testfn(!llvm.array<2 x f32> {llvm.alignstack = 8 : i64})
2849+
llvm.func internal @g(%arg0: !llvm.array<2 x f32>) attributes {dso_local} {
2850+
// CHECK-LABEL: @g
2851+
// CHECK: call void @testfn([2 x float] alignstack(8) %0)
2852+
llvm.call @testfn(%arg0) : (!llvm.array<2 x f32> {llvm.alignstack = 8 : i64}) -> ()
2853+
llvm.return
2854+
}
2855+
llvm.func local_unnamed_addr @testfn2(!llvm.struct<(i8, i8)> {llvm.alignstack = 8 : i64})
2856+
llvm.func internal @h(%arg0: !llvm.struct<(i8, i8)>) attributes {dso_local} {
2857+
// CHECK-LABEL: @h
2858+
// CHECK: call void @testfn2({ i8, i8 } alignstack(8) %0)
2859+
llvm.call @testfn2(%arg0) : (!llvm.struct<(i8, i8)> {llvm.alignstack = 8 : i64}) -> ()
2860+
llvm.return
2861+
}
2862+
llvm.func local_unnamed_addr @testfn3(i32 {llvm.alignstack = 8 : i64})
2863+
llvm.func internal @i(%arg0: i32) attributes {dso_local} {
2864+
// CHECK-LABEL: @i
2865+
// CHECK: call void @testfn3(i32 alignstack(8) %0)
2866+
llvm.call @testfn3(%arg0) : (i32 {llvm.alignstack = 8 : i64}) -> ()
2867+
llvm.return
2868+
}

0 commit comments

Comments
 (0)