1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --version 3
2 ; RUN: opt -S -passes=argpromotion < %s | FileCheck %s
4 declare ptr @malloc(i64)
5 declare ptr @calloc(i64, i64)
7 define internal ptr @my_alloc1(i64 %unchanged, ptr %unused, i64 %size, ptr %unused2) allocsize(2) {
8 ; CHECK: Function Attrs: allocsize(1)
9 ; CHECK-LABEL: define internal ptr @my_alloc1(
10 ; CHECK-SAME: i64 [[UNCHANGED:%.*]], i64 [[SIZE:%.*]]) #[[ATTR0:[0-9]+]] {
11 ; CHECK-NEXT: [[PTR:%.*]] = call ptr @malloc(i64 [[SIZE]])
12 ; CHECK-NEXT: ret ptr [[PTR]]
14 %ptr = call ptr @malloc(i64 %size)
18 define internal ptr @my_alloc2(i64 %unchanged, ptr %unused, i64 %size, i64 %size2, ptr %unused2) allocsize(2,3) {
19 ; CHECK: Function Attrs: allocsize(1,2)
20 ; CHECK-LABEL: define internal ptr @my_alloc2(
21 ; CHECK-SAME: i64 [[UNCHANGED:%.*]], i64 [[SIZE:%.*]], i64 [[SIZE2:%.*]]) #[[ATTR1:[0-9]+]] {
22 ; CHECK-NEXT: [[PTR:%.*]] = call ptr @calloc(i64 [[SIZE]], i64 [[SIZE2]])
23 ; CHECK-NEXT: ret ptr [[PTR]]
25 %ptr = call ptr @calloc(i64 %size, i64 %size2)
29 define internal ptr @my_alloc3(i64 %unchanged, ptr %promoted, ptr %promoted2, i64 %size) allocsize(3) {
30 ; CHECK: Function Attrs: allocsize(5)
31 ; CHECK-LABEL: define internal ptr @my_alloc3(
32 ; CHECK-SAME: i64 [[UNCHANGED:%.*]], i32 [[PROMOTED_0_VAL:%.*]], i32 [[PROMOTED_4_VAL:%.*]], i32 [[PROMOTED2_0_VAL:%.*]], i32 [[PROMOTED2_4_VAL:%.*]], i64 [[SIZE:%.*]]) #[[ATTR2:[0-9]+]] {
33 ; CHECK-NEXT: [[PTR:%.*]] = call ptr @malloc(i64 [[SIZE]])
34 ; CHECK-NEXT: ret ptr [[PTR]]
36 load i32, ptr %promoted
37 %promoted.gep1 = getelementptr i8, ptr %promoted, i64 4
38 load i32, ptr %promoted.gep1
40 load i32, ptr %promoted2
41 %promoted2.gep1 = getelementptr i8, ptr %promoted2, i64 4
42 load i32, ptr %promoted2.gep1
44 %ptr = call ptr @malloc(i64 %size)
48 define internal ptr @my_alloc4(i64 %unchanged, ptr %promoted, ptr %promoted2, i64 %size, i64 %size2) allocsize(3,4) {
49 ; CHECK: Function Attrs: allocsize(5,6)
50 ; CHECK-LABEL: define internal ptr @my_alloc4(
51 ; CHECK-SAME: i64 [[UNCHANGED:%.*]], i32 [[PROMOTED_0_VAL:%.*]], i32 [[PROMOTED_4_VAL:%.*]], i32 [[PROMOTED2_0_VAL:%.*]], i32 [[PROMOTED2_4_VAL:%.*]], i64 [[SIZE:%.*]], i64 [[SIZE2:%.*]]) #[[ATTR3:[0-9]+]] {
52 ; CHECK-NEXT: [[PTR:%.*]] = call ptr @calloc(i64 [[SIZE]], i64 [[SIZE2]])
53 ; CHECK-NEXT: ret ptr [[PTR]]
55 load i32, ptr %promoted
56 %promoted.gep1 = getelementptr i8, ptr %promoted, i64 4
57 load i32, ptr %promoted.gep1
59 load i32, ptr %promoted2
60 %promoted2.gep1 = getelementptr i8, ptr %promoted2, i64 4
61 load i32, ptr %promoted2.gep1
63 %ptr = call ptr @calloc(i64 %size, i64 %size2)
67 define void @call_my_alloc(ptr %arg, ptr %arg2) {
68 ; CHECK-LABEL: define void @call_my_alloc(
69 ; CHECK-SAME: ptr [[ARG:%.*]], ptr [[ARG2:%.*]]) {
70 ; CHECK-NEXT: [[TMP1:%.*]] = call ptr @my_alloc1(i64 0, i64 2)
71 ; CHECK-NEXT: [[TMP2:%.*]] = call ptr @my_alloc2(i64 0, i64 2, i64 2)
72 ; CHECK-NEXT: [[ARG_VAL:%.*]] = load i32, ptr [[ARG]], align 4
73 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr i8, ptr [[ARG]], i64 4
74 ; CHECK-NEXT: [[ARG_VAL1:%.*]] = load i32, ptr [[TMP3]], align 4
75 ; CHECK-NEXT: [[ARG2_VAL:%.*]] = load i32, ptr [[ARG2]], align 4
76 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr i8, ptr [[ARG2]], i64 4
77 ; CHECK-NEXT: [[ARG2_VAL2:%.*]] = load i32, ptr [[TMP4]], align 4
78 ; CHECK-NEXT: [[TMP5:%.*]] = call ptr @my_alloc3(i64 0, i32 [[ARG_VAL]], i32 [[ARG_VAL1]], i32 [[ARG2_VAL]], i32 [[ARG2_VAL2]], i64 2)
79 ; CHECK-NEXT: [[ARG_VAL3:%.*]] = load i32, ptr [[ARG]], align 4
80 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr i8, ptr [[ARG]], i64 4
81 ; CHECK-NEXT: [[ARG_VAL4:%.*]] = load i32, ptr [[TMP6]], align 4
82 ; CHECK-NEXT: [[ARG2_VAL5:%.*]] = load i32, ptr [[ARG2]], align 4
83 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr i8, ptr [[ARG2]], i64 4
84 ; CHECK-NEXT: [[ARG2_VAL6:%.*]] = load i32, ptr [[TMP7]], align 4
85 ; CHECK-NEXT: [[TMP8:%.*]] = call ptr @my_alloc4(i64 0, i32 [[ARG_VAL3]], i32 [[ARG_VAL4]], i32 [[ARG2_VAL5]], i32 [[ARG2_VAL6]], i64 2, i64 2)
86 ; CHECK-NEXT: ret void
88 %ptr = call ptr @my_alloc1(i64 0, ptr null, i64 2, ptr null)
89 %ptr2 = call ptr @my_alloc2(i64 0, ptr null, i64 2, i64 2, ptr null)
90 %ptr3 = call ptr @my_alloc3(i64 0, ptr %arg, ptr %arg2, i64 2)
91 %ptr4 = call ptr @my_alloc4(i64 0, ptr %arg, ptr %arg2, i64 2, i64 2)