• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -canon-freeze -S | FileCheck %s
3; A set of tests that have several phi nodes
4declare void @call(i32)
5declare i32 @call2()
6
7define void @onephi_used(i32 %n, i32 %i.init, i32 %j.init) {
8; CHECK-LABEL: @onephi_used(
9; CHECK-NEXT:  entry:
10; CHECK-NEXT:    [[I_INIT_FROZEN:%.*]] = freeze i32 [[I_INIT:%.*]]
11; CHECK-NEXT:    br label [[LOOP:%.*]]
12; CHECK:       loop:
13; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_INIT_FROZEN]], [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
14; CHECK-NEXT:    [[J:%.*]] = phi i32 [ [[J_INIT:%.*]], [[ENTRY]] ], [ [[J_NEXT:%.*]], [[LOOP]] ]
15; CHECK-NEXT:    [[I_NEXT]] = add i32 [[I]], 1
16; CHECK-NEXT:    [[J_NEXT]] = add nuw nsw i32 [[J]], -2
17; CHECK-NEXT:    call void @call(i32 [[I]])
18; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 [[I_NEXT]], [[N:%.*]]
19; CHECK-NEXT:    br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
20; CHECK:       exit:
21; CHECK-NEXT:    ret void
22;
23entry:
24  br label %loop
25loop:
26  %i = phi i32 [ %i.init, %entry ], [ %i.next, %loop ]
27  %j = phi i32 [ %j.init, %entry ], [ %j.next, %loop ]
28  %i.next = add nuw nsw i32 %i, 1
29  %j.next = add nuw nsw i32 %j, -2
30  %i.fr = freeze i32 %i
31  call void @call(i32 %i.fr)
32  %cond = icmp eq i32 %i.next, %n
33  br i1 %cond, label %loop, label %exit
34
35exit:
36  ret void
37}
38
39; Negative test
40define void @twophis_used(i32 %n, i32 %i.init, i32 %j.init) {
41; CHECK-LABEL: @twophis_used(
42; CHECK-NEXT:  entry:
43; CHECK-NEXT:    br label [[LOOP:%.*]]
44; CHECK:       loop:
45; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_INIT:%.*]], [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
46; CHECK-NEXT:    [[J:%.*]] = phi i32 [ [[J_INIT:%.*]], [[ENTRY]] ], [ [[J_NEXT:%.*]], [[LOOP]] ]
47; CHECK-NEXT:    [[I_NEXT]] = add nuw nsw i32 [[I]], 1
48; CHECK-NEXT:    [[J_NEXT]] = add nuw nsw i32 [[J]], -2
49; CHECK-NEXT:    [[IJ:%.*]] = add i32 [[I]], [[J]]
50; CHECK-NEXT:    [[IJ_FR:%.*]] = freeze i32 [[IJ]]
51; CHECK-NEXT:    call void @call(i32 [[IJ_FR]])
52; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 [[I_NEXT]], [[N:%.*]]
53; CHECK-NEXT:    br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
54; CHECK:       exit:
55; CHECK-NEXT:    ret void
56;
57entry:
58  br label %loop
59loop:
60  %i = phi i32 [ %i.init, %entry ], [ %i.next, %loop ]
61  %j = phi i32 [ %j.init, %entry ], [ %j.next, %loop ]
62  %i.next = add nuw nsw i32 %i, 1
63  %j.next = add nuw nsw i32 %j, -2
64  %ij = add i32 %i, %j
65  %ij.fr = freeze i32 %ij
66  call void @call(i32 %ij.fr)
67  %cond = icmp eq i32 %i.next, %n
68  br i1 %cond, label %loop, label %exit
69
70exit:
71  ret void
72}
73
74; Negative test
75define void @nonindphi_used(i32 %n, i32 %i.init, i32 %j.init, i32 %k.init) {
76; CHECK-LABEL: @nonindphi_used(
77; CHECK-NEXT:  entry:
78; CHECK-NEXT:    br label [[LOOP:%.*]]
79; CHECK:       loop:
80; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_INIT:%.*]], [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
81; CHECK-NEXT:    [[J:%.*]] = phi i32 [ [[J_INIT:%.*]], [[ENTRY]] ], [ [[J_NEXT:%.*]], [[LOOP]] ]
82; CHECK-NEXT:    [[K:%.*]] = phi i32 [ [[K_INIT:%.*]], [[ENTRY]] ], [ [[ANY:%.*]], [[LOOP]] ]
83; CHECK-NEXT:    [[I_NEXT]] = add nuw nsw i32 [[I]], 1
84; CHECK-NEXT:    [[J_NEXT]] = add nuw nsw i32 [[J]], -2
85; CHECK-NEXT:    [[IJ:%.*]] = add i32 [[I]], [[J]]
86; CHECK-NEXT:    [[IJK:%.*]] = add i32 [[IJ]], [[K]]
87; CHECK-NEXT:    [[IJK_FR:%.*]] = freeze i32 [[IJK]]
88; CHECK-NEXT:    call void @call(i32 [[IJK_FR]])
89; CHECK-NEXT:    [[ANY]] = call i32 @call2()
90; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 [[I_NEXT]], [[N:%.*]]
91; CHECK-NEXT:    br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
92; CHECK:       exit:
93; CHECK-NEXT:    ret void
94;
95entry:
96  br label %loop
97
98loop:
99  %i = phi i32 [ %i.init, %entry ], [ %i.next, %loop ]
100  %j = phi i32 [ %j.init, %entry ], [ %j.next, %loop ]
101  %k = phi i32 [ %k.init, %entry ], [ %any, %loop ]
102  %i.next = add nuw nsw i32 %i, 1
103  %j.next = add nuw nsw i32 %j, -2
104  %ij = add i32 %i, %j
105  %ijk = add i32 %ij, %k
106  %ijk.fr = freeze i32 %ijk
107  call void @call(i32 %ijk.fr)
108  %any = call i32 @call2()
109  %cond = icmp eq i32 %i.next, %n
110  br i1 %cond, label %loop, label %exit
111
112exit:
113  ret void
114}
115