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-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: [[MUL:%.*]] = shl i32 [[N:%.*]], 1
19 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[MUL]], 0
20 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
21 ; CHECK: for.body.preheader:
22 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[MUL]] to i64
23 ; CHECK-NEXT: [[TMP1:%.*]] = add nsw i64 [[TMP0]], -1
24 ; CHECK-NEXT: [[TMP2:%.*]] = lshr i64 [[TMP1]], 1
25 ; CHECK-NEXT: [[TMP3:%.*]] = shl i64 [[TMP2]], 3
26 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[TMP3]], 8
27 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[F:%.*]], i8 0, i64 [[TMP4]], i1 false)
28 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
30 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
31 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[F]], i64 [[INDVARS_IV]]
32 ; CHECK-NEXT: [[TMP5:%.*]] = or disjoint i64 [[INDVARS_IV]], 1
33 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[F]], i64 [[TMP5]]
34 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 2
35 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[INDVARS_IV_NEXT]], [[TMP0]]
36 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
37 ; CHECK: for.end.loopexit:
38 ; CHECK-NEXT: br label [[FOR_END]]
40 ; CHECK-NEXT: ret void
44 %cmp1 = icmp eq i32 %mul, 0
45 br i1 %cmp1, label %for.end, label %for.body.preheader
47 for.body.preheader: ; preds = %entry
48 %0 = zext i32 %mul to i64
51 for.body: ; preds = %for.body.preheader, %for.body
52 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
53 %arrayidx = getelementptr inbounds i32, ptr %f, i64 %indvars.iv
54 store i32 0, ptr %arrayidx, align 4
55 %1 = or disjoint i64 %indvars.iv, 1
56 %arrayidx2 = getelementptr inbounds i32, ptr %f, i64 %1
57 store i32 0, ptr %arrayidx2, align 4
58 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
59 %cmp = icmp ult i64 %indvars.iv.next, %0
60 br i1 %cmp, label %for.body, label %for.end.loopexit
62 for.end.loopexit: ; preds = %for.body
65 for.end: ; preds = %for.end.loopexit, %entry
69 ;void test_pattern(int *f, unsigned n) {
70 ; for (unsigned i = 0; i < 2 * n; i += 2) {
75 define void @test_pattern(ptr %f, i32 %n) nounwind ssp {
76 ; CHECK-LABEL: @test_pattern(
78 ; CHECK-NEXT: [[MUL:%.*]] = shl i32 [[N:%.*]], 1
79 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[MUL]], 0
80 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
81 ; CHECK: for.body.preheader:
82 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[MUL]] to i64
83 ; CHECK-NEXT: [[TMP1:%.*]] = add nsw i64 [[TMP0]], -1
84 ; CHECK-NEXT: [[TMP2:%.*]] = lshr i64 [[TMP1]], 1
85 ; CHECK-NEXT: [[TMP3:%.*]] = shl i64 [[TMP2]], 3
86 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[TMP3]], 8
87 ; CHECK-NEXT: call void @memset_pattern16(ptr [[F:%.*]], ptr @.memset_pattern, i64 [[TMP4]])
88 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
90 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
91 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[F]], i64 [[INDVARS_IV]]
92 ; CHECK-NEXT: [[TMP5:%.*]] = or disjoint i64 [[INDVARS_IV]], 1
93 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[F]], i64 [[TMP5]]
94 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 2
95 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[INDVARS_IV_NEXT]], [[TMP0]]
96 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
97 ; CHECK: for.end.loopexit:
98 ; CHECK-NEXT: br label [[FOR_END]]
100 ; CHECK-NEXT: ret void
104 %cmp1 = icmp eq i32 %mul, 0
105 br i1 %cmp1, label %for.end, label %for.body.preheader
107 for.body.preheader: ; preds = %entry
108 %0 = zext i32 %mul to i64
111 for.body: ; preds = %for.body.preheader, %for.body
112 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
113 %arrayidx = getelementptr inbounds i32, ptr %f, i64 %indvars.iv
114 store i32 2, ptr %arrayidx, align 4
115 %1 = or disjoint i64 %indvars.iv, 1
116 %arrayidx2 = getelementptr inbounds i32, ptr %f, i64 %1
117 store i32 2, ptr %arrayidx2, align 4
118 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
119 %cmp = icmp ult i64 %indvars.iv.next, %0
120 br i1 %cmp, label %for.body, label %for.end.loopexit
122 for.end.loopexit: ; preds = %for.body
125 for.end: ; preds = %for.end.loopexit, %entry