1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -tailcallelim -verify-dom-info -S | FileCheck %s
4 ; the test was generated from the following C++ source:
7 ; typedef struct A { long long x[10] = {0}; } A;
9 ; void dostuff(A a, A b, int i) {
12 ; printf("%lld %lld\n", a.x[5], b.x[5]); dostuff(b, a, i+1);
14 ; __attribute((optnone)) int main() { dostuff(global, global, 0); }
16 ; This test checks that values for two ByValue operands are copied
17 ; into temporarily variables first and then the temporaily
18 ; variables are copied into original function arguments location.
20 %struct.A = type { [10 x i64] }
22 @global = dso_local local_unnamed_addr global %struct.A zeroinitializer, align 8
23 @.str = private unnamed_addr constant [11 x i8] c"%lld %lld\0A\00", align 1
25 ; Function Attrs: noinline nounwind uwtable
26 define dso_local void @_Z7dostuff1AS_i(%struct.A* nocapture byval(%struct.A) align 8 %a, %struct.A* nocapture readonly byval(%struct.A) align 8 %b, i32 %i) local_unnamed_addr #0 {
27 ; CHECK-LABEL: @_Z7dostuff1AS_i(
29 ; CHECK-NEXT: [[AGG_TMP52:%.*]] = alloca [[STRUCT_A:%.*]], align 8
30 ; CHECK-NEXT: [[AGG_TMP1:%.*]] = alloca [[STRUCT_A]], align 8
31 ; CHECK-NEXT: [[AGG_TMP:%.*]] = alloca [[STRUCT_A]], align 8
32 ; CHECK-NEXT: [[AGG_TMP5:%.*]] = alloca [[STRUCT_A]], align 8
33 ; CHECK-NEXT: br label [[TAILRECURSE:%.*]]
35 ; CHECK-NEXT: [[I_TR:%.*]] = phi i32 [ [[I:%.*]], [[ENTRY:%.*]] ], [ [[ADD:%.*]], [[IF_END:%.*]] ]
36 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I_TR]], 10
37 ; CHECK-NEXT: br i1 [[CMP]], label [[RETURN:%.*]], label [[IF_END]]
39 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [[STRUCT_A]], %struct.A* [[A:%.*]], i64 0, i32 0, i64 5
40 ; CHECK-NEXT: [[TMP0:%.*]] = load i64, i64* [[ARRAYIDX]], align 8
41 ; CHECK-NEXT: [[INC:%.*]] = add nsw i64 [[TMP0]], 1
42 ; CHECK-NEXT: store i64 [[INC]], i64* [[ARRAYIDX]], align 8
43 ; CHECK-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds [[STRUCT_A]], %struct.A* [[B:%.*]], i64 0, i32 0, i64 5
44 ; CHECK-NEXT: [[TMP1:%.*]] = load i64, i64* [[ARRAYIDX4]], align 8
45 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 [[INC]], i64 [[TMP1]])
46 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast %struct.A* [[AGG_TMP]] to i8*
47 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 80, i8* nonnull [[TMP2]])
48 ; CHECK-NEXT: [[TMP3:%.*]] = bitcast %struct.A* [[B]] to i8*
49 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 8 dereferenceable(80) [[TMP2]], i8* nonnull align 8 dereferenceable(80) [[TMP3]], i64 80, i1 false)
50 ; CHECK-NEXT: [[TMP4:%.*]] = bitcast %struct.A* [[AGG_TMP5]] to i8*
51 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 80, i8* nonnull [[TMP4]])
52 ; CHECK-NEXT: [[TMP5:%.*]] = bitcast %struct.A* [[A]] to i8*
53 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 8 dereferenceable(80) [[TMP4]], i8* nonnull align 8 dereferenceable(80) [[TMP5]], i64 80, i1 false)
54 ; CHECK-NEXT: [[ADD]] = add nsw i32 [[I_TR]], 1
55 ; CHECK-NEXT: [[TMP6:%.*]] = bitcast %struct.A* [[AGG_TMP1]] to i8*
56 ; CHECK-NEXT: [[TMP7:%.*]] = bitcast %struct.A* [[AGG_TMP]] to i8*
57 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP6]], i8* align 8 [[TMP7]], i64 80, i1 false)
58 ; CHECK-NEXT: [[TMP8:%.*]] = bitcast %struct.A* [[AGG_TMP52]] to i8*
59 ; CHECK-NEXT: [[TMP9:%.*]] = bitcast %struct.A* [[AGG_TMP5]] to i8*
60 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP8]], i8* align 8 [[TMP9]], i64 80, i1 false)
61 ; CHECK-NEXT: [[TMP10:%.*]] = bitcast %struct.A* [[A]] to i8*
62 ; CHECK-NEXT: [[TMP11:%.*]] = bitcast %struct.A* [[AGG_TMP1]] to i8*
63 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP10]], i8* align 8 [[TMP11]], i64 80, i1 false)
64 ; CHECK-NEXT: [[TMP12:%.*]] = bitcast %struct.A* [[B]] to i8*
65 ; CHECK-NEXT: [[TMP13:%.*]] = bitcast %struct.A* [[AGG_TMP52]] to i8*
66 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP12]], i8* align 8 [[TMP13]], i64 80, i1 false)
67 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 80, i8* nonnull [[TMP2]])
68 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 80, i8* nonnull [[TMP4]])
69 ; CHECK-NEXT: br label [[TAILRECURSE]]
71 ; CHECK-NEXT: ret void
74 %agg.tmp = alloca %struct.A, align 8
75 %agg.tmp5 = alloca %struct.A, align 8
76 %cmp = icmp eq i32 %i, 10
77 br i1 %cmp, label %return, label %if.end
79 if.end: ; preds = %entry
80 %arrayidx = getelementptr inbounds %struct.A, %struct.A* %a, i64 0, i32 0, i64 5
81 %0 = load i64, i64* %arrayidx, align 8
82 %inc = add nsw i64 %0, 1
83 store i64 %inc, i64* %arrayidx, align 8
84 %arrayidx4 = getelementptr inbounds %struct.A, %struct.A* %b, i64 0, i32 0, i64 5
85 %1 = load i64, i64* %arrayidx4, align 8
86 %call = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str
87 , i64 0, i64 0), i64 %inc, i64 %1)
88 %2 = bitcast %struct.A* %agg.tmp to i8*
89 call void @llvm.lifetime.start.p0i8(i64 80, i8* nonnull %2)
90 %3 = bitcast %struct.A* %b to i8*
91 call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 8 dereferenceable(80) %2, i8* nonnull align 8 dereferenceable(80) %3, i64 80, i1 false)
92 %4 = bitcast %struct.A* %agg.tmp5 to i8*
93 call void @llvm.lifetime.start.p0i8(i64 80, i8* nonnull %4)
94 %5 = bitcast %struct.A* %a to i8*
95 call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 8 dereferenceable(80) %4, i8* nonnull align 8 dereferenceable(80) %5, i64 80, i1 false)
96 %add = add nsw i32 %i, 1
97 call void @_Z7dostuff1AS_i(%struct.A* nonnull byval(%struct.A) align 8 %agg.tmp, %struct.A* nonnull byval(%struct.A) align 8 %agg.tmp5, i32 %add)
98 call void @llvm.lifetime.end.p0i8(i64 80, i8* nonnull %2)
99 call void @llvm.lifetime.end.p0i8(i64 80, i8* nonnull %4)
102 return: ; preds = %entry, %if.end
106 ; Function Attrs: nofree nounwind
107 declare dso_local noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #1
109 ; Function Attrs: argmemonly nounwind willreturn
110 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) #2
112 ; Function Attrs: argmemonly nounwind willreturn
113 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #2
115 ; Function Attrs: argmemonly nounwind willreturn
116 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #2
118 ; Function Attrs: noinline norecurse nounwind optnone uwtable
119 define dso_local i32 @main() local_unnamed_addr #3 {
120 ; CHECK-LABEL: @main(
122 ; CHECK-NEXT: [[AGG_TMP:%.*]] = alloca [[STRUCT_A:%.*]], align 8
123 ; CHECK-NEXT: [[AGG_TMP1:%.*]] = alloca [[STRUCT_A]], align 8
124 ; CHECK-NEXT: [[TMP0:%.*]] = bitcast %struct.A* [[AGG_TMP]] to i8*
125 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP0]], i8* align 8 bitcast (%struct.A* @global to i8*), i64 80, i1 false)
126 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast %struct.A* [[AGG_TMP1]] to i8*
127 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP1]], i8* align 8 bitcast (%struct.A* @global to i8*), i64 80, i1 false)
128 ; CHECK-NEXT: tail call void @_Z7dostuff1AS_i(%struct.A* byval(%struct.A) align 8 [[AGG_TMP]], %struct.A* byval(%struct.A) align 8 [[AGG_TMP1]], i32 0)
129 ; CHECK-NEXT: ret i32 0
132 %agg.tmp = alloca %struct.A, align 8
133 %agg.tmp1 = alloca %struct.A, align 8
134 %0 = bitcast %struct.A* %agg.tmp to i8*
135 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %0, i8* align 8 bitcast (%struct.A* @global to i8*), i64 80, i1 false)
136 %1 = bitcast %struct.A* %agg.tmp1 to i8*
137 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %1, i8* align 8 bitcast (%struct.A* @global to i8*), i64 80, i1 false)
138 call void @_Z7dostuff1AS_i(%struct.A* byval(%struct.A) align 8 %agg.tmp, %struct.A* byval(%struct.A) align 8 %agg.tmp1, i32 0)
142 attributes #0 = { uwtable }
143 attributes #1 = { uwtable }
144 attributes #2 = { argmemonly nounwind willreturn }