1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-idiom < %s -S | FileCheck %s --check-prefix=DIS-NONE
3 ; RUN: opt -passes=loop-idiom -disable-loop-idiom-all < %s -S | FileCheck %s --check-prefix=DIS-ALL
4 ; RUN: opt -passes=loop-idiom -disable-loop-idiom-memcpy < %s -S | FileCheck %s --check-prefix=DIS-MEMCPY
5 ; RUN: opt -passes=loop-idiom -disable-loop-idiom-memset < %s -S | FileCheck %s --check-prefix=DIS-MEMSET
6 ; RUN: opt -passes=loop-idiom -disable-loop-idiom-memset -disable-loop-idiom-memcpy < %s -S | FileCheck %s --check-prefix=DIS-ALL
7 ; RUN: opt -passes="loop-idiom" -aa-pipeline=basic-aa < %s -S | FileCheck %s --check-prefix=DIS-NONE
8 ; RUN: opt -passes="loop-idiom" -aa-pipeline=basic-aa -disable-loop-idiom-all < %s -S | FileCheck %s --check-prefix=DIS-ALL
9 ; RUN: opt -passes="loop-idiom" -aa-pipeline=basic-aa -disable-loop-idiom-memcpy < %s -S | FileCheck %s --check-prefix=DIS-MEMCPY
10 ; RUN: opt -passes="loop-idiom" -aa-pipeline=basic-aa -disable-loop-idiom-memset < %s -S | FileCheck %s --check-prefix=DIS-MEMSET
11 ; RUN: opt -passes="loop-idiom" -aa-pipeline=basic-aa -disable-loop-idiom-memset -disable-loop-idiom-memcpy < %s -S | FileCheck %s --check-prefix=DIS-ALL
13 define void @test-memcpy(i64 %Size) nounwind ssp {
14 ; DIS-NONE-LABEL: @test-memcpy(
15 ; DIS-NONE-NEXT: bb.nph:
16 ; DIS-NONE-NEXT: [[BASE:%.*]] = alloca i8, i32 10000, align 1
17 ; DIS-NONE-NEXT: [[DEST:%.*]] = alloca i8, i32 10000, align 1
18 ; DIS-NONE-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 [[DEST]], ptr align 1 [[BASE]], i64 [[SIZE:%.*]], i1 false)
19 ; DIS-NONE-NEXT: br label [[FOR_BODY:%.*]]
21 ; DIS-NONE-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ]
22 ; DIS-NONE-NEXT: [[I_0_014:%.*]] = getelementptr i8, ptr [[BASE]], i64 [[INDVAR]]
23 ; DIS-NONE-NEXT: [[DESTI:%.*]] = getelementptr i8, ptr [[DEST]], i64 [[INDVAR]]
24 ; DIS-NONE-NEXT: [[V:%.*]] = load i8, ptr [[I_0_014]], align 1
25 ; DIS-NONE-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
26 ; DIS-NONE-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVAR_NEXT]], [[SIZE]]
27 ; DIS-NONE-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
29 ; DIS-NONE-NEXT: ret void
31 ; DIS-ALL-LABEL: @test-memcpy(
32 ; DIS-ALL-NEXT: bb.nph:
33 ; DIS-ALL-NEXT: [[BASE:%.*]] = alloca i8, i32 10000, align 1
34 ; DIS-ALL-NEXT: [[DEST:%.*]] = alloca i8, i32 10000, align 1
35 ; DIS-ALL-NEXT: br label [[FOR_BODY:%.*]]
37 ; DIS-ALL-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ]
38 ; DIS-ALL-NEXT: [[I_0_014:%.*]] = getelementptr i8, ptr [[BASE]], i64 [[INDVAR]]
39 ; DIS-ALL-NEXT: [[DESTI:%.*]] = getelementptr i8, ptr [[DEST]], i64 [[INDVAR]]
40 ; DIS-ALL-NEXT: [[V:%.*]] = load i8, ptr [[I_0_014]], align 1
41 ; DIS-ALL-NEXT: store i8 [[V]], ptr [[DESTI]], align 1
42 ; DIS-ALL-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
43 ; DIS-ALL-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVAR_NEXT]], [[SIZE:%.*]]
44 ; DIS-ALL-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
46 ; DIS-ALL-NEXT: ret void
48 ; DIS-MEMCPY-LABEL: @test-memcpy(
49 ; DIS-MEMCPY-NEXT: bb.nph:
50 ; DIS-MEMCPY-NEXT: [[BASE:%.*]] = alloca i8, i32 10000, align 1
51 ; DIS-MEMCPY-NEXT: [[DEST:%.*]] = alloca i8, i32 10000, align 1
52 ; DIS-MEMCPY-NEXT: br label [[FOR_BODY:%.*]]
53 ; DIS-MEMCPY: for.body:
54 ; DIS-MEMCPY-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ]
55 ; DIS-MEMCPY-NEXT: [[I_0_014:%.*]] = getelementptr i8, ptr [[BASE]], i64 [[INDVAR]]
56 ; DIS-MEMCPY-NEXT: [[DESTI:%.*]] = getelementptr i8, ptr [[DEST]], i64 [[INDVAR]]
57 ; DIS-MEMCPY-NEXT: [[V:%.*]] = load i8, ptr [[I_0_014]], align 1
58 ; DIS-MEMCPY-NEXT: store i8 [[V]], ptr [[DESTI]], align 1
59 ; DIS-MEMCPY-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
60 ; DIS-MEMCPY-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVAR_NEXT]], [[SIZE:%.*]]
61 ; DIS-MEMCPY-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
62 ; DIS-MEMCPY: for.end:
63 ; DIS-MEMCPY-NEXT: ret void
65 ; DIS-MEMSET-LABEL: @test-memcpy(
66 ; DIS-MEMSET-NEXT: bb.nph:
67 ; DIS-MEMSET-NEXT: [[BASE:%.*]] = alloca i8, i32 10000, align 1
68 ; DIS-MEMSET-NEXT: [[DEST:%.*]] = alloca i8, i32 10000, align 1
69 ; DIS-MEMSET-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 [[DEST]], ptr align 1 [[BASE]], i64 [[SIZE:%.*]], i1 false)
70 ; DIS-MEMSET-NEXT: br label [[FOR_BODY:%.*]]
71 ; DIS-MEMSET: for.body:
72 ; DIS-MEMSET-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ]
73 ; DIS-MEMSET-NEXT: [[I_0_014:%.*]] = getelementptr i8, ptr [[BASE]], i64 [[INDVAR]]
74 ; DIS-MEMSET-NEXT: [[DESTI:%.*]] = getelementptr i8, ptr [[DEST]], i64 [[INDVAR]]
75 ; DIS-MEMSET-NEXT: [[V:%.*]] = load i8, ptr [[I_0_014]], align 1
76 ; DIS-MEMSET-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
77 ; DIS-MEMSET-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVAR_NEXT]], [[SIZE]]
78 ; DIS-MEMSET-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
79 ; DIS-MEMSET: for.end:
80 ; DIS-MEMSET-NEXT: ret void
83 %Base = alloca i8, i32 10000
84 %Dest = alloca i8, i32 10000
87 for.body: ; preds = %bb.nph, %for.body
88 %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
89 %I.0.014 = getelementptr i8, ptr %Base, i64 %indvar
90 %DestI = getelementptr i8, ptr %Dest, i64 %indvar
91 %V = load i8, ptr %I.0.014, align 1
92 store i8 %V, ptr %DestI, align 1
93 %indvar.next = add i64 %indvar, 1
94 %exitcond = icmp eq i64 %indvar.next, %Size
95 br i1 %exitcond, label %for.end, label %for.body
97 for.end: ; preds = %for.body, %entry
101 define void @test-memset(ptr %Base, i64 %Size) nounwind ssp {
102 ; CHECK-LABEL: @test-memset(
103 ; CHECK-NEXT: bb.nph:
104 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[BASE:%.*]], i8 0, i64 [[SIZE:%.*]], i1 false)
105 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
107 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ]
108 ; CHECK-NEXT: [[I_0_014:%.*]] = getelementptr i8, ptr [[BASE]], i64 [[INDVAR]]
109 ; CHECK-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
110 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVAR_NEXT]], [[SIZE]]
111 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
113 ; CHECK-NEXT: ret void
115 ; DIS-NONE-LABEL: @test-memset(
116 ; DIS-NONE-NEXT: bb.nph:
117 ; DIS-NONE-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[BASE:%.*]], i8 0, i64 [[SIZE:%.*]], i1 false)
118 ; DIS-NONE-NEXT: br label [[FOR_BODY:%.*]]
119 ; DIS-NONE: for.body:
120 ; DIS-NONE-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ]
121 ; DIS-NONE-NEXT: [[I_0_014:%.*]] = getelementptr i8, ptr [[BASE]], i64 [[INDVAR]]
122 ; DIS-NONE-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
123 ; DIS-NONE-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVAR_NEXT]], [[SIZE]]
124 ; DIS-NONE-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
126 ; DIS-NONE-NEXT: ret void
128 ; DIS-ALL-LABEL: @test-memset(
129 ; DIS-ALL-NEXT: bb.nph:
130 ; DIS-ALL-NEXT: br label [[FOR_BODY:%.*]]
132 ; DIS-ALL-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ]
133 ; DIS-ALL-NEXT: [[I_0_014:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 [[INDVAR]]
134 ; DIS-ALL-NEXT: store i8 0, ptr [[I_0_014]], align 1
135 ; DIS-ALL-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
136 ; DIS-ALL-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVAR_NEXT]], [[SIZE:%.*]]
137 ; DIS-ALL-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
139 ; DIS-ALL-NEXT: ret void
141 ; DIS-MEMCPY-LABEL: @test-memset(
142 ; DIS-MEMCPY-NEXT: bb.nph:
143 ; DIS-MEMCPY-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[BASE:%.*]], i8 0, i64 [[SIZE:%.*]], i1 false)
144 ; DIS-MEMCPY-NEXT: br label [[FOR_BODY:%.*]]
145 ; DIS-MEMCPY: for.body:
146 ; DIS-MEMCPY-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ]
147 ; DIS-MEMCPY-NEXT: [[I_0_014:%.*]] = getelementptr i8, ptr [[BASE]], i64 [[INDVAR]]
148 ; DIS-MEMCPY-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
149 ; DIS-MEMCPY-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVAR_NEXT]], [[SIZE]]
150 ; DIS-MEMCPY-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
151 ; DIS-MEMCPY: for.end:
152 ; DIS-MEMCPY-NEXT: ret void
154 ; DIS-MEMSET-LABEL: @test-memset(
155 ; DIS-MEMSET-NEXT: bb.nph:
156 ; DIS-MEMSET-NEXT: br label [[FOR_BODY:%.*]]
157 ; DIS-MEMSET: for.body:
158 ; DIS-MEMSET-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ]
159 ; DIS-MEMSET-NEXT: [[I_0_014:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 [[INDVAR]]
160 ; DIS-MEMSET-NEXT: store i8 0, ptr [[I_0_014]], align 1
161 ; DIS-MEMSET-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
162 ; DIS-MEMSET-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVAR_NEXT]], [[SIZE:%.*]]
163 ; DIS-MEMSET-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
164 ; DIS-MEMSET: for.end:
165 ; DIS-MEMSET-NEXT: ret void
167 bb.nph: ; preds = %entry
170 for.body: ; preds = %bb.nph, %for.body
171 %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
172 %I.0.014 = getelementptr i8, ptr %Base, i64 %indvar
173 store i8 0, ptr %I.0.014, align 1
174 %indvar.next = add i64 %indvar, 1
175 %exitcond = icmp eq i64 %indvar.next, %Size
176 br i1 %exitcond, label %for.end, label %for.body
178 for.end: ; preds = %for.body, %entry