• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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; RUN: opt < %s -passes=argpromotion -S | FileCheck %s
4
5target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6target triple = "x86_64-unknown-linux-gnu"
7
8%union.u = type { x86_fp80 }
9%struct.s = type { double, i16, i8, [5 x i8] }
10
11@b = internal global %struct.s { double 3.14, i16 9439, i8 25, [5 x i8] undef }, align 16
12
13%struct.Foo = type { i32, i64 }
14@a = internal global %struct.Foo { i32 1, i64 2 }, align 8
15
16define void @run() {
17; CHECK-LABEL: define {{[^@]+}}@run()
18; CHECK-NEXT:  entry:
19; CHECK-NEXT:    [[TMP0:%.*]] = tail call i8 @UseLongDoubleUnsafely(%union.u* byval(%union.u) align 16 bitcast (%struct.s* @b to %union.u*))
20; CHECK-NEXT:    [[DOT0:%.*]] = getelementptr [[UNION_U:%.*]], %union.u* bitcast (%struct.s* @b to %union.u*), i32 0, i32 0
21; CHECK-NEXT:    [[DOT0_VAL:%.*]] = load x86_fp80, x86_fp80* [[DOT0]]
22; CHECK-NEXT:    [[TMP1:%.*]] = tail call x86_fp80 @UseLongDoubleSafely(x86_fp80 [[DOT0_VAL]])
23; CHECK-NEXT:    [[TMP2:%.*]] = call i64 @AccessPaddingOfStruct(%struct.Foo* @a)
24; CHECK-NEXT:    [[TMP3:%.*]] = call i64 @CaptureAStruct(%struct.Foo* @a)
25; CHECK-NEXT:    ret void
26;
27entry:
28  tail call i8 @UseLongDoubleUnsafely(%union.u* byval(%union.u) align 16 bitcast (%struct.s* @b to %union.u*))
29  tail call x86_fp80 @UseLongDoubleSafely(%union.u* byval(%union.u) align 16 bitcast (%struct.s* @b to %union.u*))
30  call i64 @AccessPaddingOfStruct(%struct.Foo* @a)
31  call i64 @CaptureAStruct(%struct.Foo* @a)
32  ret void
33}
34
35define internal i8 @UseLongDoubleUnsafely(%union.u* byval(%union.u) align 16 %arg) {
36; CHECK-LABEL: define {{[^@]+}}@UseLongDoubleUnsafely
37; CHECK-SAME: (%union.u* byval(%union.u) align 16 [[ARG:%.*]])
38; CHECK-NEXT:  entry:
39; CHECK-NEXT:    [[BITCAST:%.*]] = bitcast %union.u* [[ARG]] to %struct.s*
40; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [[STRUCT_S:%.*]], %struct.s* [[BITCAST]], i64 0, i32 2
41; CHECK-NEXT:    [[RESULT:%.*]] = load i8, i8* [[GEP]]
42; CHECK-NEXT:    ret i8 [[RESULT]]
43;
44entry:
45  %bitcast = bitcast %union.u* %arg to %struct.s*
46  %gep = getelementptr inbounds %struct.s, %struct.s* %bitcast, i64 0, i32 2
47  %result = load i8, i8* %gep
48  ret i8 %result
49}
50
51define internal x86_fp80 @UseLongDoubleSafely(%union.u* byval(%union.u) align 16 %arg) {
52; CHECK-LABEL: define {{[^@]+}}@UseLongDoubleSafely
53; CHECK-SAME: (x86_fp80 [[ARG_0:%.*]])
54; CHECK-NEXT:    [[ARG:%.*]] = alloca [[UNION_U:%.*]], align 16
55; CHECK-NEXT:    [[DOT0:%.*]] = getelementptr [[UNION_U]], %union.u* [[ARG]], i32 0, i32 0
56; CHECK-NEXT:    store x86_fp80 [[ARG_0]], x86_fp80* [[DOT0]]
57; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [[UNION_U]], %union.u* [[ARG]], i64 0, i32 0
58; CHECK-NEXT:    [[FP80:%.*]] = load x86_fp80, x86_fp80* [[GEP]]
59; CHECK-NEXT:    ret x86_fp80 [[FP80]]
60;
61  %gep = getelementptr inbounds %union.u, %union.u* %arg, i64 0, i32 0
62  %fp80 = load x86_fp80, x86_fp80* %gep
63  ret x86_fp80 %fp80
64}
65
66define internal i64 @AccessPaddingOfStruct(%struct.Foo* byval(%struct.Foo) %a) {
67; CHECK-LABEL: define {{[^@]+}}@AccessPaddingOfStruct
68; CHECK-SAME: (%struct.Foo* byval(%struct.Foo) [[A:%.*]])
69; CHECK-NEXT:    [[P:%.*]] = bitcast %struct.Foo* [[A]] to i64*
70; CHECK-NEXT:    [[V:%.*]] = load i64, i64* [[P]]
71; CHECK-NEXT:    ret i64 [[V]]
72;
73  %p = bitcast %struct.Foo* %a to i64*
74  %v = load i64, i64* %p
75  ret i64 %v
76}
77
78define internal i64 @CaptureAStruct(%struct.Foo* byval(%struct.Foo) %a) {
79; CHECK-LABEL: define {{[^@]+}}@CaptureAStruct
80; CHECK-SAME: (%struct.Foo* byval(%struct.Foo) [[A:%.*]])
81; CHECK-NEXT:  entry:
82; CHECK-NEXT:    [[A_PTR:%.*]] = alloca %struct.Foo*
83; CHECK-NEXT:    br label [[LOOP:%.*]]
84; CHECK:       loop:
85; CHECK-NEXT:    [[PHI:%.*]] = phi %struct.Foo* [ null, [[ENTRY:%.*]] ], [ [[GEP:%.*]], [[LOOP]] ]
86; CHECK-NEXT:    [[TMP0:%.*]] = phi %struct.Foo* [ [[A]], [[ENTRY]] ], [ [[TMP0]], [[LOOP]] ]
87; CHECK-NEXT:    store %struct.Foo* [[PHI]], %struct.Foo** [[A_PTR]]
88; CHECK-NEXT:    [[GEP]] = getelementptr [[STRUCT_FOO:%.*]], %struct.Foo* [[A]], i64 0
89; CHECK-NEXT:    br label [[LOOP]]
90;
91entry:
92  %a_ptr = alloca %struct.Foo*
93  br label %loop
94
95loop:
96  %phi = phi %struct.Foo* [ null, %entry ], [ %gep, %loop ]
97  %0   = phi %struct.Foo* [ %a, %entry ],   [ %0, %loop ]
98  store %struct.Foo* %phi, %struct.Foo** %a_ptr
99  %gep = getelementptr %struct.Foo, %struct.Foo* %a, i64 0
100  br label %loop
101}
102