1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
2; RUN: opt -S -argpromotion < %s | FileCheck %s
3
4define internal i32 @callee_must_exec(i32* %p) {
5; CHECK-LABEL: define {{[^@]+}}@callee_must_exec
6; CHECK-SAME: (i32 [[P_0_VAL:%.*]]) {
7; CHECK-NEXT:    ret i32 [[P_0_VAL]]
8;
9  %x = load i32, i32* %p, align 16
10  ret i32 %x
11}
12
13define void @caller_must_exec(i32* %p) {
14; CHECK-LABEL: define {{[^@]+}}@caller_must_exec
15; CHECK-SAME: (i32* [[P:%.*]]) {
16; CHECK-NEXT:    [[P_VAL:%.*]] = load i32, i32* [[P]], align 16
17; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @callee_must_exec(i32 [[P_VAL]])
18; CHECK-NEXT:    ret void
19;
20  call i32 @callee_must_exec(i32* %p)
21  ret void
22}
23
24define internal i32 @callee_guaranteed_aligned_1(i1 %c, i32* %p) {
25; CHECK-LABEL: define {{[^@]+}}@callee_guaranteed_aligned_1
26; CHECK-SAME: (i1 [[C:%.*]], i32 [[P_0_VAL:%.*]]) {
27; CHECK-NEXT:    br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
28; CHECK:       if:
29; CHECK-NEXT:    ret i32 [[P_0_VAL]]
30; CHECK:       else:
31; CHECK-NEXT:    ret i32 -1
32;
33  br i1 %c, label %if, label %else
34
35if:
36  %x = load i32, i32* %p, align 16
37  ret i32 %x
38
39else:
40  ret i32 -1
41}
42
43define void @caller_guaranteed_aligned_1(i1 %c, i32* align 16 dereferenceable(4) %p) {
44; CHECK-LABEL: define {{[^@]+}}@caller_guaranteed_aligned_1
45; CHECK-SAME: (i1 [[C:%.*]], i32* align 16 dereferenceable(4) [[P:%.*]]) {
46; CHECK-NEXT:    [[P_VAL:%.*]] = load i32, i32* [[P]], align 16
47; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @callee_guaranteed_aligned_1(i1 [[C]], i32 [[P_VAL]])
48; CHECK-NEXT:    ret void
49;
50  call i32 @callee_guaranteed_aligned_1(i1 %c, i32* %p)
51  ret void
52}
53
54define internal i32 @callee_guaranteed_aligned_2(i1 %c, i32* align 16 dereferenceable(4) %p) {
55; CHECK-LABEL: define {{[^@]+}}@callee_guaranteed_aligned_2
56; CHECK-SAME: (i1 [[C:%.*]], i32 [[P_0_VAL:%.*]]) {
57; CHECK-NEXT:    br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
58; CHECK:       if:
59; CHECK-NEXT:    ret i32 [[P_0_VAL]]
60; CHECK:       else:
61; CHECK-NEXT:    ret i32 -1
62;
63  br i1 %c, label %if, label %else
64
65if:
66  %x = load i32, i32* %p, align 16
67  ret i32 %x
68
69else:
70  ret i32 -1
71}
72
73define void @caller_guaranteed_aligned_2(i1 %c, i32* %p) {
74; CHECK-LABEL: define {{[^@]+}}@caller_guaranteed_aligned_2
75; CHECK-SAME: (i1 [[C:%.*]], i32* [[P:%.*]]) {
76; CHECK-NEXT:    [[P_VAL:%.*]] = load i32, i32* [[P]], align 16
77; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @callee_guaranteed_aligned_2(i1 [[C]], i32 [[P_VAL]])
78; CHECK-NEXT:    ret void
79;
80  call i32 @callee_guaranteed_aligned_2(i1 %c, i32* %p)
81  ret void
82}
83
84; This should not be promoted, as the caller only guarantees that the
85; pointer is dereferenceable, not that it is aligned.
86define internal i32 @callee_not_guaranteed_aligned(i1 %c, i32* %p) {
87; CHECK-LABEL: define {{[^@]+}}@callee_not_guaranteed_aligned
88; CHECK-SAME: (i1 [[C:%.*]], i32* [[P:%.*]]) {
89; CHECK-NEXT:    br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
90; CHECK:       if:
91; CHECK-NEXT:    [[X:%.*]] = load i32, i32* [[P]], align 16
92; CHECK-NEXT:    ret i32 [[X]]
93; CHECK:       else:
94; CHECK-NEXT:    ret i32 -1
95;
96  br i1 %c, label %if, label %else
97
98if:
99  %x = load i32, i32* %p, align 16
100  ret i32 %x
101
102else:
103  ret i32 -1
104}
105
106define void @caller_not_guaranteed_aligned(i1 %c, i32* dereferenceable(4) %p) {
107; CHECK-LABEL: define {{[^@]+}}@caller_not_guaranteed_aligned
108; CHECK-SAME: (i1 [[C:%.*]], i32* dereferenceable(4) [[P:%.*]]) {
109; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @callee_not_guaranteed_aligned(i1 [[C]], i32* [[P]])
110; CHECK-NEXT:    ret void
111;
112  call i32 @callee_not_guaranteed_aligned(i1 %c, i32* %p)
113  ret void
114}
115