1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes="loop-flatten" -verify-scev -S < %s | FileCheck %s
4 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
6 ; This shouldn't flatten, as the inner add is used by a lcssa.
11 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER_I:%.*]]
12 ; CHECK: for.cond1.preheader.i:
13 ; CHECK-NEXT: [[L_011_I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[ADD6_I:%.*]], [[FOR_INC5_I:%.*]] ]
14 ; CHECK-NEXT: br label [[WHILE_COND_I_PREHEADER_I:%.*]]
15 ; CHECK: while.cond.i.preheader.i:
16 ; CHECK-NEXT: [[STOREMERGE9_I:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_I]] ], [ [[ADD_I:%.*]], [[WHILE_COND_I_PREHEADER_I]] ]
17 ; CHECK-NEXT: [[ADD_I]] = add nuw nsw i32 [[STOREMERGE9_I]], 1
18 ; CHECK-NEXT: [[CMP2_I:%.*]] = icmp ult i32 [[STOREMERGE9_I]], 5
19 ; CHECK-NEXT: br i1 [[CMP2_I]], label [[WHILE_COND_I_PREHEADER_I]], label [[FOR_INC5_I]]
21 ; CHECK-NEXT: [[ADD_I_LCSSA:%.*]] = phi i32 [ [[ADD_I]], [[WHILE_COND_I_PREHEADER_I]] ]
22 ; CHECK-NEXT: [[ADD6_I]] = add nuw nsw i32 [[L_011_I]], 1
23 ; CHECK-NEXT: [[EXITCOND_NOT_I:%.*]] = icmp eq i32 [[ADD6_I]], 6
24 ; CHECK-NEXT: br i1 [[EXITCOND_NOT_I]], label [[E_EXIT:%.*]], label [[FOR_COND1_PREHEADER_I]]
26 ; CHECK-NEXT: [[ADD_I_LCSSA_LCSSA:%.*]] = phi i32 [ [[ADD_I_LCSSA]], [[FOR_INC5_I]] ]
27 ; CHECK-NEXT: ret i32 [[ADD_I_LCSSA_LCSSA]]
30 br label %for.cond1.preheader.i
32 for.cond1.preheader.i: ; preds = %for.inc5.i, %entry
33 %l.011.i = phi i32 [ 0, %entry ], [ %add6.i, %for.inc5.i ]
34 br label %while.cond.i.preheader.i
36 while.cond.i.preheader.i: ; preds = %while.cond.i.preheader.i, %for.cond1.preheader.i
37 %storemerge9.i = phi i32 [ 0, %for.cond1.preheader.i ], [ %add.i, %while.cond.i.preheader.i ]
38 %add.i = add nuw nsw i32 %storemerge9.i, 1
39 %cmp2.i = icmp ult i32 %storemerge9.i, 5
40 br i1 %cmp2.i, label %while.cond.i.preheader.i, label %for.inc5.i
42 for.inc5.i: ; preds = %while.cond.i.preheader.i
43 %add.i.lcssa = phi i32 [ %add.i, %while.cond.i.preheader.i ]
44 %add6.i = add nuw nsw i32 %l.011.i, 1
45 %exitcond.not.i = icmp eq i32 %add6.i, 6
46 br i1 %exitcond.not.i, label %e.exit, label %for.cond1.preheader.i
48 e.exit: ; preds = %for.inc5.i
49 %add.i.lcssa.lcssa = phi i32 [ %add.i.lcssa, %for.inc5.i ]
50 ret i32 %add.i.lcssa.lcssa
54 define i32 @test64() {
55 ; CHECK-LABEL: @test64(
57 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER_I:%.*]]
58 ; CHECK: for.cond1.preheader.i:
59 ; CHECK-NEXT: [[L_011_I:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[ADD6_I:%.*]], [[FOR_INC5_I:%.*]] ]
60 ; CHECK-NEXT: br label [[WHILE_COND_I_PREHEADER_I:%.*]]
61 ; CHECK: while.cond.i.preheader.i:
62 ; CHECK-NEXT: [[STOREMERGE9_I:%.*]] = phi i64 [ 0, [[FOR_COND1_PREHEADER_I]] ], [ [[ADD_I:%.*]], [[WHILE_COND_I_PREHEADER_I]] ]
63 ; CHECK-NEXT: [[ADD_I]] = add nuw nsw i64 [[STOREMERGE9_I]], 1
64 ; CHECK-NEXT: [[CMP2_I:%.*]] = icmp ult i64 [[STOREMERGE9_I]], 5
65 ; CHECK-NEXT: br i1 [[CMP2_I]], label [[WHILE_COND_I_PREHEADER_I]], label [[FOR_INC5_I]]
67 ; CHECK-NEXT: [[ADD_I_LCSSA_WIDEN:%.*]] = phi i64 [ [[ADD_I]], [[WHILE_COND_I_PREHEADER_I]] ]
68 ; CHECK-NEXT: [[ADD_I_LCSSA:%.*]] = trunc i64 [[ADD_I_LCSSA_WIDEN]] to i32
69 ; CHECK-NEXT: [[ADD6_I]] = add nuw nsw i64 [[L_011_I]], 1
70 ; CHECK-NEXT: [[EXITCOND_NOT_I:%.*]] = icmp eq i64 [[ADD6_I]], 6
71 ; CHECK-NEXT: br i1 [[EXITCOND_NOT_I]], label [[E_EXIT:%.*]], label [[FOR_COND1_PREHEADER_I]]
73 ; CHECK-NEXT: [[ADD_I_LCSSA_LCSSA:%.*]] = phi i32 [ [[ADD_I_LCSSA]], [[FOR_INC5_I]] ]
74 ; CHECK-NEXT: ret i32 [[ADD_I_LCSSA_LCSSA]]
77 br label %for.cond1.preheader.i
79 for.cond1.preheader.i: ; preds = %for.inc5.i, %entry
80 %l.011.i = phi i64 [ 0, %entry ], [ %add6.i, %for.inc5.i ]
81 br label %while.cond.i.preheader.i
83 while.cond.i.preheader.i: ; preds = %while.cond.i.preheader.i, %for.cond1.preheader.i
84 %storemerge9.i = phi i64 [ 0, %for.cond1.preheader.i ], [ %add.i, %while.cond.i.preheader.i ]
85 %add.i = add nuw nsw i64 %storemerge9.i, 1
86 %cmp2.i = icmp ult i64 %storemerge9.i, 5
87 br i1 %cmp2.i, label %while.cond.i.preheader.i, label %for.inc5.i
89 for.inc5.i: ; preds = %while.cond.i.preheader.i
90 %add.i.lcssa.widen = phi i64 [ %add.i, %while.cond.i.preheader.i ]
91 %add.i.lcssa = trunc i64 %add.i.lcssa.widen to i32
92 %add6.i = add nuw nsw i64 %l.011.i, 1
93 %exitcond.not.i = icmp eq i64 %add6.i, 6
94 br i1 %exitcond.not.i, label %e.exit, label %for.cond1.preheader.i
96 e.exit: ; preds = %for.inc5.i
97 %add.i.lcssa.lcssa = phi i32 [ %add.i.lcssa, %for.inc5.i ]
98 ret i32 %add.i.lcssa.lcssa