1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S -passes=indvars < %s | FileCheck %s
; Do not infer that %cmp is true. The %indvar3 input of %indvar2 comes from
; a previous iteration, so we should not compare it to a value from the current
; iteration.
define i32 @test() {
; CHECK-LABEL: define i32 @test() {
; CHECK-NEXT: [[ENTRY:.*]]:
; CHECK-NEXT: br label %[[FOR_PREHEADER:.*]]
; CHECK: [[FOR_PREHEADER]]:
; CHECK-NEXT: [[INDVAR1:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[PHI:%.*]], %[[FOR_INC:.*]] ]
; CHECK-NEXT: [[INDVAR2:%.*]] = phi i32 [ 1, %[[ENTRY]] ], [ [[INDVAR3:%.*]], %[[FOR_INC]] ]
; CHECK-NEXT: [[INDVAR3]] = phi i32 [ 0, %[[ENTRY]] ], [ [[INC:%.*]], %[[FOR_INC]] ]
; CHECK-NEXT: [[COND1:%.*]] = icmp eq i32 [[INDVAR3]], 0
; CHECK-NEXT: br i1 [[COND1]], label %[[FOR_INC]], label %[[FOR_END:.*]]
; CHECK: [[FOR_END]]:
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[INDVAR2]], 0
; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT: br label %[[FOR_INC]]
; CHECK: [[FOR_INC]]:
; CHECK-NEXT: [[PHI]] = phi i32 [ [[EXT]], %[[FOR_END]] ], [ 0, %[[FOR_PREHEADER]] ]
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[INDVAR3]], 1
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INDVAR3]], 2
; CHECK-NEXT: br i1 [[EXITCOND]], label %[[FOR_EXIT:.*]], label %[[FOR_PREHEADER]]
; CHECK: [[FOR_EXIT]]:
; CHECK-NEXT: [[INDVAR1_LCSSA:%.*]] = phi i32 [ [[INDVAR1]], %[[FOR_INC]] ]
; CHECK-NEXT: ret i32 [[INDVAR1_LCSSA]]
;
entry:
br label %for.preheader
for.preheader:
%indvar1 = phi i32 [ 0, %entry ], [ %phi, %for.inc ]
%indvar2 = phi i32 [ 1, %entry ], [ %indvar3, %for.inc ]
%indvar3 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
%cond1 = icmp eq i32 %indvar3, 0
br i1 %cond1, label %for.inc, label %for.end
for.end:
%cmp = icmp sgt i32 %indvar2, 0
%ext = zext i1 %cmp to i32
br label %for.inc
for.inc:
%phi = phi i32 [ %ext, %for.end ], [ 0, %for.preheader ]
%inc = add i32 %indvar3, 1
%exitcond = icmp eq i32 %indvar3, 2
br i1 %exitcond, label %for.exit, label %for.preheader
for.exit:
ret i32 %indvar1
}
|