1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -basic-aa -loop-idiom < %s -S | FileCheck %s
4 define void @copy_both_noalias(float* noalias nocapture %d, float* noalias nocapture readonly %s, i64 %sz) {
5 ; CHECK-LABEL: @copy_both_noalias(
7 ; CHECK-NEXT: [[D1:%.*]] = bitcast float* [[D:%.*]] to i8*
8 ; CHECK-NEXT: [[S2:%.*]] = bitcast float* [[S:%.*]] to i8*
9 ; CHECK-NEXT: [[EXITCOND_NOT1:%.*]] = icmp eq i64 [[SZ:%.*]], 0
10 ; CHECK-NEXT: br i1 [[EXITCOND_NOT1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
11 ; CHECK: for.body.preheader:
12 ; CHECK-NEXT: [[TMP0:%.*]] = shl nuw i64 [[SZ]], 2
13 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[D1]], i8* align 4 [[S2]], i64 [[TMP0]], i1 false)
14 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
16 ; CHECK-NEXT: [[I_04:%.*]] = phi i64 [ [[INC:%.*]], [[FOR_BODY]] ], [ 0, [[FOR_BODY_PREHEADER]] ]
17 ; CHECK-NEXT: [[D_ADDR_03:%.*]] = phi float* [ [[INCDEC_PTR1:%.*]], [[FOR_BODY]] ], [ [[D]], [[FOR_BODY_PREHEADER]] ]
18 ; CHECK-NEXT: [[S_ADDR_02:%.*]] = phi float* [ [[INCDEC_PTR:%.*]], [[FOR_BODY]] ], [ [[S]], [[FOR_BODY_PREHEADER]] ]
19 ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds float, float* [[S_ADDR_02]], i64 1
20 ; CHECK-NEXT: [[TMP1:%.*]] = load float, float* [[S_ADDR_02]], align 4
21 ; CHECK-NEXT: [[INCDEC_PTR1]] = getelementptr inbounds float, float* [[D_ADDR_03]], i64 1
22 ; CHECK-NEXT: [[INC]] = add i64 [[I_04]], 1
23 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INC]], [[SZ]]
24 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END_LOOPEXIT:%.*]], label [[FOR_BODY]]
25 ; CHECK: for.end.loopexit:
26 ; CHECK-NEXT: br label [[FOR_END]]
28 ; CHECK-NEXT: ret void
31 %exitcond.not1 = icmp eq i64 %sz, 0
32 br i1 %exitcond.not1, label %for.end, label %for.body.preheader
34 for.body.preheader: ; preds = %entry
37 for.body: ; preds = %for.body.preheader, %for.body
38 %i.04 = phi i64 [ %inc, %for.body ], [ 0, %for.body.preheader ]
39 %d.addr.03 = phi float* [ %incdec.ptr1, %for.body ], [ %d, %for.body.preheader ]
40 %s.addr.02 = phi float* [ %incdec.ptr, %for.body ], [ %s, %for.body.preheader ]
41 %incdec.ptr = getelementptr inbounds float, float* %s.addr.02, i64 1
42 %0 = load float, float* %s.addr.02, align 4
43 %incdec.ptr1 = getelementptr inbounds float, float* %d.addr.03, i64 1
44 store float %0, float* %d.addr.03, align 4
45 %inc = add i64 %i.04, 1
46 %exitcond.not = icmp eq i64 %inc, %sz
47 br i1 %exitcond.not, label %for.end.loopexit, label %for.body
49 for.end.loopexit: ; preds = %for.body
52 for.end: ; preds = %for.end.loopexit, %entry
56 define void @copy_one_noalias(float* nocapture %d, float* noalias nocapture readonly %s, i64 %sz) {
57 ; CHECK-LABEL: @copy_one_noalias(
59 ; CHECK-NEXT: [[D1:%.*]] = bitcast float* [[D:%.*]] to i8*
60 ; CHECK-NEXT: [[S2:%.*]] = bitcast float* [[S:%.*]] to i8*
61 ; CHECK-NEXT: [[EXITCOND_NOT1:%.*]] = icmp eq i64 [[SZ:%.*]], 0
62 ; CHECK-NEXT: br i1 [[EXITCOND_NOT1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
63 ; CHECK: for.body.preheader:
64 ; CHECK-NEXT: [[TMP0:%.*]] = shl nuw i64 [[SZ]], 2
65 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[D1]], i8* align 4 [[S2]], i64 [[TMP0]], i1 false)
66 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
68 ; CHECK-NEXT: [[I_04:%.*]] = phi i64 [ [[INC:%.*]], [[FOR_BODY]] ], [ 0, [[FOR_BODY_PREHEADER]] ]
69 ; CHECK-NEXT: [[D_ADDR_03:%.*]] = phi float* [ [[INCDEC_PTR1:%.*]], [[FOR_BODY]] ], [ [[D]], [[FOR_BODY_PREHEADER]] ]
70 ; CHECK-NEXT: [[S_ADDR_02:%.*]] = phi float* [ [[INCDEC_PTR:%.*]], [[FOR_BODY]] ], [ [[S]], [[FOR_BODY_PREHEADER]] ]
71 ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds float, float* [[S_ADDR_02]], i64 1
72 ; CHECK-NEXT: [[TMP1:%.*]] = load float, float* [[S_ADDR_02]], align 4
73 ; CHECK-NEXT: [[INCDEC_PTR1]] = getelementptr inbounds float, float* [[D_ADDR_03]], i64 1
74 ; CHECK-NEXT: [[INC]] = add i64 [[I_04]], 1
75 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INC]], [[SZ]]
76 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END_LOOPEXIT:%.*]], label [[FOR_BODY]]
77 ; CHECK: for.end.loopexit:
78 ; CHECK-NEXT: br label [[FOR_END]]
80 ; CHECK-NEXT: ret void
83 %exitcond.not1 = icmp eq i64 %sz, 0
84 br i1 %exitcond.not1, label %for.end, label %for.body.preheader
86 for.body.preheader: ; preds = %entry
89 for.body: ; preds = %for.body.preheader, %for.body
90 %i.04 = phi i64 [ %inc, %for.body ], [ 0, %for.body.preheader ]
91 %d.addr.03 = phi float* [ %incdec.ptr1, %for.body ], [ %d, %for.body.preheader ]
92 %s.addr.02 = phi float* [ %incdec.ptr, %for.body ], [ %s, %for.body.preheader ]
93 %incdec.ptr = getelementptr inbounds float, float* %s.addr.02, i64 1
94 %0 = load float, float* %s.addr.02, align 4
95 %incdec.ptr1 = getelementptr inbounds float, float* %d.addr.03, i64 1
96 store float %0, float* %d.addr.03, align 4
97 %inc = add i64 %i.04, 1
98 %exitcond.not = icmp eq i64 %inc, %sz
99 br i1 %exitcond.not, label %for.end.loopexit, label %for.body
101 for.end.loopexit: ; preds = %for.body
104 for.end: ; preds = %for.end.loopexit, %entry
109 define dso_local void @memcpy_loop(i8* noalias nocapture %p, i8* noalias nocapture readonly %q, i32 %n) {
110 ; CHECK-LABEL: @memcpy_loop(
112 ; CHECK-NEXT: [[CMP4:%.*]] = icmp sgt i32 [[N:%.*]], 0
113 ; CHECK-NEXT: br i1 [[CMP4]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
114 ; CHECK: for.body.preheader:
115 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[N]] to i64
116 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 [[P:%.*]], i8* align 1 [[Q:%.*]], i64 [[TMP0]], i1 false)
117 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
118 ; CHECK: for.cond.cleanup.loopexit:
119 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
120 ; CHECK: for.cond.cleanup:
121 ; CHECK-NEXT: ret void
123 ; CHECK-NEXT: [[I_07:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_BODY]] ], [ 0, [[FOR_BODY_PREHEADER]] ]
124 ; CHECK-NEXT: [[P_ADDR_06:%.*]] = phi i8* [ [[INCDEC_PTR1:%.*]], [[FOR_BODY]] ], [ [[P]], [[FOR_BODY_PREHEADER]] ]
125 ; CHECK-NEXT: [[Q_ADDR_05:%.*]] = phi i8* [ [[INCDEC_PTR:%.*]], [[FOR_BODY]] ], [ [[Q]], [[FOR_BODY_PREHEADER]] ]
126 ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i8, i8* [[Q_ADDR_05]], i64 1
127 ; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[Q_ADDR_05]], align 1
128 ; CHECK-NEXT: [[INCDEC_PTR1]] = getelementptr inbounds i8, i8* [[P_ADDR_06]], i64 1
129 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_07]], 1
130 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i32 [[INC]], [[N]]
131 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_BODY]]
134 %cmp4 = icmp sgt i32 %n, 0
135 br i1 %cmp4, label %for.body, label %for.cond.cleanup
141 %i.07 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
142 %p.addr.06 = phi i8* [ %incdec.ptr1, %for.body ], [ %p, %entry ]
143 %q.addr.05 = phi i8* [ %incdec.ptr, %for.body ], [ %q, %entry ]
144 %incdec.ptr = getelementptr inbounds i8, i8* %q.addr.05, i64 1
145 %0 = load i8, i8* %q.addr.05, align 1
146 %incdec.ptr1 = getelementptr inbounds i8, i8* %p.addr.06, i64 1
147 store i8 %0, i8* %p.addr.06, align 1
148 %inc = add nuw nsw i32 %i.07, 1
149 %exitcond.not = icmp eq i32 %inc, %n
150 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body