1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -S -loop-unroll -unroll-runtime %s -o - | FileCheck %s 3; RUN: opt -S -loop-unroll -unroll-runtime -unroll-max-upperbound=6 %s -o - | FileCheck %s --check-prefix=UPPER 4 5target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" 6 7@global = dso_local local_unnamed_addr global i32 0, align 4 8@global.1 = dso_local local_unnamed_addr global i8* null, align 4 9 10; Check that loop in hoge_3, with a runtime upperbound of 3, is not unrolled. 11define dso_local void @hoge_3(i8 %arg) { 12; CHECK-LABEL: @hoge_3( 13; CHECK-NEXT: entry: 14; CHECK-NEXT: [[X:%.*]] = load i32, i32* @global, align 4 15; CHECK-NEXT: [[Y:%.*]] = load i8*, i8** @global.1, align 4 16; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i32 [[X]], 17 17; CHECK-NEXT: br i1 [[TMP0]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]] 18; CHECK: loop.preheader: 19; CHECK-NEXT: br label [[LOOP:%.*]] 20; CHECK: loop: 21; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[LOOP]] ], [ [[X]], [[LOOP_PREHEADER]] ] 22; CHECK-NEXT: [[PTR:%.*]] = phi i8* [ [[PTR_NEXT:%.*]], [[LOOP]] ], [ [[Y]], [[LOOP_PREHEADER]] ] 23; CHECK-NEXT: [[IV_NEXT]] = add nuw i32 [[IV]], 8 24; CHECK-NEXT: [[PTR_NEXT]] = getelementptr inbounds i8, i8* [[PTR]], i32 1 25; CHECK-NEXT: store i8 [[ARG:%.*]], i8* [[PTR_NEXT]], align 1 26; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[IV_NEXT]], 17 27; CHECK-NEXT: br i1 [[TMP1]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]] 28; CHECK: exit.loopexit: 29; CHECK-NEXT: br label [[EXIT]] 30; CHECK: exit: 31; CHECK-NEXT: ret void 32; 33; UPPER-LABEL: @hoge_3( 34; UPPER-NEXT: entry: 35; UPPER-NEXT: [[X:%.*]] = load i32, i32* @global, align 4 36; UPPER-NEXT: [[Y:%.*]] = load i8*, i8** @global.1, align 4 37; UPPER-NEXT: [[TMP0:%.*]] = icmp ult i32 [[X]], 17 38; UPPER-NEXT: br i1 [[TMP0]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]] 39; UPPER: loop.preheader: 40; UPPER-NEXT: br label [[LOOP:%.*]] 41; UPPER: loop: 42; UPPER-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[LOOP]] ], [ [[X]], [[LOOP_PREHEADER]] ] 43; UPPER-NEXT: [[PTR:%.*]] = phi i8* [ [[PTR_NEXT:%.*]], [[LOOP]] ], [ [[Y]], [[LOOP_PREHEADER]] ] 44; UPPER-NEXT: [[IV_NEXT]] = add nuw i32 [[IV]], 8 45; UPPER-NEXT: [[PTR_NEXT]] = getelementptr inbounds i8, i8* [[PTR]], i32 1 46; UPPER-NEXT: store i8 [[ARG:%.*]], i8* [[PTR_NEXT]], align 1 47; UPPER-NEXT: [[TMP1:%.*]] = icmp ult i32 [[IV_NEXT]], 17 48; UPPER-NEXT: br i1 [[TMP1]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]] 49; UPPER: exit.loopexit: 50; UPPER-NEXT: br label [[EXIT]] 51; UPPER: exit: 52; UPPER-NEXT: ret void 53; 54entry: 55 %x = load i32, i32* @global, align 4 56 %y = load i8*, i8** @global.1, align 4 57 %0 = icmp ult i32 %x, 17 58 br i1 %0, label %loop, label %exit 59 60loop: 61 %iv = phi i32 [ %x, %entry ], [ %iv.next, %loop ] 62 %ptr = phi i8* [ %y, %entry ], [ %ptr.next, %loop ] 63 %iv.next = add nuw i32 %iv, 8 64 %ptr.next = getelementptr inbounds i8, i8* %ptr, i32 1 65 store i8 %arg, i8* %ptr.next, align 1 66 %1 = icmp ult i32 %iv.next, 17 67 br i1 %1, label %loop, label %exit 68 69exit: 70 ret void 71} 72 73; Check that loop in hoge_5, with a runtime upperbound of 5, is unrolled when -unroll-max-upperbound=4 74define dso_local void @hoge_5(i8 %arg) { 75; CHECK-LABEL: @hoge_5( 76; CHECK-NEXT: entry: 77; CHECK-NEXT: [[X:%.*]] = load i32, i32* @global, align 4 78; CHECK-NEXT: [[Y:%.*]] = load i8*, i8** @global.1, align 4 79; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i32 [[X]], 17 80; CHECK-NEXT: br i1 [[TMP0]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]] 81; CHECK: loop.preheader: 82; CHECK-NEXT: br label [[LOOP:%.*]] 83; CHECK: loop: 84; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[LOOP]] ], [ [[X]], [[LOOP_PREHEADER]] ] 85; CHECK-NEXT: [[PTR:%.*]] = phi i8* [ [[PTR_NEXT:%.*]], [[LOOP]] ], [ [[Y]], [[LOOP_PREHEADER]] ] 86; CHECK-NEXT: [[IV_NEXT]] = add nuw i32 [[IV]], 4 87; CHECK-NEXT: [[PTR_NEXT]] = getelementptr inbounds i8, i8* [[PTR]], i32 1 88; CHECK-NEXT: store i8 [[ARG:%.*]], i8* [[PTR_NEXT]], align 1 89; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[IV_NEXT]], 17 90; CHECK-NEXT: br i1 [[TMP1]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]] 91; CHECK: exit.loopexit: 92; CHECK-NEXT: br label [[EXIT]] 93; CHECK: exit: 94; CHECK-NEXT: ret void 95; 96; UPPER-LABEL: @hoge_5( 97; UPPER-NEXT: entry: 98; UPPER-NEXT: [[X:%.*]] = load i32, i32* @global, align 4 99; UPPER-NEXT: [[Y:%.*]] = load i8*, i8** @global.1, align 4 100; UPPER-NEXT: [[TMP0:%.*]] = icmp ult i32 [[X]], 17 101; UPPER-NEXT: br i1 [[TMP0]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]] 102; UPPER: loop.preheader: 103; UPPER-NEXT: [[TMP1:%.*]] = sub i32 16, [[X]] 104; UPPER-NEXT: [[TMP2:%.*]] = lshr i32 [[TMP1]], 2 105; UPPER-NEXT: [[TMP3:%.*]] = add nuw nsw i32 [[TMP2]], 1 106; UPPER-NEXT: [[TMP4:%.*]] = urem i32 [[TMP2]], 6 107; UPPER-NEXT: [[TMP5:%.*]] = add i32 [[TMP4]], 1 108; UPPER-NEXT: [[XTRAITER:%.*]] = urem i32 [[TMP5]], 6 109; UPPER-NEXT: [[LCMP_MOD:%.*]] = icmp ne i32 [[XTRAITER]], 0 110; UPPER-NEXT: br i1 [[LCMP_MOD]], label [[LOOP_PROL_PREHEADER:%.*]], label [[LOOP_PROL_LOOPEXIT:%.*]] 111; UPPER: loop.prol.preheader: 112; UPPER-NEXT: br label [[LOOP_PROL:%.*]] 113; UPPER: loop.prol: 114; UPPER-NEXT: [[IV_PROL:%.*]] = phi i32 [ [[IV_NEXT_PROL:%.*]], [[LOOP_PROL]] ], [ [[X]], [[LOOP_PROL_PREHEADER]] ] 115; UPPER-NEXT: [[PTR_PROL:%.*]] = phi i8* [ [[PTR_NEXT_PROL:%.*]], [[LOOP_PROL]] ], [ [[Y]], [[LOOP_PROL_PREHEADER]] ] 116; UPPER-NEXT: [[PROL_ITER:%.*]] = phi i32 [ [[XTRAITER]], [[LOOP_PROL_PREHEADER]] ], [ [[PROL_ITER_SUB:%.*]], [[LOOP_PROL]] ] 117; UPPER-NEXT: [[IV_NEXT_PROL]] = add nuw i32 [[IV_PROL]], 4 118; UPPER-NEXT: [[PTR_NEXT_PROL]] = getelementptr inbounds i8, i8* [[PTR_PROL]], i32 1 119; UPPER-NEXT: store i8 [[ARG:%.*]], i8* [[PTR_NEXT_PROL]], align 1 120; UPPER-NEXT: [[TMP6:%.*]] = icmp ult i32 [[IV_NEXT_PROL]], 17 121; UPPER-NEXT: [[PROL_ITER_SUB]] = sub i32 [[PROL_ITER]], 1 122; UPPER-NEXT: [[PROL_ITER_CMP:%.*]] = icmp ne i32 [[PROL_ITER_SUB]], 0 123; UPPER-NEXT: br i1 [[PROL_ITER_CMP]], label [[LOOP_PROL]], label [[LOOP_PROL_LOOPEXIT_UNR_LCSSA:%.*]], [[LOOP0:!llvm.loop !.*]] 124; UPPER: loop.prol.loopexit.unr-lcssa: 125; UPPER-NEXT: [[IV_UNR_PH:%.*]] = phi i32 [ [[IV_NEXT_PROL]], [[LOOP_PROL]] ] 126; UPPER-NEXT: [[PTR_UNR_PH:%.*]] = phi i8* [ [[PTR_NEXT_PROL]], [[LOOP_PROL]] ] 127; UPPER-NEXT: br label [[LOOP_PROL_LOOPEXIT]] 128; UPPER: loop.prol.loopexit: 129; UPPER-NEXT: [[IV_UNR:%.*]] = phi i32 [ [[X]], [[LOOP_PREHEADER]] ], [ [[IV_UNR_PH]], [[LOOP_PROL_LOOPEXIT_UNR_LCSSA]] ] 130; UPPER-NEXT: [[PTR_UNR:%.*]] = phi i8* [ [[Y]], [[LOOP_PREHEADER]] ], [ [[PTR_UNR_PH]], [[LOOP_PROL_LOOPEXIT_UNR_LCSSA]] ] 131; UPPER-NEXT: [[TMP7:%.*]] = icmp ult i32 [[TMP2]], 5 132; UPPER-NEXT: br i1 [[TMP7]], label [[EXIT_LOOPEXIT:%.*]], label [[LOOP_PREHEADER_NEW:%.*]] 133; UPPER: loop.preheader.new: 134; UPPER-NEXT: br label [[LOOP:%.*]] 135; UPPER: loop: 136; UPPER-NEXT: [[IV:%.*]] = phi i32 [ [[IV_UNR]], [[LOOP_PREHEADER_NEW]] ], [ [[IV_NEXT_5:%.*]], [[LOOP]] ] 137; UPPER-NEXT: [[PTR:%.*]] = phi i8* [ [[PTR_UNR]], [[LOOP_PREHEADER_NEW]] ], [ [[PTR_NEXT_5:%.*]], [[LOOP]] ] 138; UPPER-NEXT: [[IV_NEXT:%.*]] = add nuw i32 [[IV]], 4 139; UPPER-NEXT: [[PTR_NEXT:%.*]] = getelementptr inbounds i8, i8* [[PTR]], i32 1 140; UPPER-NEXT: store i8 [[ARG]], i8* [[PTR_NEXT]], align 1 141; UPPER-NEXT: [[IV_NEXT_1:%.*]] = add nuw i32 [[IV_NEXT]], 4 142; UPPER-NEXT: [[PTR_NEXT_1:%.*]] = getelementptr inbounds i8, i8* [[PTR_NEXT]], i32 1 143; UPPER-NEXT: store i8 [[ARG]], i8* [[PTR_NEXT_1]], align 1 144; UPPER-NEXT: [[IV_NEXT_2:%.*]] = add nuw i32 [[IV_NEXT_1]], 4 145; UPPER-NEXT: [[PTR_NEXT_2:%.*]] = getelementptr inbounds i8, i8* [[PTR_NEXT_1]], i32 1 146; UPPER-NEXT: store i8 [[ARG]], i8* [[PTR_NEXT_2]], align 1 147; UPPER-NEXT: [[IV_NEXT_3:%.*]] = add nuw i32 [[IV_NEXT_2]], 4 148; UPPER-NEXT: [[PTR_NEXT_3:%.*]] = getelementptr inbounds i8, i8* [[PTR_NEXT_2]], i32 1 149; UPPER-NEXT: store i8 [[ARG]], i8* [[PTR_NEXT_3]], align 1 150; UPPER-NEXT: [[IV_NEXT_4:%.*]] = add nuw i32 [[IV_NEXT_3]], 4 151; UPPER-NEXT: [[PTR_NEXT_4:%.*]] = getelementptr inbounds i8, i8* [[PTR_NEXT_3]], i32 1 152; UPPER-NEXT: store i8 [[ARG]], i8* [[PTR_NEXT_4]], align 1 153; UPPER-NEXT: [[IV_NEXT_5]] = add nuw i32 [[IV_NEXT_4]], 4 154; UPPER-NEXT: [[PTR_NEXT_5]] = getelementptr inbounds i8, i8* [[PTR_NEXT_4]], i32 1 155; UPPER-NEXT: store i8 [[ARG]], i8* [[PTR_NEXT_5]], align 1 156; UPPER-NEXT: [[TMP8:%.*]] = icmp ult i32 [[IV_NEXT_5]], 17 157; UPPER-NEXT: br i1 [[TMP8]], label [[LOOP]], label [[EXIT_LOOPEXIT_UNR_LCSSA:%.*]] 158; UPPER: exit.loopexit.unr-lcssa: 159; UPPER-NEXT: br label [[EXIT_LOOPEXIT]] 160; UPPER: exit.loopexit: 161; UPPER-NEXT: br label [[EXIT]] 162; UPPER: exit: 163; UPPER-NEXT: ret void 164; 165entry: 166 %x = load i32, i32* @global, align 4 167 %y = load i8*, i8** @global.1, align 4 168 %0 = icmp ult i32 %x, 17 169 br i1 %0, label %loop, label %exit 170 171loop: 172 %iv = phi i32 [ %x, %entry ], [ %iv.next, %loop ] 173 %ptr = phi i8* [ %y, %entry ], [ %ptr.next, %loop ] 174 %iv.next = add nuw i32 %iv, 4 175 %ptr.next = getelementptr inbounds i8, i8* %ptr, i32 1 176 store i8 %arg, i8* %ptr.next, align 1 177 %1 = icmp ult i32 %iv.next, 17 178 br i1 %1, label %loop, label %exit 179 180exit: 181 ret void 182} 183