1 ; RUN: opt -loop-unswitch -S - < %s | FileCheck %s
2 ; RUN: opt -loop-unswitch -enable-mssa-loop-dependency=true -verify-memoryssa -S - < %s | FileCheck %s
5 ;CHECK: [[Loop1:for\.end.*]]: ; preds = %for.cond.us
6 ;CHECK-NEXT: %[[PhiVar1:pdt.*]] = phi i32 [ %pdt.0.us, %for.cond.us ]
7 ;CHECK: [[Loop2:for\.end.*]]: ; preds = %for.cond.us1
8 ;CHECK-NEXT: %[[PhiVar2:pdt.*]] = phi i32 [ %pdt.0.us2, %for.cond.us1 ]
9 ;CHECK: [[Loop3:for\.end.*]]: ; preds = %for.cond
10 ;CHECK-NEXT: %[[PhiVar3:pdt.*]] = phi i32 [ %pdt.0, %for.cond ]
11 ;CHECK: [[Join1:for\.end.*]]: ; preds = %[[Loop2]], %[[Loop3]]
12 ;CHECK-NEXT: %[[PhiRes1:pdt.*]] = phi i32 [ %[[PhiVar3]], %[[Loop3]] ], [ %[[PhiVar2]], %[[Loop2]] ]
13 ;CHECK: for.end: ; preds = %[[Loop1]], %[[Join1]]
14 ;CHECK-NEXT: %[[PhiRes2:pdt.*]] = phi i32 [ %[[PhiRes1]], %[[Join1]] ], [ %[[PhiVar1]], %[[Loop1]] ]
15 ;CHECK-NEXT: ret i32 %[[PhiRes2]]
17 ; Function Attrs: nounwind uwtable
18 define i32 @b(i32 %x, i32 %y) #0 {
22 for.cond: ; preds = %for.inc, %entry
23 %pdt.0 = phi i32 [ 1, %entry ], [ %pdt.2, %for.inc ]
24 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
25 %cmp = icmp slt i32 %i.0, 100
26 br i1 %cmp, label %for.body, label %for.end
28 for.body: ; preds = %for.cond
29 %tobool = icmp ne i32 %x, 0
30 br i1 %tobool, label %if.then, label %if.else
32 if.then: ; preds = %for.body
33 %mul = mul nsw i32 %pdt.0, 2
36 if.else: ; preds = %for.body
37 %tobool1 = icmp ne i32 %y, 0
38 br i1 %tobool1, label %if.then2, label %if.else4
40 if.then2: ; preds = %if.else
41 %mul3 = mul nsw i32 %pdt.0, 3
44 if.else4: ; preds = %if.else
45 %mul5 = mul nsw i32 %pdt.0, 4
48 if.end: ; preds = %if.else4, %if.then2
49 %pdt.1 = phi i32 [ %mul3, %if.then2 ], [ %mul5, %if.else4 ]
52 if.end6: ; preds = %if.end, %if.then
53 %pdt.2 = phi i32 [ %mul, %if.then ], [ %pdt.1, %if.end ]
56 for.inc: ; preds = %if.end6
57 %inc = add nsw i32 %i.0, 1
60 for.end: ; preds = %for.cond