1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -loop-reduce -S < %s | FileCheck %s
4 target datalayout = "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128"
6 define i32 @test(i32 %c, ptr %a, ptr %b) {
9 ; CHECK-NEXT: [[CMP13:%.*]] = icmp sgt i32 [[C:%.*]], 0
10 ; CHECK-NEXT: br i1 [[CMP13]], label [[FOR_BODY_PREHEADER:%.*]], label [[RETURN:%.*]]
11 ; CHECK: for.body.preheader:
12 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[C]] to i64
13 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
15 ; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr i8, ptr [[LSR_IV:%.*]], i64 4
16 ; CHECK-NEXT: [[LSR_IV_NEXT:%.*]] = add nsw i64 [[LSR_IV1:%.*]], -1
17 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[LSR_IV_NEXT]], 0
18 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[RETURN_LOOPEXIT:%.*]], label [[FOR_BODY]]
20 ; CHECK-NEXT: [[LSR_IV1]] = phi i64 [ [[LSR_IV_NEXT]], [[FOR_COND:%.*]] ], [ [[WIDE_TRIP_COUNT]], [[FOR_BODY_PREHEADER]] ]
21 ; CHECK-NEXT: [[LSR_IV]] = phi ptr [ [[UGLYGEP]], [[FOR_COND]] ], [ [[A:%.*]], [[FOR_BODY_PREHEADER]] ]
22 ; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[LSR_IV]], align 4
23 ; CHECK-NEXT: [[TOBOOL3_NOT:%.*]] = icmp eq i32 [[VAL]], 0
24 ; CHECK-NEXT: br i1 [[TOBOOL3_NOT]], label [[FOR_COND]], label [[RETURN_LOOPEXIT]]
25 ; CHECK: return.loopexit:
26 ; CHECK-NEXT: [[RETVAL_1_PH:%.*]] = phi i32 [ 1, [[FOR_BODY]] ], [ 0, [[FOR_COND]] ]
27 ; CHECK-NEXT: br label [[RETURN]]
29 ; CHECK-NEXT: [[RETVAL_1:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[RETVAL_1_PH]], [[RETURN_LOOPEXIT]] ]
30 ; CHECK-NEXT: ret i32 [[RETVAL_1]]
33 %cmp13 = icmp sgt i32 %c, 0
34 br i1 %cmp13, label %for.body.preheader, label %return
36 for.body.preheader: ; preds = %entry
37 %wide.trip.count = zext i32 %c to i64
40 for.cond: ; preds = %for.body
41 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
42 %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
43 br i1 %exitcond.not, label %return, label %for.body
45 for.body: ; preds = %for.body.preheader, %for.cond
46 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.cond ]
47 %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv
48 %val = load i32, ptr %arrayidx, align 4
49 %tobool3.not = icmp eq i32 %val, 0
50 br i1 %tobool3.not, label %for.cond, label %return
52 return: ; preds = %for.cond, %for.body, %entry
53 %retval.1 = phi i32 [ 0, %entry ], [ 0, %for.cond ], [ 1, %for.body ]