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
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
7 %union.u = type { x86_fp80 }
8 %struct.s = type { double, i16, i8, [5 x i8] }
10 @b = internal global %struct.s { double 3.14, i16 9439, i8 25, [5 x i8] undef }, align 16
12 %struct.Foo = type { i32, i64 }
13 @a = internal global %struct.Foo { i32 1, i64 2 }, align 8
16 ; CHECK-LABEL: define {{[^@]+}}@run()
18 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i8 @UseLongDoubleUnsafely(%union.u* byval(%union.u) align 16 bitcast (%struct.s* @b to %union.u*))
19 ; CHECK-NEXT: [[DOT0:%.*]] = getelementptr [[UNION_U:%.*]], %union.u* bitcast (%struct.s* @b to %union.u*), i32 0, i32 0
20 ; CHECK-NEXT: [[DOT0_VAL:%.*]] = load x86_fp80, x86_fp80* [[DOT0]]
21 ; CHECK-NEXT: [[TMP1:%.*]] = tail call x86_fp80 @UseLongDoubleSafely(x86_fp80 [[DOT0_VAL]])
22 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @AccessPaddingOfStruct(%struct.Foo* byval(%struct.Foo) @a)
23 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @CaptureAStruct(%struct.Foo* byval(%struct.Foo) @a)
24 ; CHECK-NEXT: ret void
27 tail call i8 @UseLongDoubleUnsafely(%union.u* byval(%union.u) align 16 bitcast (%struct.s* @b to %union.u*))
28 tail call x86_fp80 @UseLongDoubleSafely(%union.u* byval(%union.u) align 16 bitcast (%struct.s* @b to %union.u*))
29 call i64 @AccessPaddingOfStruct(%struct.Foo* byval(%struct.Foo) @a)
30 call i64 @CaptureAStruct(%struct.Foo* byval(%struct.Foo) @a)
34 define internal i8 @UseLongDoubleUnsafely(%union.u* byval(%union.u) align 16 %arg) {
35 ; CHECK-LABEL: define {{[^@]+}}@UseLongDoubleUnsafely
36 ; CHECK-SAME: (%union.u* byval(%union.u) align 16 [[ARG:%.*]])
38 ; CHECK-NEXT: [[BITCAST:%.*]] = bitcast %union.u* [[ARG]] to %struct.s*
39 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [[STRUCT_S:%.*]], %struct.s* [[BITCAST]], i64 0, i32 2
40 ; CHECK-NEXT: [[RESULT:%.*]] = load i8, i8* [[GEP]]
41 ; CHECK-NEXT: ret i8 [[RESULT]]
44 %bitcast = bitcast %union.u* %arg to %struct.s*
45 %gep = getelementptr inbounds %struct.s, %struct.s* %bitcast, i64 0, i32 2
46 %result = load i8, i8* %gep
50 define internal x86_fp80 @UseLongDoubleSafely(%union.u* byval(%union.u) align 16 %arg) {
51 ; CHECK-LABEL: define {{[^@]+}}@UseLongDoubleSafely
52 ; CHECK-SAME: (x86_fp80 [[ARG_0:%.*]])
53 ; CHECK-NEXT: [[ARG:%.*]] = alloca [[UNION_U:%.*]], align 16
54 ; CHECK-NEXT: [[DOT0:%.*]] = getelementptr [[UNION_U]], %union.u* [[ARG]], i32 0, i32 0
55 ; CHECK-NEXT: store x86_fp80 [[ARG_0]], x86_fp80* [[DOT0]]
56 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [[UNION_U]], %union.u* [[ARG]], i64 0, i32 0
57 ; CHECK-NEXT: [[FP80:%.*]] = load x86_fp80, x86_fp80* [[GEP]]
58 ; CHECK-NEXT: ret x86_fp80 [[FP80]]
60 %gep = getelementptr inbounds %union.u, %union.u* %arg, i64 0, i32 0
61 %fp80 = load x86_fp80, x86_fp80* %gep
65 define internal i64 @AccessPaddingOfStruct(%struct.Foo* byval(%struct.Foo) %a) {
66 ; CHECK-LABEL: define {{[^@]+}}@AccessPaddingOfStruct
67 ; CHECK-SAME: (%struct.Foo* byval(%struct.Foo) [[A:%.*]])
68 ; CHECK-NEXT: [[P:%.*]] = bitcast %struct.Foo* [[A]] to i64*
69 ; CHECK-NEXT: [[V:%.*]] = load i64, i64* [[P]]
70 ; CHECK-NEXT: ret i64 [[V]]
72 %p = bitcast %struct.Foo* %a to i64*
73 %v = load i64, i64* %p
77 define internal i64 @CaptureAStruct(%struct.Foo* byval(%struct.Foo) %a) {
78 ; CHECK-LABEL: define {{[^@]+}}@CaptureAStruct
79 ; CHECK-SAME: (%struct.Foo* byval(%struct.Foo) [[A:%.*]])
81 ; CHECK-NEXT: [[A_PTR:%.*]] = alloca %struct.Foo*
82 ; CHECK-NEXT: br label [[LOOP:%.*]]
84 ; CHECK-NEXT: [[PHI:%.*]] = phi %struct.Foo* [ null, [[ENTRY:%.*]] ], [ [[GEP:%.*]], [[LOOP]] ]
85 ; CHECK-NEXT: [[TMP0:%.*]] = phi %struct.Foo* [ [[A]], [[ENTRY]] ], [ [[TMP0]], [[LOOP]] ]
86 ; CHECK-NEXT: store %struct.Foo* [[PHI]], %struct.Foo** [[A_PTR]]
87 ; CHECK-NEXT: [[GEP]] = getelementptr [[STRUCT_FOO:%.*]], %struct.Foo* [[A]], i64 0
88 ; CHECK-NEXT: br label [[LOOP]]
91 %a_ptr = alloca %struct.Foo*
95 %phi = phi %struct.Foo* [ null, %entry ], [ %gep, %loop ]
96 %0 = phi %struct.Foo* [ %a, %entry ], [ %0, %loop ]
97 store %struct.Foo* %phi, %struct.Foo** %a_ptr
98 %gep = getelementptr %struct.Foo, %struct.Foo* %a, i64 0