1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature
2 ; RUN: opt < %s -passes=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(ptr nocapture byval(%struct.A) align 8 %a, ptr nocapture readonly byval(%struct.A) align 8 %b, i32 %i) local_unnamed_addr #0 {
27 ; CHECK-LABEL: define {{[^@]+}}@_Z7dostuff1AS_i
28 ; CHECK-SAME: (ptr nocapture byval([[STRUCT_A:%.*]]) align 8 [[A:%.*]], ptr nocapture byval([[STRUCT_A]]) align 8 [[B:%.*]], i32 [[I:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
30 ; CHECK-NEXT: [[AGG_TMP52:%.*]] = alloca [[STRUCT_A]], align 8
31 ; CHECK-NEXT: [[AGG_TMP1:%.*]] = alloca [[STRUCT_A]], align 8
32 ; CHECK-NEXT: [[AGG_TMP:%.*]] = alloca [[STRUCT_A]], align 8
33 ; CHECK-NEXT: [[AGG_TMP5:%.*]] = alloca [[STRUCT_A]], align 8
34 ; CHECK-NEXT: br label [[TAILRECURSE:%.*]]
36 ; CHECK-NEXT: [[I_TR:%.*]] = phi i32 [ [[I]], [[ENTRY:%.*]] ], [ [[ADD:%.*]], [[IF_END:%.*]] ]
37 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I_TR]], 10
38 ; CHECK-NEXT: br i1 [[CMP]], label [[RETURN:%.*]], label [[IF_END]]
40 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [[STRUCT_A]], ptr [[A]], i64 0, i32 0, i64 5
41 ; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
42 ; CHECK-NEXT: [[INC:%.*]] = add nsw i64 [[TMP0]], 1
43 ; CHECK-NEXT: store i64 [[INC]], ptr [[ARRAYIDX]], align 8
44 ; CHECK-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds [[STRUCT_A]], ptr [[B]], i64 0, i32 0, i64 5
45 ; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[ARRAYIDX4]], align 8
46 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str, i64 [[INC]], i64 [[TMP1]])
47 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 80, ptr nonnull [[AGG_TMP]])
48 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 dereferenceable(80) [[AGG_TMP]], ptr nonnull align 8 dereferenceable(80) [[B]], i64 80, i1 false)
49 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 80, ptr nonnull [[AGG_TMP5]])
50 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 dereferenceable(80) [[AGG_TMP5]], ptr nonnull align 8 dereferenceable(80) [[A]], i64 80, i1 false)
51 ; CHECK-NEXT: [[ADD]] = add nsw i32 [[I_TR]], 1
52 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[AGG_TMP1]], ptr align 8 [[AGG_TMP]], i64 80, i1 false)
53 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[AGG_TMP52]], ptr align 8 [[AGG_TMP5]], i64 80, i1 false)
54 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[A]], ptr align 8 [[AGG_TMP1]], i64 80, i1 false)
55 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[B]], ptr align 8 [[AGG_TMP52]], i64 80, i1 false)
56 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 80, ptr nonnull [[AGG_TMP]])
57 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 80, ptr nonnull [[AGG_TMP5]])
58 ; CHECK-NEXT: br label [[TAILRECURSE]]
60 ; CHECK-NEXT: ret void
63 %agg.tmp = alloca %struct.A, align 8
64 %agg.tmp5 = alloca %struct.A, align 8
65 %cmp = icmp eq i32 %i, 10
66 br i1 %cmp, label %return, label %if.end
68 if.end: ; preds = %entry
69 %arrayidx = getelementptr inbounds %struct.A, ptr %a, i64 0, i32 0, i64 5
70 %0 = load i64, ptr %arrayidx, align 8
71 %inc = add nsw i64 %0, 1
72 store i64 %inc, ptr %arrayidx, align 8
73 %arrayidx4 = getelementptr inbounds %struct.A, ptr %b, i64 0, i32 0, i64 5
74 %1 = load i64, ptr %arrayidx4, align 8
75 %call = call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str
77 call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %agg.tmp)
78 call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 dereferenceable(80) %agg.tmp, ptr nonnull align 8 dereferenceable(80) %b, i64 80, i1 false)
79 call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %agg.tmp5)
80 call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 dereferenceable(80) %agg.tmp5, ptr nonnull align 8 dereferenceable(80) %a, i64 80, i1 false)
81 %add = add nsw i32 %i, 1
82 call void @_Z7dostuff1AS_i(ptr nonnull byval(%struct.A) align 8 %agg.tmp, ptr nonnull byval(%struct.A) align 8 %agg.tmp5, i32 %add)
83 call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %agg.tmp)
84 call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %agg.tmp5)
87 return: ; preds = %entry, %if.end
91 ; Function Attrs: nofree nounwind
92 declare dso_local noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1
94 ; Function Attrs: argmemonly nounwind willreturn
95 declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2
97 ; Function Attrs: argmemonly nounwind willreturn
98 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2
100 ; Function Attrs: argmemonly nounwind willreturn
101 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2
103 ; Function Attrs: noinline norecurse nounwind optnone uwtable
104 define dso_local i32 @main() local_unnamed_addr #3 {
105 ; CHECK-LABEL: define {{[^@]+}}@main() local_unnamed_addr {
107 ; CHECK-NEXT: [[AGG_TMP:%.*]] = alloca [[STRUCT_A:%.*]], align 8
108 ; CHECK-NEXT: [[AGG_TMP1:%.*]] = alloca [[STRUCT_A]], align 8
109 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[AGG_TMP]], ptr align 8 @global, i64 80, i1 false)
110 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[AGG_TMP1]], ptr align 8 @global, i64 80, i1 false)
111 ; CHECK-NEXT: tail call void @_Z7dostuff1AS_i(ptr byval([[STRUCT_A]]) align 8 [[AGG_TMP]], ptr byval([[STRUCT_A]]) align 8 [[AGG_TMP1]], i32 0)
112 ; CHECK-NEXT: ret i32 0
115 %agg.tmp = alloca %struct.A, align 8
116 %agg.tmp1 = alloca %struct.A, align 8
117 call void @llvm.memcpy.p0.p0.i64(ptr align 8 %agg.tmp, ptr align 8 @global, i64 80, i1 false)
118 call void @llvm.memcpy.p0.p0.i64(ptr align 8 %agg.tmp1, ptr align 8 @global, i64 80, i1 false)
119 call void @_Z7dostuff1AS_i(ptr byval(%struct.A) align 8 %agg.tmp, ptr byval(%struct.A) align 8 %agg.tmp1, i32 0)
123 attributes #0 = { uwtable }
124 attributes #1 = { uwtable }
125 attributes #2 = { argmemonly nounwind willreturn }