1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=indvars -S < %s | FileCheck %s
4 ; indvars should transform the phi node pair from the for-loop
6 @c = common global i32 0, align 4
8 define i32 @main() #0 {
11 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @c, align 4
12 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TMP0]], 0
13 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[FOR_BODY_PREHEADER:%.*]], label [[EXIT:%.*]]
14 ; CHECK: for.body.preheader:
15 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
17 ; CHECK-NEXT: br label [[FOR_INC:%.*]]
19 ; CHECK-NEXT: br i1 false, label [[FOR_BODY]], label [[EXIT_LOOPEXIT:%.*]]
20 ; CHECK: exit.loopexit:
21 ; CHECK-NEXT: br label [[EXIT]]
23 ; CHECK-NEXT: [[RET:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 0, [[EXIT_LOOPEXIT]] ]
24 ; CHECK-NEXT: ret i32 [[RET]]
27 %0 = load i32, ptr @c, align 4
28 %tobool = icmp eq i32 %0, 0
29 br i1 %tobool, label %for.body, label %exit
32 %inc2 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
33 %sub = add i32 %inc2, -1
34 %cmp1 = icmp uge i32 %sub, %inc2
35 %conv = zext i1 %cmp1 to i32
39 %inc = add nsw i32 %inc2, 1
40 %cmp = icmp slt i32 %inc, 5
41 br i1 %cmp, label %for.body, label %exit
44 %ret = phi i32 [ 0, %entry ], [ %conv, %for.inc ]