1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -basic-aa -loop-idiom < %s -S | FileCheck %s --check-prefix=DIS-NONE
3 ; RUN: opt -basic-aa -loop-idiom -disable-loop-idiom-all < %s -S | FileCheck %s --check-prefix=DIS-ALL
4 ; RUN: opt -basic-aa -loop-idiom -disable-loop-idiom-memcpy < %s -S | FileCheck %s --check-prefix=DIS-MEMCPY
5 ; RUN: opt -basic-aa -loop-idiom -disable-loop-idiom-memset < %s -S | FileCheck %s --check-prefix=DIS-MEMSET
6 ; RUN: opt -basic-aa -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.p0i8.p0i8.i64(i8* align 1 [[DEST]], i8* 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, i8* [[BASE]], i64 [[INDVAR]]
23 ; DIS-NONE-NEXT: [[DESTI:%.*]] = getelementptr i8, i8* [[DEST]], i64 [[INDVAR]]
24 ; DIS-NONE-NEXT: [[V:%.*]] = load i8, i8* [[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, i8* [[BASE]], i64 [[INDVAR]]
39 ; DIS-ALL-NEXT: [[DESTI:%.*]] = getelementptr i8, i8* [[DEST]], i64 [[INDVAR]]
40 ; DIS-ALL-NEXT: [[V:%.*]] = load i8, i8* [[I_0_014]], align 1
41 ; DIS-ALL-NEXT: store i8 [[V]], i8* [[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, i8* [[BASE]], i64 [[INDVAR]]
56 ; DIS-MEMCPY-NEXT: [[DESTI:%.*]] = getelementptr i8, i8* [[DEST]], i64 [[INDVAR]]
57 ; DIS-MEMCPY-NEXT: [[V:%.*]] = load i8, i8* [[I_0_014]], align 1
58 ; DIS-MEMCPY-NEXT: store i8 [[V]], i8* [[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.p0i8.p0i8.i64(i8* align 1 [[DEST]], i8* 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, i8* [[BASE]], i64 [[INDVAR]]
74 ; DIS-MEMSET-NEXT: [[DESTI:%.*]] = getelementptr i8, i8* [[DEST]], i64 [[INDVAR]]
75 ; DIS-MEMSET-NEXT: [[V:%.*]] = load i8, i8* [[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, i8* %Base, i64 %indvar
90 %DestI = getelementptr i8, i8* %Dest, i64 %indvar
91 %V = load i8, i8* %I.0.014, align 1
92 store i8 %V, i8* %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(i8* %Base, i64 %Size) nounwind ssp {
102 ; CHECK-LABEL: @test-memset(
103 ; CHECK-NEXT: bb.nph:
104 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* 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, i8* [[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-ALL-LABEL: @test-memset(
116 ; DIS-ALL-NEXT: bb.nph:
117 ; DIS-ALL-NEXT: br label [[FOR_BODY:%.*]]
119 ; DIS-ALL-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ]
120 ; DIS-ALL-NEXT: [[I_0_014:%.*]] = getelementptr i8, i8* [[BASE:%.*]], i64 [[INDVAR]]
121 ; DIS-ALL-NEXT: store i8 0, i8* [[I_0_014]], align 1
122 ; DIS-ALL-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
123 ; DIS-ALL-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVAR_NEXT]], [[SIZE:%.*]]
124 ; DIS-ALL-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
126 ; DIS-ALL-NEXT: ret void
128 ; DIS-MEMCPY-LABEL: @test-memset(
129 ; DIS-MEMCPY-NEXT: bb.nph:
130 ; DIS-MEMCPY-NEXT: call void @llvm.memset.p0i8.i64(i8* align 1 [[BASE:%.*]], i8 0, i64 [[SIZE:%.*]], i1 false)
131 ; DIS-MEMCPY-NEXT: br label [[FOR_BODY:%.*]]
132 ; DIS-MEMCPY: for.body:
133 ; DIS-MEMCPY-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ]
134 ; DIS-MEMCPY-NEXT: [[I_0_014:%.*]] = getelementptr i8, i8* [[BASE]], i64 [[INDVAR]]
135 ; DIS-MEMCPY-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
136 ; DIS-MEMCPY-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVAR_NEXT]], [[SIZE]]
137 ; DIS-MEMCPY-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
138 ; DIS-MEMCPY: for.end:
139 ; DIS-MEMCPY-NEXT: ret void
141 ; DIS-MEMSET-LABEL: @test-memset(
142 ; DIS-MEMSET-NEXT: bb.nph:
143 ; DIS-MEMSET-NEXT: br label [[FOR_BODY:%.*]]
144 ; DIS-MEMSET: for.body:
145 ; DIS-MEMSET-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[BB_NPH:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ]
146 ; DIS-MEMSET-NEXT: [[I_0_014:%.*]] = getelementptr i8, i8* [[BASE:%.*]], i64 [[INDVAR]]
147 ; DIS-MEMSET-NEXT: store i8 0, i8* [[I_0_014]], align 1
148 ; DIS-MEMSET-NEXT: [[INDVAR_NEXT]] = add i64 [[INDVAR]], 1
149 ; DIS-MEMSET-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVAR_NEXT]], [[SIZE:%.*]]
150 ; DIS-MEMSET-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
151 ; DIS-MEMSET: for.end:
152 ; DIS-MEMSET-NEXT: ret void
154 bb.nph: ; preds = %entry
157 for.body: ; preds = %bb.nph, %for.body
158 %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
159 %I.0.014 = getelementptr i8, i8* %Base, i64 %indvar
160 store i8 0, i8* %I.0.014, align 1
161 %indvar.next = add i64 %indvar, 1
162 %exitcond = icmp eq i64 %indvar.next, %Size
163 br i1 %exitcond, label %for.end, label %for.body
165 for.end: ; preds = %for.body, %entry