1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ;RUN: opt -newgvn -S < %s | FileCheck %s
3 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-apple-macosx10.12.0"
5 ;; Ensure we don't infinite loop when all phi arguments are really unreachable or self-defined
6 define void @fn1(i64 %arg) {
9 ; CHECK-NEXT: br i1 undef, label [[IF_THEN:%.*]], label [[COND_TRUE:%.*]]
11 ; CHECK-NEXT: br i1 false, label [[FIRSTPHIBLOCK:%.*]], label [[TEMP:%.*]]
12 ; CHECK: firstphiblock:
13 ; CHECK-NEXT: br i1 undef, label %for.cond17thread-pre-split, label [[SECONDPHIBLOCK:%.*]]
14 ; CHECK: secondphiblock:
15 ; CHECK-NEXT: [[SECONDPHI:%.*]] = phi i64 [ [[THIRDPHI:%.*]], [[THIRDPHIBLOCK:%.*]] ], [ undef, [[FIRSTPHIBLOCK]] ]
16 ; CHECK-NEXT: br i1 undef, label [[FIRSTPHIBLOCK]], label [[THIRDPHIBLOCK]]
17 ; CHECK: thirdphiblock:
18 ; CHECK-NEXT: [[THIRDPHI]] = phi i64 [ [[SECONDPHI]], [[SECONDPHIBLOCK]] ], [ [[DIV:%.*]], [[COND_TRUE]] ]
19 ; CHECK-NEXT: br label [[SECONDPHIBLOCK]]
20 ; CHECK: for.cond17thread-pre-split:
21 ; CHECK-NEXT: br label [[COND_TRUE]]
23 ; CHECK-NEXT: [[DIV]] = sdiv i64 [[ARG:%.*]], 4
24 ; CHECK-NEXT: br label [[THIRDPHIBLOCK]]
26 ; CHECK-NEXT: ret void
29 br i1 undef, label %if.then, label %cond.true
31 br i1 false, label %firstphiblock, label %temp
33 %firstphi = phi i64 [ %arg, %if.then ], [ undef, %secondphiblock ]
34 br i1 undef, label %for.cond17thread-pre-split, label %secondphiblock
36 %secondphi = phi i64 [ %thirdphi, %thirdphiblock ], [ %firstphi, %firstphiblock ]
37 br i1 undef, label %firstphiblock, label %thirdphiblock
39 %thirdphi = phi i64 [ %secondphi, %secondphiblock ], [ %div, %cond.true ]
40 br label %secondphiblock
41 for.cond17thread-pre-split:
44 %fourthphi = phi i64 [ %arg, %entry ], [ %firstphi, %for.cond17thread-pre-split ]
45 %div = sdiv i64 %fourthphi, 4
46 br label %thirdphiblock
50 define void @fn2(i64 %arg) {
53 ; CHECK-NEXT: br i1 undef, label [[IF_THEN:%.*]], label [[COND_TRUE:%.*]]
55 ; CHECK-NEXT: br i1 false, label [[FIRSTPHIBLOCK:%.*]], label [[TEMP:%.*]]
56 ; CHECK: firstphiblock:
57 ; CHECK-NEXT: [[FIRSTPHI:%.*]] = phi i64 [ undef, [[IF_THEN]] ], [ [[SECONDPHI:%.*]], [[SECONDPHIBLOCK:%.*]] ]
58 ; CHECK-NEXT: br i1 undef, label %for.cond17thread-pre-split, label [[SECONDPHIBLOCK]]
59 ; CHECK: secondphiblock:
60 ; CHECK-NEXT: [[SECONDPHI]] = phi i64 [ [[THIRDPHI:%.*]], [[THIRDPHIBLOCK:%.*]] ], [ [[FIRSTPHI]], [[FIRSTPHIBLOCK]] ]
61 ; CHECK-NEXT: br i1 undef, label [[FIRSTPHIBLOCK]], label [[THIRDPHIBLOCK]]
62 ; CHECK: thirdphiblock:
63 ; CHECK-NEXT: [[THIRDPHI]] = phi i64 [ [[SECONDPHI]], [[SECONDPHIBLOCK]] ], [ [[DIV:%.*]], [[COND_TRUE]] ]
64 ; CHECK-NEXT: br label [[SECONDPHIBLOCK]]
65 ; CHECK: for.cond17thread-pre-split:
66 ; CHECK-NEXT: br label [[COND_TRUE]]
68 ; CHECK-NEXT: [[FOURTHPHI:%.*]] = phi i64 [ [[ARG:%.*]], [[ENTRY:%.*]] ], [ [[FIRSTPHI]], %for.cond17thread-pre-split ]
69 ; CHECK-NEXT: [[DIV]] = sdiv i64 [[FOURTHPHI]], 4
70 ; CHECK-NEXT: br label [[THIRDPHIBLOCK]]
72 ; CHECK-NEXT: ret void
75 br i1 undef, label %if.then, label %cond.true
77 br i1 false, label %firstphiblock, label %temp
79 %firstphi = phi i64 [ %arg, %if.then ], [ %secondphi, %secondphiblock ]
80 br i1 undef, label %for.cond17thread-pre-split, label %secondphiblock
82 %secondphi = phi i64 [ %thirdphi, %thirdphiblock ], [ %firstphi, %firstphiblock ]
83 br i1 undef, label %firstphiblock, label %thirdphiblock
85 %thirdphi = phi i64 [ %secondphi, %secondphiblock ], [ %div, %cond.true ]
86 br label %secondphiblock
87 for.cond17thread-pre-split:
90 %fourthphi = phi i64 [ %arg, %entry ], [ %firstphi, %for.cond17thread-pre-split ]
91 %div = sdiv i64 %fourthphi, 4
92 br label %thirdphiblock
96 @b = external global i32, align 4
97 @a = external global i32, align 4
101 ; CHECK-NEXT: br label [[L1:%.*]]
102 ; CHECK: l1.loopexit:
103 ; CHECK-NEXT: br label [[L1]]
105 ; CHECK-NEXT: [[F_0:%.*]] = phi i32* [ @b, [[ENTRY:%.*]] ], [ @a, [[L1_LOOPEXIT:%.*]] ]
106 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
107 ; CHECK: for.cond.loopexit:
108 ; CHECK-NEXT: store i8 undef, i8* null
109 ; CHECK-NEXT: br label [[FOR_COND]]
111 ; CHECK-NEXT: br i1 undef, label [[FOR_END14:%.*]], label [[FOR_COND1_PREHEADER:%.*]]
112 ; CHECK: for.cond1.preheader:
113 ; CHECK-NEXT: br label [[FOR_BODY3:%.*]]
115 ; CHECK-NEXT: br label [[L2:%.*]]
117 ; CHECK-NEXT: br i1 undef, label [[FOR_COND1:%.*]], label [[L1_LOOPEXIT]]
119 ; CHECK-NEXT: [[G_4:%.*]] = phi i32* [ @b, [[FOR_END14]] ], [ @a, [[FOR_COND1]] ]
120 ; CHECK-NEXT: [[F_2:%.*]] = phi i32* [ [[F_0]], [[FOR_END14]] ], [ @a, [[FOR_COND1]] ]
121 ; CHECK-NEXT: br label [[FOR_INC:%.*]]
123 ; CHECK-NEXT: br i1 false, label [[FOR_COND_LOOPEXIT:%.*]], label [[FOR_INC]]
125 ; CHECK-NEXT: br label [[L2]]
130 %g.223.lcssa = phi i32* [ @b, %for.body3 ]
133 %g.0 = phi i32* [ undef, %entry ], [ %g.223.lcssa, %l1.loopexit ]
134 %f.0 = phi i32* [ @b, %entry ], [ @a, %l1.loopexit ]
139 %g.1 = phi i32* [ %g.0, %l1 ], [ %g.4, %for.cond.loopexit ]
140 %f.1 = phi i32* [ %f.0, %l1 ], [ %f.2, %for.cond.loopexit ]
141 br i1 undef, label %for.end14, label %for.cond1.preheader
147 br i1 undef, label %for.cond1, label %l1.loopexit
149 %g.4 = phi i32* [ %g.1, %for.end14 ], [ @a, %for.cond1 ]
150 %f.2 = phi i32* [ %f.1, %for.end14 ], [ @a, %for.cond1 ]
153 br i1 false, label %for.cond.loopexit, label %for.inc