1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -debugify -loop-idiom -pass-remarks=loop-idiom -pass-remarks-analysis=loop-idiom -verify -verify-each -verify-dom-info -verify-loop-info < %s -S 2>&1 | FileCheck %s
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
6 ; Check that everything still works when debuginfo is present, and that it is reasonably propagated.
10 ; bool index_iteration_eq_variable_size_no_overlap(char const* ptr, size_t count) {
11 ; char const* ptr0 = ptr;
12 ; char const* ptr1 = ptr + count;
13 ; for(size_t i = 0; i < count; i++) {
14 ; if(ptr0[i] != ptr1[i])
21 ; void loop_within_loop(size_t outer_count, char const** ptr0, char const** ptr1, size_t* count) {
22 ; for(size_t i = 0; i != outer_count; ++i)
23 ; sink(std::equal(ptr0[i], ptr0[i] + count[i], ptr1[i]));
26 ; CHECK: remark: <stdin>:13:1: Loop recognized as a bcmp idiom
27 ; CHECK: remark: <stdin>:11:1: Transformed bcmp idiom into a call to memcmp() function
28 ; CHECK: remark: <stdin>:29:1: Loop recognized as a bcmp idiom
29 ; CHECK: remark: <stdin>:34:1: Transformed bcmp idiom into a call to memcmp() function
31 define i1 @_Z43index_iteration_eq_variable_size_no_overlapPKcm(i8* nocapture %ptr, i64 %count) {
32 ; CHECK-LABEL: @_Z43index_iteration_eq_variable_size_no_overlapPKcm(
34 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[PTR:%.*]], i64 [[COUNT_BYTECOUNT:%.*]], !dbg !22
35 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[ADD_PTR]], metadata !9, metadata !DIExpression()), !dbg !22
36 ; CHECK-NEXT: [[CMP14:%.*]] = icmp eq i64 [[COUNT_BYTECOUNT]], 0, !dbg !23
37 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[CMP14]], metadata !11, metadata !DIExpression()), !dbg !23
38 ; CHECK-NEXT: br i1 [[CMP14]], label [[CLEANUP:%.*]], label [[FOR_BODY_BCMPDISPATCHBB:%.*]], !dbg !24
39 ; CHECK: for.body.bcmpdispatchbb:
40 ; CHECK-NEXT: [[MEMCMP:%.*]] = call i32 @memcmp(i8* [[PTR]], i8* [[ADD_PTR]], i64 [[COUNT_BYTECOUNT]]), !dbg !25
41 ; CHECK-NEXT: [[PTR_VS_ADD_PTR_EQCMP:%.*]] = icmp eq i32 [[MEMCMP]], 0, !dbg !25
42 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !14, metadata !DIExpression()), !dbg !26
43 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !15, metadata !DIExpression()), !dbg !27
44 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !16, metadata !DIExpression()), !dbg !28
45 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !17, metadata !DIExpression()), !dbg !29
46 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !18, metadata !DIExpression()), !dbg !30
47 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !19, metadata !DIExpression()), !dbg !25
48 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !20, metadata !DIExpression()), !dbg !31
49 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !13, metadata !DIExpression()), !dbg !32
50 ; CHECK-NEXT: br i1 [[PTR_VS_ADD_PTR_EQCMP]], label [[PTR_VS_ADD_PTR_EQCMP_EQUALBB:%.*]], label [[PTR_VS_ADD_PTR_EQCMP_UNEQUALBB:%.*]], !dbg !25
51 ; CHECK: ptr.vs.add.ptr.eqcmp.equalbb:
52 ; CHECK-NEXT: br label [[CLEANUP_LOOPEXIT:%.*]], !dbg !33
53 ; CHECK: ptr.vs.add.ptr.eqcmp.unequalbb:
54 ; CHECK-NEXT: br label [[CLEANUP_LOOPEXIT]], !dbg !34
55 ; CHECK: cleanup.loopexit:
56 ; CHECK-NEXT: [[RES_PH:%.*]] = phi i1 [ false, [[PTR_VS_ADD_PTR_EQCMP_UNEQUALBB]] ], [ true, [[PTR_VS_ADD_PTR_EQCMP_EQUALBB]] ]
57 ; CHECK-NEXT: br label [[CLEANUP]], !dbg !35
59 ; CHECK-NEXT: [[RES:%.*]] = phi i1 [ true, [[ENTRY:%.*]] ], [ [[RES_PH]], [[CLEANUP_LOOPEXIT]] ], !dbg !36
60 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[RES]], metadata !21, metadata !DIExpression()), !dbg !36
61 ; CHECK-NEXT: ret i1 [[RES]], !dbg !35
64 %add.ptr = getelementptr inbounds i8, i8* %ptr, i64 %count
65 %cmp14 = icmp eq i64 %count, 0
66 br i1 %cmp14, label %cleanup, label %for.body
68 for.cond: ; preds = %for.body
69 %cmp = icmp ult i64 %inc, %count
70 br i1 %cmp, label %for.body, label %cleanup
72 for.body: ; preds = %entry, %for.cond
73 %i.015 = phi i64 [ %inc, %for.cond ], [ 0, %entry ]
74 %arrayidx = getelementptr inbounds i8, i8* %ptr, i64 %i.015
75 %v0 = load i8, i8* %arrayidx
76 %arrayidx1 = getelementptr inbounds i8, i8* %add.ptr, i64 %i.015
77 %v1 = load i8, i8* %arrayidx1
78 %cmp3 = icmp eq i8 %v0, %v1
79 %inc = add nuw i64 %i.015, 1
80 br i1 %cmp3, label %for.cond, label %cleanup
82 cleanup: ; preds = %for.body, %for.cond, %entry
83 %res = phi i1 [ true, %entry ], [ true, %for.cond ], [ false, %for.body ]
87 define void @_Z16loop_within_loopmPPKcS1_Pm(i64 %outer_count, i8** %ptr0, i8** %ptr1, i64* %count) {
88 ; CHECK-LABEL: @_Z16loop_within_loopmPPKcS1_Pm(
90 ; CHECK-NEXT: [[CMP11:%.*]] = icmp eq i64 [[OUTER_COUNT:%.*]], 0, !dbg !60
91 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[CMP11]], metadata !39, metadata !DIExpression()), !dbg !60
92 ; CHECK-NEXT: br i1 [[CMP11]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY_PREHEADER:%.*]], !dbg !61
93 ; CHECK: for.body.preheader:
94 ; CHECK-NEXT: br label [[FOR_BODY:%.*]], !dbg !62
95 ; CHECK: for.cond.cleanup.loopexit:
96 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]], !dbg !63
97 ; CHECK: for.cond.cleanup:
98 ; CHECK-NEXT: ret void, !dbg !63
100 ; CHECK-NEXT: [[I_012:%.*]] = phi i64 [ [[INC:%.*]], [[_ZNST3__15EQUALIPKCS2_EEBT_S3_T0__EXIT:%.*]] ], [ 0, [[FOR_BODY_PREHEADER]] ], !dbg !64
101 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 [[I_012]], metadata !40, metadata !DIExpression()), !dbg !64
102 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8*, i8** [[PTR0:%.*]], i64 [[I_012]], !dbg !65
103 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i8** [[ARRAYIDX]], metadata !41, metadata !DIExpression()), !dbg !65
104 ; CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[ARRAYIDX]], !dbg !66
105 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[T0]], metadata !42, metadata !DIExpression()), !dbg !66
106 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i64, i64* [[COUNT:%.*]], i64 [[I_012]], !dbg !67
107 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i64* [[ARRAYIDX2]], metadata !43, metadata !DIExpression()), !dbg !67
108 ; CHECK-NEXT: [[T1_BYTECOUNT:%.*]] = load i64, i64* [[ARRAYIDX2]], !dbg !68
109 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 [[T1_BYTECOUNT]], metadata !44, metadata !DIExpression()), !dbg !68
110 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[T0]], i64 [[T1_BYTECOUNT]], !dbg !69
111 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[ADD_PTR]], metadata !45, metadata !DIExpression()), !dbg !69
112 ; CHECK-NEXT: [[CMP5_I_I:%.*]] = icmp eq i64 [[T1_BYTECOUNT]], 0, !dbg !70
113 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[CMP5_I_I]], metadata !46, metadata !DIExpression()), !dbg !70
114 ; CHECK-NEXT: br i1 [[CMP5_I_I]], label [[_ZNST3__15EQUALIPKCS2_EEBT_S3_T0__EXIT]], label [[FOR_BODY_I_I_PREHEADER:%.*]], !dbg !62
115 ; CHECK: for.body.i.i.preheader:
116 ; CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds i8*, i8** [[PTR1:%.*]], i64 [[I_012]], !dbg !71
117 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i8** [[ARRAYIDX3]], metadata !47, metadata !DIExpression()), !dbg !71
118 ; CHECK-NEXT: [[T2:%.*]] = load i8*, i8** [[ARRAYIDX3]], !dbg !72
119 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* [[T2]], metadata !48, metadata !DIExpression()), !dbg !72
120 ; CHECK-NEXT: [[MEMCMP:%.*]] = call i32 @memcmp(i8* [[T0]], i8* [[T2]], i64 [[T1_BYTECOUNT]]), !dbg !73
121 ; CHECK-NEXT: [[T0_VS_T2_EQCMP:%.*]] = icmp eq i32 [[MEMCMP]], 0, !dbg !73
122 ; CHECK-NEXT: br label [[FOR_BODY_I_I_BCMPDISPATCHBB:%.*]]
123 ; CHECK: for.body.i.i.bcmpdispatchbb:
124 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !49, metadata !DIExpression()), !dbg !74
125 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !50, metadata !DIExpression()), !dbg !75
126 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !51, metadata !DIExpression()), !dbg !76
127 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !52, metadata !DIExpression()), !dbg !77
128 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !53, metadata !DIExpression()), !dbg !73
129 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !54, metadata !DIExpression()), !dbg !78
130 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !55, metadata !DIExpression()), !dbg !79
131 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 undef, metadata !56, metadata !DIExpression()), !dbg !80
132 ; CHECK-NEXT: br i1 [[T0_VS_T2_EQCMP]], label [[T0_VS_T2_EQCMP_EQUALBB:%.*]], label [[T0_VS_T2_EQCMP_UNEQUALBB:%.*]], !dbg !73
133 ; CHECK: t0.vs.t2.eqcmp.equalbb:
134 ; CHECK-NEXT: br i1 true, label [[_ZNST3__15EQUALIPKCS2_EEBT_S3_T0__EXIT_LOOPEXIT:%.*]], label [[FOR_BODY_I_I_BCMPDISPATCHBB]], !dbg !81
135 ; CHECK: t0.vs.t2.eqcmp.unequalbb:
136 ; CHECK-NEXT: br i1 true, label [[_ZNST3__15EQUALIPKCS2_EEBT_S3_T0__EXIT_LOOPEXIT]], label [[FOR_BODY_I_I_BCMPDISPATCHBB]], !dbg !82
137 ; CHECK: _ZNSt3__15equalIPKcS2_EEbT_S3_T0_.exit.loopexit:
138 ; CHECK-NEXT: [[RETVAL_0_I_I_PH:%.*]] = phi i1 [ false, [[T0_VS_T2_EQCMP_UNEQUALBB]] ], [ true, [[T0_VS_T2_EQCMP_EQUALBB]] ]
139 ; CHECK-NEXT: br label [[_ZNST3__15EQUALIPKCS2_EEBT_S3_T0__EXIT]], !dbg !83
140 ; CHECK: _ZNSt3__15equalIPKcS2_EEbT_S3_T0_.exit:
141 ; CHECK-NEXT: [[RETVAL_0_I_I:%.*]] = phi i1 [ true, [[FOR_BODY]] ], [ [[RETVAL_0_I_I_PH]], [[_ZNST3__15EQUALIPKCS2_EEBT_S3_T0__EXIT_LOOPEXIT]] ], !dbg !84
142 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[RETVAL_0_I_I]], metadata !57, metadata !DIExpression()), !dbg !84
143 ; CHECK-NEXT: tail call void @_Z4sinkb(i1 [[RETVAL_0_I_I]]), !dbg !83
144 ; CHECK-NEXT: [[INC]] = add nuw i64 [[I_012]], 1, !dbg !85
145 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 [[INC]], metadata !58, metadata !DIExpression()), !dbg !85
146 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[INC]], [[OUTER_COUNT]], !dbg !86
147 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[CMP]], metadata !59, metadata !DIExpression()), !dbg !86
148 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY]], !dbg !87
151 %cmp11 = icmp eq i64 %outer_count, 0
152 br i1 %cmp11, label %for.cond.cleanup, label %for.body
154 for.cond.cleanup: ; preds = %_ZNSt3__15equalIPKcS2_EEbT_S3_T0_.exit, %entry
157 for.body: ; preds = %entry, %_ZNSt3__15equalIPKcS2_EEbT_S3_T0_.exit
158 %i.012 = phi i64 [ %inc, %_ZNSt3__15equalIPKcS2_EEbT_S3_T0_.exit ], [ 0, %entry ]
159 %arrayidx = getelementptr inbounds i8*, i8** %ptr0, i64 %i.012
160 %t0 = load i8*, i8** %arrayidx
161 %arrayidx2 = getelementptr inbounds i64, i64* %count, i64 %i.012
162 %t1 = load i64, i64* %arrayidx2
163 %add.ptr = getelementptr inbounds i8, i8* %t0, i64 %t1
164 %cmp5.i.i = icmp eq i64 %t1, 0
165 br i1 %cmp5.i.i, label %_ZNSt3__15equalIPKcS2_EEbT_S3_T0_.exit, label %for.body.i.i.preheader
167 for.body.i.i.preheader: ; preds = %for.body
168 %arrayidx3 = getelementptr inbounds i8*, i8** %ptr1, i64 %i.012
169 %t2 = load i8*, i8** %arrayidx3
170 br label %for.body.i.i
172 for.body.i.i: ; preds = %for.body.i.i.preheader, %for.inc.i.i
173 %__first2.addr.07.i.i = phi i8* [ %incdec.ptr1.i.i, %for.inc.i.i ], [ %t2, %for.body.i.i.preheader ]
174 %__first1.addr.06.i.i = phi i8* [ %incdec.ptr.i.i, %for.inc.i.i ], [ %t0, %for.body.i.i.preheader ]
175 %t3 = load i8, i8* %__first1.addr.06.i.i
176 %t4 = load i8, i8* %__first2.addr.07.i.i
177 %cmp.i.i.i = icmp eq i8 %t3, %t4
178 br i1 %cmp.i.i.i, label %for.inc.i.i, label %_ZNSt3__15equalIPKcS2_EEbT_S3_T0_.exit
180 for.inc.i.i: ; preds = %for.body.i.i
181 %incdec.ptr.i.i = getelementptr inbounds i8, i8* %__first1.addr.06.i.i, i64 1
182 %incdec.ptr1.i.i = getelementptr inbounds i8, i8* %__first2.addr.07.i.i, i64 1
183 %cmp.i.i = icmp eq i8* %incdec.ptr.i.i, %add.ptr
184 br i1 %cmp.i.i, label %_ZNSt3__15equalIPKcS2_EEbT_S3_T0_.exit, label %for.body.i.i
186 _ZNSt3__15equalIPKcS2_EEbT_S3_T0_.exit: ; preds = %for.body.i.i, %for.inc.i.i, %for.body
187 %retval.0.i.i = phi i1 [ true, %for.body ], [ true, %for.inc.i.i ], [ false, %for.body.i.i ]
188 tail call void @_Z4sinkb(i1 %retval.0.i.i)
189 %inc = add nuw i64 %i.012, 1
190 %cmp = icmp eq i64 %inc, %outer_count
191 br i1 %cmp, label %for.cond.cleanup, label %for.body
193 declare void @_Z4sinkb(i1)