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-m:e-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
8 define void @test(ptr noalias nocapture %base, i64 %size) #1 {
11 ; CHECK-NEXT: [[CMP3:%.*]] = icmp eq i64 [[SIZE:%.*]], 0
12 ; CHECK-NEXT: br i1 [[CMP3]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
13 ; CHECK: for.body.preheader:
14 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
16 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
17 ; CHECK-NEXT: tail call void @ff()
18 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[BASE:%.*]], i64 [[INDVARS_IV]]
19 ; CHECK-NEXT: store i8 0, ptr [[ARRAYIDX]], align 1
20 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1
21 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[SIZE]]
22 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
23 ; CHECK: for.end.loopexit:
24 ; CHECK-NEXT: br label [[FOR_END]]
26 ; CHECK-NEXT: ret void
29 %cmp3 = icmp eq i64 %size, 0
30 br i1 %cmp3, label %for.end, label %for.body.preheader
32 for.body.preheader: ; preds = %entry
35 for.body: ; preds = %for.body.preheader, %for.body
36 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
38 %arrayidx = getelementptr inbounds i8, ptr %base, i64 %indvars.iv
39 store i8 0, ptr %arrayidx, align 1
40 %indvars.iv.next = add i64 %indvars.iv, 1
41 %exitcond = icmp ne i64 %indvars.iv.next, %size
42 br i1 %exitcond, label %for.body, label %for.end.loopexit
44 for.end.loopexit: ; preds = %for.body
47 for.end: ; preds = %for.end.loopexit, %entry
51 attributes #1 = { uwtable }