|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 |
| 2 | +; RUN: opt < %s -S -passes=simplifycfg | FileCheck %s --check-prefixes=CHECK-CFG |
| 3 | +; RUN: opt < %s -S -passes=simplifycfg,loop-unroll --unroll-max-upperbound=17 | FileCheck %s --check-prefixes=CHECK-UNROLL |
| 4 | + |
| 5 | +define void @func(i32 noundef %Idx, ptr noundef %Arr, i32 noundef %Dims, ptr noundef %Out) { |
| 6 | +; CHECK-CFG-LABEL: define void @func( |
| 7 | +; CHECK-CFG-SAME: i32 noundef [[IDX:%.*]], ptr noundef [[ARR:%.*]], i32 noundef [[DIMS:%.*]], ptr noundef [[OUT:%.*]]) { |
| 8 | +; CHECK-CFG-NEXT: entry: |
| 9 | +; CHECK-CFG-NEXT: br label [[FOR_COND:%.*]] |
| 10 | +; CHECK-CFG: for.cond: |
| 11 | +; CHECK-CFG-NEXT: [[DIM_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC16:%.*]], [[FOR_COND_CLEANUP6:%.*]] ] |
| 12 | +; CHECK-CFG-NEXT: [[IDX_ADDR_0:%.*]] = phi i32 [ [[IDX]], [[ENTRY]] ], [ [[ADD:%.*]], [[FOR_COND_CLEANUP6]] ] |
| 13 | +; CHECK-CFG-NEXT: [[CMP:%.*]] = icmp sge i32 [[DIM_0]], 16 |
| 14 | +; CHECK-CFG-NEXT: [[CMP1:%.*]] = icmp eq i32 [[DIM_0]], [[DIMS]] |
| 15 | +; CHECK-CFG-NEXT: [[OR_COND:%.*]] = or i1 [[CMP]], [[CMP1]] |
| 16 | +; CHECK-CFG-NEXT: br i1 [[OR_COND]], label [[CLEANUP:%.*]], label [[IF_END:%.*]] |
| 17 | +; CHECK-CFG: if.end: |
| 18 | +; CHECK-CFG-NEXT: [[IDXPROM:%.*]] = sext i32 [[DIM_0]] to i64 |
| 19 | +; CHECK-CFG-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds ptr, ptr [[ARR]], i64 [[IDXPROM]] |
| 20 | +; CHECK-CFG-NEXT: [[TMP0:%.*]] = load ptr, ptr [[ARRAYIDX]], align 8 |
| 21 | +; CHECK-CFG-NEXT: [[IDXPROM2:%.*]] = sext i32 [[IDX_ADDR_0]] to i64 |
| 22 | +; CHECK-CFG-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds i32, ptr [[TMP0]], i64 [[IDXPROM2]] |
| 23 | +; CHECK-CFG-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARRAYIDX3]], align 4 |
| 24 | +; CHECK-CFG-NEXT: [[ADD]] = add nsw i32 [[TMP1]], 1 |
| 25 | +; CHECK-CFG-NEXT: br label [[FOR_COND4:%.*]] |
| 26 | +; CHECK-CFG: for.cond4: |
| 27 | +; CHECK-CFG-NEXT: [[ARG_0:%.*]] = phi i32 [ 0, [[IF_END]] ], [ [[INC:%.*]], [[FOR_BODY7:%.*]] ] |
| 28 | +; CHECK-CFG-NEXT: [[CMP5:%.*]] = icmp slt i32 [[ARG_0]], 4 |
| 29 | +; CHECK-CFG-NEXT: br i1 [[CMP5]], label [[FOR_BODY7]], label [[FOR_COND_CLEANUP6]] |
| 30 | +; CHECK-CFG: for.cond.cleanup6: |
| 31 | +; CHECK-CFG-NEXT: [[INC16]] = add nsw i32 [[DIM_0]], 1 |
| 32 | +; CHECK-CFG-NEXT: br label [[FOR_COND]], !llvm.loop [[LOOP0:![0-9]+]] |
| 33 | +; CHECK-CFG: for.body7: |
| 34 | +; CHECK-CFG-NEXT: [[TMP2:%.*]] = load ptr, ptr [[ARRAYIDX]], align 8 |
| 35 | +; CHECK-CFG-NEXT: [[IDXPROM10:%.*]] = sext i32 [[ARG_0]] to i64 |
| 36 | +; CHECK-CFG-NEXT: [[ARRAYIDX11:%.*]] = getelementptr inbounds i32, ptr [[TMP2]], i64 [[IDXPROM10]] |
| 37 | +; CHECK-CFG-NEXT: [[TMP3:%.*]] = load i32, ptr [[ARRAYIDX11]], align 4 |
| 38 | +; CHECK-CFG-NEXT: [[ARRAYIDX13:%.*]] = getelementptr inbounds i32, ptr [[OUT]], i64 [[IDXPROM10]] |
| 39 | +; CHECK-CFG-NEXT: [[TMP4:%.*]] = load i32, ptr [[ARRAYIDX13]], align 4 |
| 40 | +; CHECK-CFG-NEXT: [[ADD14:%.*]] = add nsw i32 [[TMP4]], [[TMP3]] |
| 41 | +; CHECK-CFG-NEXT: store i32 [[ADD14]], ptr [[ARRAYIDX13]], align 4 |
| 42 | +; CHECK-CFG-NEXT: call void @_Z3barv() |
| 43 | +; CHECK-CFG-NEXT: [[INC]] = add nsw i32 [[ARG_0]], 1 |
| 44 | +; CHECK-CFG-NEXT: br label [[FOR_COND4]], !llvm.loop [[LOOP3:![0-9]+]] |
| 45 | +; CHECK-CFG: cleanup: |
| 46 | +; CHECK-CFG-NEXT: ret void |
| 47 | +; |
| 48 | +; CHECK-UNROLL-LABEL: define void @func( |
| 49 | +; CHECK-UNROLL-SAME: i32 noundef [[IDX:%.*]], ptr noundef [[ARR:%.*]], i32 noundef [[DIMS:%.*]], ptr noundef [[OUT:%.*]]) { |
| 50 | +; CHECK-UNROLL-NEXT: entry: |
| 51 | +; CHECK-UNROLL-NEXT: br label [[FOR_COND:%.*]] |
| 52 | +; CHECK-UNROLL: for.cond: |
| 53 | +; CHECK-UNROLL-NEXT: [[DIM_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC16:%.*]], [[FOR_COND_CLEANUP6:%.*]] ] |
| 54 | +; CHECK-UNROLL-NEXT: [[IDX_ADDR_0:%.*]] = phi i32 [ [[IDX]], [[ENTRY]] ], [ [[ADD:%.*]], [[FOR_COND_CLEANUP6]] ] |
| 55 | +; CHECK-UNROLL-NEXT: [[CMP:%.*]] = icmp sge i32 [[DIM_0]], 16 |
| 56 | +; CHECK-UNROLL-NEXT: [[CMP1:%.*]] = icmp eq i32 [[DIM_0]], [[DIMS]] |
| 57 | +; CHECK-UNROLL-NEXT: [[OR_COND:%.*]] = or i1 [[CMP]], [[CMP1]] |
| 58 | +; CHECK-UNROLL-NEXT: br i1 [[OR_COND]], label [[CLEANUP:%.*]], label [[IF_END:%.*]] |
| 59 | +; CHECK-UNROLL: if.end: |
| 60 | +; CHECK-UNROLL-NEXT: [[IDXPROM:%.*]] = sext i32 [[DIM_0]] to i64 |
| 61 | +; CHECK-UNROLL-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds ptr, ptr [[ARR]], i64 [[IDXPROM]] |
| 62 | +; CHECK-UNROLL-NEXT: [[TMP0:%.*]] = load ptr, ptr [[ARRAYIDX]], align 8 |
| 63 | +; CHECK-UNROLL-NEXT: [[IDXPROM2:%.*]] = sext i32 [[IDX_ADDR_0]] to i64 |
| 64 | +; CHECK-UNROLL-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds i32, ptr [[TMP0]], i64 [[IDXPROM2]] |
| 65 | +; CHECK-UNROLL-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARRAYIDX3]], align 4 |
| 66 | +; CHECK-UNROLL-NEXT: [[ADD]] = add nsw i32 [[TMP1]], 1 |
| 67 | +; CHECK-UNROLL-NEXT: br label [[FOR_COND4:%.*]] |
| 68 | +; CHECK-UNROLL: for.cond4: |
| 69 | +; CHECK-UNROLL-NEXT: br label [[FOR_BODY7:%.*]] |
| 70 | +; CHECK-UNROLL: for.cond.cleanup6: |
| 71 | +; CHECK-UNROLL-NEXT: [[INC16]] = add nsw i32 [[DIM_0]], 1 |
| 72 | +; CHECK-UNROLL-NEXT: br label [[FOR_COND]], !llvm.loop [[LOOP0:![0-9]+]] |
| 73 | +; CHECK-UNROLL: for.body7: |
| 74 | +; CHECK-UNROLL-NEXT: [[TMP2:%.*]] = load ptr, ptr [[ARRAYIDX]], align 8 |
| 75 | +; CHECK-UNROLL-NEXT: [[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4 |
| 76 | +; CHECK-UNROLL-NEXT: [[TMP4:%.*]] = load i32, ptr [[OUT]], align 4 |
| 77 | +; CHECK-UNROLL-NEXT: [[ADD14:%.*]] = add nsw i32 [[TMP4]], [[TMP3]] |
| 78 | +; CHECK-UNROLL-NEXT: store i32 [[ADD14]], ptr [[OUT]], align 4 |
| 79 | +; CHECK-UNROLL-NEXT: call void @_Z3barv() |
| 80 | +; CHECK-UNROLL-NEXT: br label [[FOR_BODY7_1:%.*]] |
| 81 | +; CHECK-UNROLL: for.body7.1: |
| 82 | +; CHECK-UNROLL-NEXT: [[TMP5:%.*]] = load ptr, ptr [[ARRAYIDX]], align 8 |
| 83 | +; CHECK-UNROLL-NEXT: [[ARRAYIDX11_1:%.*]] = getelementptr inbounds i32, ptr [[TMP5]], i64 1 |
| 84 | +; CHECK-UNROLL-NEXT: [[TMP6:%.*]] = load i32, ptr [[ARRAYIDX11_1]], align 4 |
| 85 | +; CHECK-UNROLL-NEXT: [[ARRAYIDX13_1:%.*]] = getelementptr inbounds i32, ptr [[OUT]], i64 1 |
| 86 | +; CHECK-UNROLL-NEXT: [[TMP7:%.*]] = load i32, ptr [[ARRAYIDX13_1]], align 4 |
| 87 | +; CHECK-UNROLL-NEXT: [[ADD14_1:%.*]] = add nsw i32 [[TMP7]], [[TMP6]] |
| 88 | +; CHECK-UNROLL-NEXT: store i32 [[ADD14_1]], ptr [[ARRAYIDX13_1]], align 4 |
| 89 | +; CHECK-UNROLL-NEXT: call void @_Z3barv() |
| 90 | +; CHECK-UNROLL-NEXT: br label [[FOR_BODY7_2:%.*]] |
| 91 | +; CHECK-UNROLL: for.body7.2: |
| 92 | +; CHECK-UNROLL-NEXT: [[TMP8:%.*]] = load ptr, ptr [[ARRAYIDX]], align 8 |
| 93 | +; CHECK-UNROLL-NEXT: [[ARRAYIDX11_2:%.*]] = getelementptr inbounds i32, ptr [[TMP8]], i64 2 |
| 94 | +; CHECK-UNROLL-NEXT: [[TMP9:%.*]] = load i32, ptr [[ARRAYIDX11_2]], align 4 |
| 95 | +; CHECK-UNROLL-NEXT: [[ARRAYIDX13_2:%.*]] = getelementptr inbounds i32, ptr [[OUT]], i64 2 |
| 96 | +; CHECK-UNROLL-NEXT: [[TMP10:%.*]] = load i32, ptr [[ARRAYIDX13_2]], align 4 |
| 97 | +; CHECK-UNROLL-NEXT: [[ADD14_2:%.*]] = add nsw i32 [[TMP10]], [[TMP9]] |
| 98 | +; CHECK-UNROLL-NEXT: store i32 [[ADD14_2]], ptr [[ARRAYIDX13_2]], align 4 |
| 99 | +; CHECK-UNROLL-NEXT: call void @_Z3barv() |
| 100 | +; CHECK-UNROLL-NEXT: br label [[FOR_BODY7_3:%.*]] |
| 101 | +; CHECK-UNROLL: for.body7.3: |
| 102 | +; CHECK-UNROLL-NEXT: [[TMP11:%.*]] = load ptr, ptr [[ARRAYIDX]], align 8 |
| 103 | +; CHECK-UNROLL-NEXT: [[ARRAYIDX11_3:%.*]] = getelementptr inbounds i32, ptr [[TMP11]], i64 3 |
| 104 | +; CHECK-UNROLL-NEXT: [[TMP12:%.*]] = load i32, ptr [[ARRAYIDX11_3]], align 4 |
| 105 | +; CHECK-UNROLL-NEXT: [[ARRAYIDX13_3:%.*]] = getelementptr inbounds i32, ptr [[OUT]], i64 3 |
| 106 | +; CHECK-UNROLL-NEXT: [[TMP13:%.*]] = load i32, ptr [[ARRAYIDX13_3]], align 4 |
| 107 | +; CHECK-UNROLL-NEXT: [[ADD14_3:%.*]] = add nsw i32 [[TMP13]], [[TMP12]] |
| 108 | +; CHECK-UNROLL-NEXT: store i32 [[ADD14_3]], ptr [[ARRAYIDX13_3]], align 4 |
| 109 | +; CHECK-UNROLL-NEXT: call void @_Z3barv() |
| 110 | +; CHECK-UNROLL-NEXT: br i1 false, label [[FOR_BODY7_4:%.*]], label [[FOR_COND_CLEANUP6]] |
| 111 | +; CHECK-UNROLL: for.body7.4: |
| 112 | +; CHECK-UNROLL-NEXT: [[ARRAYIDX_LCSSA:%.*]] = phi ptr [ [[ARRAYIDX]], [[FOR_BODY7_3]] ] |
| 113 | +; CHECK-UNROLL-NEXT: [[TMP14:%.*]] = load ptr, ptr [[ARRAYIDX_LCSSA]], align 8 |
| 114 | +; CHECK-UNROLL-NEXT: [[ARRAYIDX11_4:%.*]] = getelementptr inbounds i32, ptr [[TMP14]], i64 4 |
| 115 | +; CHECK-UNROLL-NEXT: [[TMP15:%.*]] = load i32, ptr [[ARRAYIDX11_4]], align 4 |
| 116 | +; CHECK-UNROLL-NEXT: [[ARRAYIDX13_4:%.*]] = getelementptr inbounds i32, ptr [[OUT]], i64 4 |
| 117 | +; CHECK-UNROLL-NEXT: [[TMP16:%.*]] = load i32, ptr [[ARRAYIDX13_4]], align 4 |
| 118 | +; CHECK-UNROLL-NEXT: [[ADD14_4:%.*]] = add nsw i32 [[TMP16]], [[TMP15]] |
| 119 | +; CHECK-UNROLL-NEXT: store i32 [[ADD14_4]], ptr [[ARRAYIDX13_4]], align 4 |
| 120 | +; CHECK-UNROLL-NEXT: call void @_Z3barv() |
| 121 | +; CHECK-UNROLL-NEXT: unreachable |
| 122 | +; CHECK-UNROLL: cleanup: |
| 123 | +; CHECK-UNROLL-NEXT: ret void |
| 124 | +; |
| 125 | +entry: |
| 126 | + br label %for.cond |
| 127 | + |
| 128 | +for.cond: ; preds = %for.cond.cleanup6, %entry |
| 129 | + %Dim.0 = phi i32 [ 0, %entry ], [ %inc16, %for.cond.cleanup6 ] |
| 130 | + %Idx.addr.0 = phi i32 [ %Idx, %entry ], [ %add, %for.cond.cleanup6 ] |
| 131 | + %cmp = icmp slt i32 %Dim.0, 16 |
| 132 | + br i1 %cmp, label %for.body, label %for.cond.cleanup |
| 133 | + |
| 134 | +for.cond.cleanup: ; preds = %for.cond |
| 135 | + br label %cleanup |
| 136 | + |
| 137 | +for.body: ; preds = %for.cond |
| 138 | + %cmp1 = icmp eq i32 %Dim.0, %Dims |
| 139 | + br i1 %cmp1, label %if.then, label %if.end |
| 140 | + |
| 141 | +if.then: ; preds = %for.body |
| 142 | + br label %cleanup |
| 143 | + |
| 144 | +if.end: ; preds = %for.body |
| 145 | + %idxprom = sext i32 %Dim.0 to i64 |
| 146 | + %arrayidx = getelementptr inbounds ptr, ptr %Arr, i64 %idxprom |
| 147 | + %0 = load ptr, ptr %arrayidx, align 8 |
| 148 | + %idxprom2 = sext i32 %Idx.addr.0 to i64 |
| 149 | + %arrayidx3 = getelementptr inbounds i32, ptr %0, i64 %idxprom2 |
| 150 | + %1 = load i32, ptr %arrayidx3, align 4 |
| 151 | + %add = add nsw i32 %1, 1 |
| 152 | + br label %for.cond4 |
| 153 | + |
| 154 | +for.cond4: ; preds = %for.body7, %if.end |
| 155 | + %arg.0 = phi i32 [ 0, %if.end ], [ %inc, %for.body7 ] |
| 156 | + %cmp5 = icmp slt i32 %arg.0, 4 |
| 157 | + br i1 %cmp5, label %for.body7, label %for.cond.cleanup6 |
| 158 | + |
| 159 | +for.cond.cleanup6: ; preds = %for.cond4 |
| 160 | + %inc16 = add nsw i32 %Dim.0, 1 |
| 161 | + br label %for.cond, !llvm.loop !0 |
| 162 | + |
| 163 | +for.body7: ; preds = %for.cond4 |
| 164 | + %2 = load ptr, ptr %arrayidx, align 8 |
| 165 | + %idxprom10 = sext i32 %arg.0 to i64 |
| 166 | + %arrayidx11 = getelementptr inbounds i32, ptr %2, i64 %idxprom10 |
| 167 | + %3 = load i32, ptr %arrayidx11, align 4 |
| 168 | + %arrayidx13 = getelementptr inbounds i32, ptr %Out, i64 %idxprom10 |
| 169 | + %4 = load i32, ptr %arrayidx13, align 4 |
| 170 | + %add14 = add nsw i32 %4, %3 |
| 171 | + store i32 %add14, ptr %arrayidx13, align 4 |
| 172 | + call void @_Z3barv() |
| 173 | + %inc = add nsw i32 %arg.0, 1 |
| 174 | + br label %for.cond4, !llvm.loop !3 |
| 175 | + |
| 176 | +cleanup: ; preds = %if.then, %for.cond.cleanup |
| 177 | + ret void |
| 178 | +} |
| 179 | + |
| 180 | + declare void @_Z3barv() |
| 181 | + |
| 182 | +!0 = distinct !{!0, !1, !2} |
| 183 | +!1 = !{!"llvm.loop.mustprogress"} |
| 184 | +!2 = !{!"llvm.loop.unroll.enable"} |
| 185 | +!3 = distinct !{!3, !1} |
| 186 | +; CHECK-CFG: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]]} |
| 187 | +; CHECK-CFG: [[META1]] = !{!"llvm.loop.mustprogress"} |
| 188 | +; CHECK-CFG: [[META2]] = !{!"llvm.loop.unroll.enable"} |
| 189 | +; CHECK-CFG: [[LOOP3]] = distinct !{[[LOOP3]], [[META1]]} |
| 190 | +;. |
| 191 | +; CHECK-UNROLL: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]]} |
| 192 | +; CHECK-UNROLL: [[META1]] = !{!"llvm.loop.mustprogress"} |
| 193 | +; CHECK-UNROLL: [[META2]] = !{!"llvm.loop.unroll.enable"} |
| 194 | +;. |
0 commit comments