1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-idiom < %s -S | FileCheck %s
3 target datalayout = "e-p:64:64:64:32-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"
5 ; CHECK: @.memset_pattern = private unnamed_addr constant [4 x i32] [i32 2, i32 2, i32 2, i32 2], align 16
7 target triple = "x86_64-apple-darwin10.0.0"
9 ;void test(int *f, unsigned n) {
10 ; for (unsigned i = 0; i < 2 * n; i += 2) {
15 define void @test(ptr %f, i32 %n) nounwind ssp {
18 ; CHECK-NEXT: [[TMP0:%.*]] = shl i32 [[N:%.*]], 1
19 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[TMP0]], 0
20 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
21 ; CHECK: for.body.preheader:
22 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[TMP0]], -1
23 ; CHECK-NEXT: [[TMP2:%.*]] = lshr i32 [[TMP1]], 1
24 ; CHECK-NEXT: [[TMP3:%.*]] = shl i32 [[TMP2]], 3
25 ; CHECK-NEXT: [[TMP4:%.*]] = add i32 [[TMP3]], 8
26 ; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 4 [[F:%.*]], i8 0, i32 [[TMP4]], i1 false)
27 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
29 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
30 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[F]], i32 [[INDVARS_IV]]
31 ; CHECK-NEXT: [[TMP5:%.*]] = or i32 [[INDVARS_IV]], 1
32 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[F]], i32 [[TMP5]]
33 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 2
34 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[INDVARS_IV_NEXT]], [[TMP0]]
35 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
36 ; CHECK: for.end.loopexit:
37 ; CHECK-NEXT: br label [[FOR_END]]
39 ; CHECK-NEXT: ret void
43 %cmp1 = icmp eq i32 %0, 0
44 br i1 %cmp1, label %for.end, label %for.body.preheader
46 for.body.preheader: ; preds = %entry
49 for.body: ; preds = %for.body.preheader, %for.body
50 %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
51 %arrayidx = getelementptr inbounds i32, ptr %f, i32 %indvars.iv
52 store i32 0, ptr %arrayidx, align 4
53 %1 = or i32 %indvars.iv, 1
54 %arrayidx2 = getelementptr inbounds i32, ptr %f, i32 %1
55 store i32 0, ptr %arrayidx2, align 4
56 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 2
57 %cmp = icmp ult i32 %indvars.iv.next, %0
58 br i1 %cmp, label %for.body, label %for.end.loopexit
60 for.end.loopexit: ; preds = %for.body
63 for.end: ; preds = %for.end.loopexit, %entry
67 ;void test_pattern(int *f, unsigned n) {
68 ; for (unsigned i = 0; i < 2 * n; i += 2) {
73 define void @test_pattern(ptr %f, i32 %n) nounwind ssp {
74 ; CHECK-LABEL: @test_pattern(
76 ; CHECK-NEXT: [[MUL:%.*]] = shl i32 [[N:%.*]], 1
77 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[MUL]], 0
78 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
79 ; CHECK: for.body.preheader:
80 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[MUL]], -1
81 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[TMP0]], 1
82 ; CHECK-NEXT: [[TMP2:%.*]] = shl i32 [[TMP1]], 3
83 ; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[TMP2]], 8
84 ; CHECK-NEXT: call void @memset_pattern16(ptr [[F:%.*]], ptr @.memset_pattern, i32 [[TMP3]])
85 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
87 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
88 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[F]], i32 [[INDVARS_IV]]
89 ; CHECK-NEXT: [[X1:%.*]] = or i32 [[INDVARS_IV]], 1
90 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[F]], i32 [[X1]]
91 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 2
92 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[INDVARS_IV_NEXT]], [[MUL]]
93 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
94 ; CHECK: for.end.loopexit:
95 ; CHECK-NEXT: br label [[FOR_END]]
97 ; CHECK-NEXT: ret void
101 %cmp1 = icmp eq i32 %mul, 0
102 br i1 %cmp1, label %for.end, label %for.body.preheader
104 for.body.preheader: ; preds = %entry
107 for.body: ; preds = %for.body.preheader, %for.body
108 %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
109 %arrayidx = getelementptr inbounds i32, ptr %f, i32 %indvars.iv
110 store i32 2, ptr %arrayidx, align 4
111 %x1 = or i32 %indvars.iv, 1
112 %arrayidx2 = getelementptr inbounds i32, ptr %f, i32 %x1
113 store i32 2, ptr %arrayidx2, align 4
114 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 2
115 %cmp = icmp ult i32 %indvars.iv.next, %mul
116 br i1 %cmp, label %for.body, label %for.end.loopexit
118 for.end.loopexit: ; preds = %for.body
121 for.end: ; preds = %for.end.loopexit, %entry