1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
2; RUN: opt -S -passes=argpromotion < %s | FileCheck %s
3
4; Test argument promotion involving bitcasts.
5
6%opaque = type opaque
7
8define internal i32 @callee_basic(i8* %p) {
9; CHECK-LABEL: define {{[^@]+}}@callee_basic
10; CHECK-SAME: (i32 [[P_0_VAL:%.*]], i32 [[P_4_VAL:%.*]]) {
11; CHECK-NEXT:    [[Z:%.*]] = add i32 [[P_0_VAL]], [[P_4_VAL]]
12; CHECK-NEXT:    ret i32 [[Z]]
13;
14  %p.32 = bitcast i8* %p to i32*
15  %x = load i32, i32* %p.32
16  %p1 = getelementptr i8, i8* %p, i64 4
17  %p1.32 = bitcast i8* %p1 to i32*
18  %y = load i32, i32* %p1.32
19  %z = add i32 %x, %y
20  ret i32 %z
21}
22
23define void @caller_basic(i8* %p) {
24; CHECK-LABEL: define {{[^@]+}}@caller_basic
25; CHECK-SAME: (i8* [[P:%.*]]) {
26; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i8* [[P]] to i32*
27; CHECK-NEXT:    [[P_VAL:%.*]] = load i32, i32* [[TMP1]], align 4
28; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr i8, i8* [[P]], i64 4
29; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i8* [[TMP2]] to i32*
30; CHECK-NEXT:    [[P_VAL1:%.*]] = load i32, i32* [[TMP3]], align 4
31; CHECK-NEXT:    [[TMP4:%.*]] = call i32 @callee_basic(i32 [[P_VAL]], i32 [[P_VAL1]])
32; CHECK-NEXT:    ret void
33;
34  call i32 @callee_basic(i8* %p)
35  ret void
36}
37
38define internal i32 @callee_opaque(%opaque* %p) {
39; CHECK-LABEL: define {{[^@]+}}@callee_opaque
40; CHECK-SAME: (i32 [[P_0_VAL:%.*]], i32 [[P_4_VAL:%.*]]) {
41; CHECK-NEXT:    [[Z:%.*]] = add i32 [[P_0_VAL]], [[P_4_VAL]]
42; CHECK-NEXT:    ret i32 [[Z]]
43;
44  %p.32 = bitcast %opaque* %p to i32*
45  %x = load i32, i32* %p.32
46  %p1.32 = getelementptr i32, i32* %p.32, i64 1
47  %y = load i32, i32* %p1.32
48  %z = add i32 %x, %y
49  ret i32 %z
50}
51
52define void @caller_opaque(%opaque* %p) {
53; CHECK-LABEL: define {{[^@]+}}@caller_opaque
54; CHECK-SAME: (%opaque* [[P:%.*]]) {
55; CHECK-NEXT:    [[TMP1:%.*]] = bitcast %opaque* [[P]] to i32*
56; CHECK-NEXT:    [[P_VAL:%.*]] = load i32, i32* [[TMP1]], align 4
57; CHECK-NEXT:    [[TMP2:%.*]] = bitcast %opaque* [[P]] to i8*
58; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr i8, i8* [[TMP2]], i64 4
59; CHECK-NEXT:    [[TMP4:%.*]] = bitcast i8* [[TMP3]] to i32*
60; CHECK-NEXT:    [[P_VAL1:%.*]] = load i32, i32* [[TMP4]], align 4
61; CHECK-NEXT:    [[TMP5:%.*]] = call i32 @callee_opaque(i32 [[P_VAL]], i32 [[P_VAL1]])
62; CHECK-NEXT:    ret void
63;
64  call i32 @callee_opaque(%opaque* %p)
65  ret void
66}
67