| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 | |
| ; RUN: opt -passes=indvars -replexitval=never -S %s | FileCheck %s | |
| target datalayout = "n8:16:32:64" | |
| ; The division by (1 umax (9 + %start)<u nuw>) can execute in %entry, so its | |
| ; divisor must be expanded without use flags. | |
| define void @exit_count_udiv_by_umax_of_exit_value_nuw(i8 noundef %start, i8 noundef %n, i8 noundef %x) { | |
| ; | |
| ; CHECK-LABEL: define void @exit_count_udiv_by_umax_of_exit_value_nuw( | |
| ; CHECK-SAME: i8 noundef [[START:%.*]], i8 noundef [[N:%.*]], i8 noundef [[X:%.*]]) { | |
| ; CHECK-NEXT: [[ENTRY:.*]]: | |
| ; CHECK-NEXT: br label %[[OUTER_HEADER:.*]] | |
| ; CHECK: [[OUTER_HEADER]]: | |
| ; CHECK-NEXT: [[OUTER_IV:%.*]] = phi i8 [ 0, %[[ENTRY]] ], [ [[OUTER_IV_NEXT:%.*]], %[[OUTER_LATCH:.*]] ] | |
| ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i8 [[OUTER_IV]], [[N]] | |
| ; CHECK-NEXT: br i1 [[TMP3]], label %[[EXIT:.*]], label %[[INNER_PH:.*]] | |
| ; CHECK: [[INNER_PH]]: | |
| ; CHECK-NEXT: br label %[[INNER:.*]] | |
| ; CHECK: [[INNER]]: | |
| ; CHECK-NEXT: [[INNER_IV:%.*]] = phi i8 [ [[START]], %[[INNER_PH]] ], [ [[INNER_IV_NEXT:%.*]], %[[INNER]] ] | |
| ; CHECK-NEXT: [[INNER_COUNT:%.*]] = phi i32 [ 0, %[[INNER_PH]] ], [ [[INNER_COUNT_NEXT:%.*]], %[[INNER]] ] | |
| ; CHECK-NEXT: [[INNER_IV_NEXT]] = add nuw i8 [[INNER_IV]], 1 | |
| ; CHECK-NEXT: [[INNER_COUNT_NEXT]] = add nuw nsw i32 [[INNER_COUNT]], 1 | |
| ; CHECK-NEXT: [[INNER_EC:%.*]] = icmp eq i32 [[INNER_COUNT_NEXT]], 10 | |
| ; CHECK-NEXT: br i1 [[INNER_EC]], label %[[OUTER_LATCH]], label %[[INNER]] | |
| ; CHECK: [[OUTER_LATCH]]: | |
| ; CHECK-NEXT: [[INNER_IV_LCSSA:%.*]] = phi i8 [ [[INNER_IV]], %[[INNER]] ] | |
| ; CHECK-NEXT: [[DIVISOR:%.*]] = call i8 @llvm.umax.i8(i8 [[INNER_IV_LCSSA]], i8 1) | |
| ; CHECK-NEXT: [[OUTER_BOUND:%.*]] = udiv i8 [[X]], [[DIVISOR]] | |
| ; CHECK-NEXT: [[OUTER_IV_NEXT]] = add nuw i8 [[OUTER_IV]], 1 | |
| ; CHECK-NEXT: [[TMP4:%.*]] = icmp ult i8 [[OUTER_IV_NEXT]], [[OUTER_BOUND]] | |
| ; CHECK-NEXT: br i1 [[TMP4]], label %[[OUTER_HEADER]], label %[[EXIT]] | |
| ; CHECK: [[EXIT]]: | |
| ; CHECK-NEXT: ret void | |
| ; | |
| entry: | |
| br label %outer.header | |
| outer.header: | |
| %outer.iv = phi i8 [ 0, %entry ], [ %outer.iv.next, %outer.latch ] | |
| %outer.header.ec = icmp eq i8 %outer.iv, %n | |
| br i1 %outer.header.ec, label %exit, label %inner.ph | |
| inner.ph: | |
| br label %inner | |
| inner: | |
| %inner.iv = phi i8 [ %start, %inner.ph ], [ %inner.iv.next, %inner ] | |
| %inner.count = phi i32 [ 0, %inner.ph ], [ %inner.count.next, %inner ] | |
| %inner.iv.next = add nuw i8 %inner.iv, 1 | |
| %inner.count.next = add i32 %inner.count, 1 | |
| %inner.ec = icmp eq i32 %inner.count.next, 10 | |
| br i1 %inner.ec, label %outer.latch, label %inner | |
| outer.latch: | |
| %inner.iv.lcssa = phi i8 [ %inner.iv, %inner ] | |
| %divisor = call i8 @llvm.umax.i8(i8 %inner.iv.lcssa, i8 1) | |
| %outer.bound = udiv i8 %x, %divisor | |
| %outer.iv.next = add i8 %outer.iv, 1 | |
| %outer.latch.ec = icmp ult i8 %outer.iv.next, %outer.bound | |
| br i1 %outer.latch.ec, label %outer.header, label %exit | |
| exit: | |
| ret void | |
| } |