1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
4 ; Check that we can turn the icmp sle into icmp ult, regardless of the
5 ; order of the incoming values of the PHI node.
9 define void @phi_recurrence_start_first() {
10 ; CHECK-LABEL: @phi_recurrence_start_first(
12 ; CHECK-NEXT: br label [[WHILE_COND:%.*]]
14 ; CHECK-NEXT: [[CELL_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[START:%.*]], [[FOR_COND26:%.*]] ]
15 ; CHECK-NEXT: [[COND_V:%.*]] = call i1 @cond()
16 ; CHECK-NEXT: br i1 [[COND_V]], label [[IF_THEN:%.*]], label [[WHILE_END:%.*]]
18 ; CHECK-NEXT: [[START]] = add nuw nsw i32 [[CELL_0]], 1
19 ; CHECK-NEXT: br i1 [[COND_V]], label [[FOR_COND11:%.*]], label [[FOR_COND26]]
21 ; CHECK-NEXT: [[I_1:%.*]] = phi i32 [ [[START]], [[IF_THEN]] ], [ [[STEP:%.*]], [[FOR_COND11]] ]
22 ; CHECK-NEXT: [[CMP13:%.*]] = icmp ult i32 [[I_1]], 100
23 ; CHECK-NEXT: [[STEP]] = add nuw nsw i32 [[I_1]], 1
24 ; CHECK-NEXT: br i1 [[CMP13]], label [[FOR_COND11]], label [[WHILE_END]]
26 ; CHECK-NEXT: br label [[WHILE_COND]]
28 ; CHECK-NEXT: ret void
33 while.cond: ; preds = %entry, %for.cond26
34 %cell.0 = phi i32 [ 0, %entry ], [ %start, %for.cond26 ]
35 %cond.v = call i1 @cond()
36 br i1 %cond.v, label %if.then, label %while.end
38 if.then: ; preds = %while.cond
39 %start = add nsw i32 %cell.0, 1
40 br i1 %cond.v, label %for.cond11, label %for.cond26
42 for.cond11: ; preds = %for.cond11, %if.then
43 %i.1 = phi i32 [ %start, %if.then ], [ %step, %for.cond11 ]
44 %cmp13 = icmp sle i32 %i.1, 99
45 %step = add nsw i32 %i.1, 1
46 br i1 %cmp13, label %for.cond11, label %while.end
48 for.cond26: ; preds = %if.then
51 while.end: ; preds = %while.cond, %for.cond11
55 define void @phi_recurrence_step_first() {
56 ; CHECK-LABEL: @phi_recurrence_step_first(
58 ; CHECK-NEXT: br label [[WHILE_COND:%.*]]
60 ; CHECK-NEXT: [[CELL_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[START:%.*]], [[FOR_COND26:%.*]] ]
61 ; CHECK-NEXT: [[COND_V:%.*]] = call i1 @cond()
62 ; CHECK-NEXT: br i1 [[COND_V]], label [[IF_THEN:%.*]], label [[WHILE_END:%.*]]
64 ; CHECK-NEXT: [[START]] = add nuw nsw i32 [[CELL_0]], 1
65 ; CHECK-NEXT: br i1 [[COND_V]], label [[FOR_COND11:%.*]], label [[FOR_COND26]]
67 ; CHECK-NEXT: [[I_1:%.*]] = phi i32 [ [[STEP:%.*]], [[FOR_COND11]] ], [ [[START]], [[IF_THEN]] ]
68 ; CHECK-NEXT: [[CMP13:%.*]] = icmp ult i32 [[I_1]], 100
69 ; CHECK-NEXT: [[STEP]] = add nuw nsw i32 [[I_1]], 1
70 ; CHECK-NEXT: br i1 [[CMP13]], label [[FOR_COND11]], label [[WHILE_END]]
72 ; CHECK-NEXT: br label [[WHILE_COND]]
74 ; CHECK-NEXT: ret void
79 while.cond: ; preds = %entry, %for.cond26
80 %cell.0 = phi i32 [ 0, %entry ], [ %start, %for.cond26 ]
81 %cond.v = call i1 @cond()
82 br i1 %cond.v, label %if.then, label %while.end
84 if.then: ; preds = %while.cond
85 %start = add nsw i32 %cell.0, 1
86 br i1 %cond.v, label %for.cond11, label %for.cond26
88 for.cond11: ; preds = %for.cond11, %if.then
89 %i.1 = phi i32 [ %step, %for.cond11 ], [ %start, %if.then]
90 %cmp13 = icmp sle i32 %i.1, 99
91 %step = add nsw i32 %i.1, 1
92 br i1 %cmp13, label %for.cond11, label %while.end
94 for.cond26: ; preds = %if.then
97 while.end: ; preds = %while.cond, %for.cond11