• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -indvars -S < %s | FileCheck %s
3
4; indvars should transform the phi node pair from the for-loop
5
6@c = common global i32 0, align 4
7
8define i32 @main() #0 {
9; CHECK-LABEL: @main(
10; CHECK-NEXT:  entry:
11; CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* @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:%.*]]
16; CHECK:       for.body:
17; CHECK-NEXT:    br label [[FOR_INC:%.*]]
18; CHECK:       for.inc:
19; CHECK-NEXT:    br i1 false, label [[FOR_BODY]], label [[EXIT_LOOPEXIT:%.*]]
20; CHECK:       exit.loopexit:
21; CHECK-NEXT:    br label [[EXIT]]
22; CHECK:       exit:
23; CHECK-NEXT:    [[RET:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 0, [[EXIT_LOOPEXIT]] ]
24; CHECK-NEXT:    ret i32 [[RET]]
25;
26entry:
27  %0 = load i32, i32* @c, align 4
28  %tobool = icmp eq i32 %0, 0
29  br i1 %tobool, label %for.body, label %exit
30
31for.body:
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
36  br label %for.inc
37
38for.inc:
39  %inc = add nsw i32 %inc2, 1
40  %cmp = icmp slt i32 %inc, 5
41  br i1 %cmp, label %for.body, label %exit
42
43exit:
44  %ret = phi i32 [ 0, %entry ], [ %conv, %for.inc ]
45  ret i32 %ret
46}
47