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() {
17 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr @b, i64 10
18 ; CHECK-NEXT: [[B_VAL:%.*]] = load i8, ptr [[TMP1]], align 1
19 ; CHECK-NEXT: [[TMP2:%.*]] = tail call i8 @UseLongDoubleUnsafely(i8 [[B_VAL]])
20 ; CHECK-NEXT: [[B_VAL1:%.*]] = load x86_fp80, ptr @b, align 16
21 ; CHECK-NEXT: [[TMP3:%.*]] = tail call x86_fp80 @UseLongDoubleSafely(x86_fp80 [[B_VAL1]])
22 ; CHECK-NEXT: [[TMP4:%.*]] = tail call x86_fp80 @UseLongDoubleSafelyNoPromotion(ptr byval([[UNION_U:%.*]]) align 16 @b)
23 ; CHECK-NEXT: [[A_VAL:%.*]] = load i64, ptr @a, align 8
24 ; CHECK-NEXT: [[TMP5:%.*]] = call i64 @AccessPaddingOfStruct(i64 [[A_VAL]])
25 ; CHECK-NEXT: [[TMP6:%.*]] = call i64 @CaptureAStruct(ptr byval([[STRUCT_FOO:%.*]]) @a)
26 ; CHECK-NEXT: ret void
28 tail call i8 @UseLongDoubleUnsafely(ptr byval(%union.u) align 16 @b)
29 tail call x86_fp80 @UseLongDoubleSafely(ptr byval(%union.u) align 16 @b)
30 tail call x86_fp80 @UseLongDoubleSafelyNoPromotion(ptr byval(%union.u) align 16 @b)
31 call i64 @AccessPaddingOfStruct(ptr byval(%struct.Foo) @a)
32 call i64 @CaptureAStruct(ptr byval(%struct.Foo) @a)
36 define internal i8 @UseLongDoubleUnsafely(ptr byval(%union.u) align 16 %arg) {
37 ; CHECK-LABEL: define {{[^@]+}}@UseLongDoubleUnsafely
38 ; CHECK-SAME: (i8 [[ARG_10_VAL:%.*]]) {
39 ; CHECK-NEXT: ret i8 [[ARG_10_VAL]]
41 %gep = getelementptr inbounds %struct.s, ptr %arg, i64 0, i32 2
42 %result = load i8, ptr %gep
46 define internal x86_fp80 @UseLongDoubleSafely(ptr byval(%union.u) align 16 %arg) {
47 ; CHECK-LABEL: define {{[^@]+}}@UseLongDoubleSafely
48 ; CHECK-SAME: (x86_fp80 [[ARG_0_VAL:%.*]]) {
49 ; CHECK-NEXT: ret x86_fp80 [[ARG_0_VAL]]
51 %fp80 = load x86_fp80, ptr %arg
55 define internal x86_fp80 @UseLongDoubleSafelyNoPromotion(ptr byval(%union.u) align 16 %arg) {
56 ; CHECK-LABEL: define {{[^@]+}}@UseLongDoubleSafelyNoPromotion
57 ; CHECK-SAME: (ptr byval([[UNION_U:%.*]]) align 16 [[ARG:%.*]]) {
58 ; CHECK-NEXT: [[IDX_SLOT:%.*]] = alloca i64, align 8
59 ; CHECK-NEXT: store i64 0, ptr [[IDX_SLOT]], align 8
60 ; CHECK-NEXT: [[IDX:%.*]] = load i64, ptr [[IDX_SLOT]], align 8
61 ; CHECK-NEXT: [[GEP_IDX:%.*]] = getelementptr inbounds [[UNION_U]], ptr [[ARG]], i64 [[IDX]], i32 0
62 ; CHECK-NEXT: [[FP80:%.*]] = load x86_fp80, ptr [[ARG]], align 16
63 ; CHECK-NEXT: ret x86_fp80 [[FP80]]
65 %idx_slot = alloca i64, align 8
66 store i64 0, ptr %idx_slot, align 8
67 %idx = load i64, ptr %idx_slot, align 8
68 %gep_idx = getelementptr inbounds %union.u, ptr %arg, i64 %idx, i32 0 ; to protect from promotion
69 %fp80 = load x86_fp80, ptr %arg
73 define internal i64 @AccessPaddingOfStruct(ptr byval(%struct.Foo) %a) {
74 ; CHECK-LABEL: define {{[^@]+}}@AccessPaddingOfStruct
75 ; CHECK-SAME: (i64 [[A_0_VAL:%.*]]) {
76 ; CHECK-NEXT: ret i64 [[A_0_VAL]]
82 define internal i64 @CaptureAStruct(ptr byval(%struct.Foo) %a) {
83 ; CHECK-LABEL: define {{[^@]+}}@CaptureAStruct
84 ; CHECK-SAME: (ptr byval([[STRUCT_FOO:%.*]]) [[A:%.*]]) {
86 ; CHECK-NEXT: [[A_PTR:%.*]] = alloca ptr, align 8
87 ; CHECK-NEXT: br label [[LOOP:%.*]]
89 ; CHECK-NEXT: [[PHI:%.*]] = phi ptr [ null, [[ENTRY:%.*]] ], [ [[A]], [[LOOP]] ]
90 ; CHECK-NEXT: [[TMP0:%.*]] = phi ptr [ [[A]], [[ENTRY]] ], [ [[TMP0]], [[LOOP]] ]
91 ; CHECK-NEXT: store ptr [[PHI]], ptr [[A_PTR]], align 8
92 ; CHECK-NEXT: br label [[LOOP]]
99 %phi = phi ptr [ null, %entry ], [ %a, %loop ]
100 %0 = phi ptr [ %a, %entry ], [ %0, %loop ]
101 store ptr %phi, ptr %a_ptr