-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathalloca_invalid.mlir
More file actions
68 lines (61 loc) · 4.27 KB
/
Copy pathalloca_invalid.mlir
File metadata and controls
68 lines (61 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// RUN: veir-opt %s -p=isel-riscv64 > %t
// RUN: filecheck %s --input-file=%t
// RUN: filecheck %s --input-file=%t --check-prefix=ABSENT
// ABSENT: "builtin.module"
// ABSENT-NOT: riscv_stack.alloca
// Unsupported allocations remain LLVM operations. Keep their results live so
// the greedy driver's ordinary dead-code elimination does not erase them.
"builtin.module"() ({
"func.func"() <{sym_name = "unsupported", function_type = (i64) -> ()}> ({
^entry(%n: i64):
%one = "llvm.mlir.constant"() <{value = 1 : i64}> : () -> i64
%large = "llvm.mlir.constant"() <{value = 2305843009213693952 : i64}> : () -> i64
%wide = "llvm.mlir.constant"() <{value = 18446744073709551616 : i128}> : () -> i128
%poison = "llvm.mlir.poison"() : () -> i64
// Constant-like poison is not a concrete allocation count.
%poison_count = "llvm.alloca"(%poison) <{elem_type = i64}> : (i64) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 0 : i64, "elem_type" = i64}>
"test.test"(%poison_count) : (!llvm.ptr) -> ()
%dynamic = "llvm.alloca"(%n) <{elem_type = i64}> : (i64) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 0 : i64, "elem_type" = i64}>
%special = "llvm.alloca"(%one) <{elem_type = i8, inalloca}> : (i64) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 0 : i64, "elem_type" = i8, inalloca}>
%layout = "llvm.alloca"(%one) <{elem_type = !llvm.struct<(i32, i64)>}> : (i64) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 0 : i64, "elem_type" = !llvm.struct<(i32, i64)>}>
// The byte size must fit a signed 64-bit value without wrapping, even for a
// wide count: `riscv_stack.alloca` stores it as a nonnegative `BitVec 64`.
%overflow = "llvm.alloca"(%large) <{elem_type = i64}> : (i64) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 0 : i64, "elem_type" = i64}>
%signed_overflow = "llvm.alloca"(%large) <{elem_type = i32}> : (i64) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 0 : i64, "elem_type" = i32}>
%wide_count = "llvm.alloca"(%wide) <{elem_type = i8}> : (i128) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 0 : i64, "elem_type" = i8}>
// The LLVM verifier currently accepts these, but they cannot become valid
// fixed stack objects with the requested alignment/result type.
%bad_align = "llvm.alloca"(%one) <{elem_type = i8, alignment = 3 : i64}> : (i64) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 3 : i64, "elem_type" = i8}>
%negative_align = "llvm.alloca"(%one) <{elem_type = i8, alignment = -8 : i64}> : (i64) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = -8 : i64, "elem_type" = i8}>
%wide_align = "llvm.alloca"(%one) <{elem_type = i8, alignment = 18446744073709551616 : i64}> : (i64) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 18446744073709551616 : i64, "elem_type" = i8}>
%signed_align = "llvm.alloca"(%one) <{elem_type = i8, alignment = 9223372036854775808 : i64}> : (i64) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 9223372036854775808 : i64, "elem_type" = i8}>
%not_pointer = "llvm.alloca"(%one) <{elem_type = i8}> : (i64) -> i64
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 0 : i64, "elem_type" = i8}> : (i64) -> i64
"test.test"(%dynamic, %special, %layout, %overflow, %signed_overflow, %wide_count, %bad_align, %negative_align, %wide_align, %signed_align, %not_pointer) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> ()
"llvm.br"()[^later] : () -> ()
^later:
// A constant-count alloca outside the entry block is still dynamic.
%non_entry = "llvm.alloca"(%one) <{elem_type = i8}> : (i64) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 0 : i64, "elem_type" = i8}>
"test.test"(%non_entry) : (!llvm.ptr) -> ()
"func.return"() : () -> ()
}) : () -> ()
// A region's first block is insufficient: it must belong to a function.
"test.test"() ({
%one = "llvm.mlir.constant"() <{value = 1 : i64}> : () -> i64
%outside = "llvm.alloca"(%one) <{elem_type = i8}> : (i64) -> !llvm.ptr
// CHECK: "llvm.alloca"({{.*}}) <{"alignment" = 0 : i64, "elem_type" = i8}>
"test.test"(%outside) : (!llvm.ptr) -> ()
}) : () -> ()
}) : () -> ()