|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 5 |
| 2 | +; RUN: opt -p loop-vectorize -mtriple=aarch64 -mattr=+sve -S %s | FileCheck %s |
| 3 | + |
| 4 | +define void @nested(ptr noalias %p0, ptr noalias %p1, i1 %c0, i1 %c1) { |
| 5 | +; CHECK-LABEL: define void @nested( |
| 6 | +; CHECK-SAME: ptr noalias [[P0:%.*]], ptr noalias [[P1:%.*]], i1 [[C0:%.*]], i1 [[C1:%.*]]) #[[ATTR0:[0-9]+]] { |
| 7 | +; CHECK-NEXT: [[ENTRY:.*]]: |
| 8 | +; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.vscale.i32() |
| 9 | +; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i32 [[TMP0]], 2 |
| 10 | +; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 1024, [[TMP1]] |
| 11 | +; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] |
| 12 | +; CHECK: [[VECTOR_PH]]: |
| 13 | +; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.vscale.i32() |
| 14 | +; CHECK-NEXT: [[TMP3:%.*]] = mul nuw i32 [[TMP2]], 4 |
| 15 | +; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 1024, [[TMP3]] |
| 16 | +; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 1024, [[N_MOD_VF]] |
| 17 | +; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i1> poison, i1 [[C1]], i64 0 |
| 18 | +; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i1> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i1> poison, <vscale x 2 x i32> zeroinitializer |
| 19 | +; CHECK-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <vscale x 2 x i1> poison, i1 [[C0]], i64 0 |
| 20 | +; CHECK-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <vscale x 2 x i1> [[BROADCAST_SPLATINSERT1]], <vscale x 2 x i1> poison, <vscale x 2 x i32> zeroinitializer |
| 21 | +; CHECK-NEXT: [[TMP4:%.*]] = select <vscale x 2 x i1> [[BROADCAST_SPLAT2]], <vscale x 2 x i1> [[BROADCAST_SPLAT]], <vscale x 2 x i1> zeroinitializer |
| 22 | +; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] |
| 23 | +; CHECK: [[VECTOR_BODY]]: |
| 24 | +; CHECK-NEXT: [[IV1:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] |
| 25 | +; CHECK-NEXT: [[TMP5:%.*]] = getelementptr i64, ptr [[P0]], i32 [[IV1]] |
| 26 | +; CHECK-NEXT: [[TMP6:%.*]] = call i64 @llvm.vscale.i64() |
| 27 | +; CHECK-NEXT: [[TMP7:%.*]] = shl nuw i64 [[TMP6]], 1 |
| 28 | +; CHECK-NEXT: [[TMP8:%.*]] = getelementptr i64, ptr [[TMP5]], i64 [[TMP7]] |
| 29 | +; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <vscale x 2 x i64> @llvm.masked.load.nxv2i64.p0(ptr [[TMP5]], i32 8, <vscale x 2 x i1> [[TMP4]], <vscale x 2 x i64> poison) |
| 30 | +; CHECK-NEXT: [[WIDE_MASKED_LOAD3:%.*]] = call <vscale x 2 x i64> @llvm.masked.load.nxv2i64.p0(ptr [[TMP8]], i32 8, <vscale x 2 x i1> [[TMP4]], <vscale x 2 x i64> poison) |
| 31 | +; CHECK-NEXT: [[TMP9:%.*]] = getelementptr i64, ptr [[P1]], i32 [[IV1]] |
| 32 | +; CHECK-NEXT: [[TMP10:%.*]] = call i64 @llvm.vscale.i64() |
| 33 | +; CHECK-NEXT: [[TMP11:%.*]] = shl nuw i64 [[TMP10]], 1 |
| 34 | +; CHECK-NEXT: [[TMP12:%.*]] = getelementptr i64, ptr [[TMP9]], i64 [[TMP11]] |
| 35 | +; CHECK-NEXT: [[WIDE_MASKED_LOAD4:%.*]] = call <vscale x 2 x i64> @llvm.masked.load.nxv2i64.p0(ptr [[TMP9]], i32 8, <vscale x 2 x i1> [[TMP4]], <vscale x 2 x i64> poison) |
| 36 | +; CHECK-NEXT: [[WIDE_MASKED_LOAD5:%.*]] = call <vscale x 2 x i64> @llvm.masked.load.nxv2i64.p0(ptr [[TMP12]], i32 8, <vscale x 2 x i1> [[TMP4]], <vscale x 2 x i64> poison) |
| 37 | +; CHECK-NEXT: [[TMP13:%.*]] = select <vscale x 2 x i1> [[TMP4]], <vscale x 2 x i64> [[WIDE_MASKED_LOAD4]], <vscale x 2 x i64> splat (i64 1) |
| 38 | +; CHECK-NEXT: [[TMP14:%.*]] = select <vscale x 2 x i1> [[TMP4]], <vscale x 2 x i64> [[WIDE_MASKED_LOAD5]], <vscale x 2 x i64> splat (i64 1) |
| 39 | +; CHECK-NEXT: [[TMP15:%.*]] = udiv <vscale x 2 x i64> [[WIDE_MASKED_LOAD]], [[TMP13]] |
| 40 | +; CHECK-NEXT: [[TMP16:%.*]] = udiv <vscale x 2 x i64> [[WIDE_MASKED_LOAD3]], [[TMP14]] |
| 41 | +; CHECK-NEXT: [[TMP17:%.*]] = call i64 @llvm.vscale.i64() |
| 42 | +; CHECK-NEXT: [[TMP18:%.*]] = shl nuw i64 [[TMP17]], 1 |
| 43 | +; CHECK-NEXT: [[TMP19:%.*]] = getelementptr i64, ptr [[TMP9]], i64 [[TMP18]] |
| 44 | +; CHECK-NEXT: call void @llvm.masked.store.nxv2i64.p0(<vscale x 2 x i64> [[TMP15]], ptr [[TMP9]], i32 8, <vscale x 2 x i1> [[TMP4]]) |
| 45 | +; CHECK-NEXT: call void @llvm.masked.store.nxv2i64.p0(<vscale x 2 x i64> [[TMP16]], ptr [[TMP19]], i32 8, <vscale x 2 x i1> [[TMP4]]) |
| 46 | +; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[IV1]], [[TMP3]] |
| 47 | +; CHECK-NEXT: [[TMP20:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]] |
| 48 | +; CHECK-NEXT: br i1 [[TMP20]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]] |
| 49 | +; CHECK: [[MIDDLE_BLOCK]]: |
| 50 | +; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 1024, [[N_VEC]] |
| 51 | +; CHECK-NEXT: br i1 [[CMP_N]], label %[[EXIT:.*]], label %[[SCALAR_PH]] |
| 52 | +; CHECK: [[SCALAR_PH]]: |
| 53 | +; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ] |
| 54 | +; CHECK-NEXT: br label %[[LOOP:.*]] |
| 55 | +; CHECK: [[LOOP]]: |
| 56 | +; CHECK-NEXT: [[X:%.*]] = phi i32 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LATCH:.*]] ] |
| 57 | +; CHECK-NEXT: br i1 [[C0]], label %[[THEN_0:.*]], label %[[LATCH]] |
| 58 | +; CHECK: [[THEN_0]]: |
| 59 | +; CHECK-NEXT: br i1 [[C1]], label %[[THEN_1:.*]], label %[[LATCH]] |
| 60 | +; CHECK: [[THEN_1]]: |
| 61 | +; CHECK-NEXT: [[GEP0:%.*]] = getelementptr i64, ptr [[P0]], i32 [[X]] |
| 62 | +; CHECK-NEXT: [[X1:%.*]] = load i64, ptr [[GEP0]], align 8 |
| 63 | +; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i64, ptr [[P1]], i32 [[X]] |
| 64 | +; CHECK-NEXT: [[Y:%.*]] = load i64, ptr [[GEP1]], align 8 |
| 65 | +; CHECK-NEXT: [[Z:%.*]] = udiv i64 [[X1]], [[Y]] |
| 66 | +; CHECK-NEXT: store i64 [[Z]], ptr [[GEP1]], align 8 |
| 67 | +; CHECK-NEXT: br label %[[LATCH]] |
| 68 | +; CHECK: [[LATCH]]: |
| 69 | +; CHECK-NEXT: [[IV_NEXT]] = add i32 [[X]], 1 |
| 70 | +; CHECK-NEXT: [[DONE:%.*]] = icmp eq i32 [[IV_NEXT]], 1024 |
| 71 | +; CHECK-NEXT: br i1 [[DONE]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP3:![0-9]+]] |
| 72 | +; CHECK: [[EXIT]]: |
| 73 | +; CHECK-NEXT: ret void |
| 74 | +; |
| 75 | +entry: |
| 76 | + br label %loop |
| 77 | + |
| 78 | +loop: |
| 79 | + %iv = phi i32 [ 0, %entry ], [ %iv.next, %latch ] |
| 80 | + br i1 %c0, label %then.0, label %latch |
| 81 | + |
| 82 | +then.0: |
| 83 | + br i1 %c1, label %then.1, label %latch |
| 84 | + |
| 85 | +then.1: |
| 86 | + %gep0 = getelementptr i64, ptr %p0, i32 %iv |
| 87 | + %x = load i64, ptr %gep0 |
| 88 | + %gep1 = getelementptr i64, ptr %p1, i32 %iv |
| 89 | + %y = load i64, ptr %gep1 |
| 90 | + %z = udiv i64 %x, %y |
| 91 | + store i64 %z, ptr %gep1 |
| 92 | + br label %latch |
| 93 | + |
| 94 | +latch: |
| 95 | + %iv.next = add i32 %iv, 1 |
| 96 | + %done = icmp eq i32 %iv.next, 1024 |
| 97 | + br i1 %done, label %exit, label %loop |
| 98 | + |
| 99 | +exit: |
| 100 | + ret void |
| 101 | +} |
| 102 | + |
| 103 | +define void @always_taken(ptr noalias %p0, ptr noalias %p1, i1 %c0, i1 %c1) { |
| 104 | +; CHECK-LABEL: define void @always_taken( |
| 105 | +; CHECK-SAME: ptr noalias [[P0:%.*]], ptr noalias [[P1:%.*]], i1 [[C0:%.*]], i1 [[C1:%.*]]) #[[ATTR0]] { |
| 106 | +; CHECK-NEXT: [[ENTRY:.*]]: |
| 107 | +; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.vscale.i32() |
| 108 | +; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i32 [[TMP0]], 2 |
| 109 | +; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 1024, [[TMP1]] |
| 110 | +; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] |
| 111 | +; CHECK: [[VECTOR_PH]]: |
| 112 | +; CHECK-NEXT: [[TMP4:%.*]] = call i32 @llvm.vscale.i32() |
| 113 | +; CHECK-NEXT: [[TMP5:%.*]] = mul nuw i32 [[TMP4]], 4 |
| 114 | +; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 1024, [[TMP5]] |
| 115 | +; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 1024, [[N_MOD_VF]] |
| 116 | +; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i1> poison, i1 [[C1]], i64 0 |
| 117 | +; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i1> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i1> poison, <vscale x 2 x i32> zeroinitializer |
| 118 | +; CHECK-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <vscale x 2 x i1> poison, i1 [[C0]], i64 0 |
| 119 | +; CHECK-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <vscale x 2 x i1> [[BROADCAST_SPLATINSERT1]], <vscale x 2 x i1> poison, <vscale x 2 x i32> zeroinitializer |
| 120 | +; CHECK-NEXT: [[TMP6:%.*]] = select <vscale x 2 x i1> [[BROADCAST_SPLAT2]], <vscale x 2 x i1> [[BROADCAST_SPLAT]], <vscale x 2 x i1> zeroinitializer |
| 121 | +; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] |
| 122 | +; CHECK: [[VECTOR_BODY]]: |
| 123 | +; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] |
| 124 | +; CHECK-NEXT: [[TMP10:%.*]] = getelementptr i64, ptr [[P0]], i32 [[INDEX]] |
| 125 | +; CHECK-NEXT: [[TMP8:%.*]] = call i64 @llvm.vscale.i64() |
| 126 | +; CHECK-NEXT: [[TMP7:%.*]] = shl nuw i64 [[TMP8]], 1 |
| 127 | +; CHECK-NEXT: [[TMP20:%.*]] = getelementptr i64, ptr [[TMP10]], i64 [[TMP7]] |
| 128 | +; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <vscale x 2 x i64> @llvm.masked.load.nxv2i64.p0(ptr [[TMP10]], i32 8, <vscale x 2 x i1> [[TMP6]], <vscale x 2 x i64> poison) |
| 129 | +; CHECK-NEXT: [[WIDE_MASKED_LOAD3:%.*]] = call <vscale x 2 x i64> @llvm.masked.load.nxv2i64.p0(ptr [[TMP20]], i32 8, <vscale x 2 x i1> [[TMP6]], <vscale x 2 x i64> poison) |
| 130 | +; CHECK-NEXT: [[TMP9:%.*]] = getelementptr i64, ptr [[P1]], i32 [[INDEX]] |
| 131 | +; CHECK-NEXT: [[TMP13:%.*]] = call i64 @llvm.vscale.i64() |
| 132 | +; CHECK-NEXT: [[TMP11:%.*]] = shl nuw i64 [[TMP13]], 1 |
| 133 | +; CHECK-NEXT: [[TMP12:%.*]] = getelementptr i64, ptr [[TMP9]], i64 [[TMP11]] |
| 134 | +; CHECK-NEXT: [[WIDE_MASKED_LOAD4:%.*]] = call <vscale x 2 x i64> @llvm.masked.load.nxv2i64.p0(ptr [[TMP9]], i32 8, <vscale x 2 x i1> [[TMP6]], <vscale x 2 x i64> poison) |
| 135 | +; CHECK-NEXT: [[WIDE_MASKED_LOAD5:%.*]] = call <vscale x 2 x i64> @llvm.masked.load.nxv2i64.p0(ptr [[TMP12]], i32 8, <vscale x 2 x i1> [[TMP6]], <vscale x 2 x i64> poison) |
| 136 | +; CHECK-NEXT: [[TMP21:%.*]] = select <vscale x 2 x i1> [[TMP6]], <vscale x 2 x i64> [[WIDE_MASKED_LOAD4]], <vscale x 2 x i64> splat (i64 1) |
| 137 | +; CHECK-NEXT: [[TMP14:%.*]] = select <vscale x 2 x i1> [[TMP6]], <vscale x 2 x i64> [[WIDE_MASKED_LOAD5]], <vscale x 2 x i64> splat (i64 1) |
| 138 | +; CHECK-NEXT: [[TMP15:%.*]] = udiv <vscale x 2 x i64> [[WIDE_MASKED_LOAD]], [[TMP21]] |
| 139 | +; CHECK-NEXT: [[TMP22:%.*]] = udiv <vscale x 2 x i64> [[WIDE_MASKED_LOAD3]], [[TMP14]] |
| 140 | +; CHECK-NEXT: [[TMP17:%.*]] = call i64 @llvm.vscale.i64() |
| 141 | +; CHECK-NEXT: [[TMP18:%.*]] = shl nuw i64 [[TMP17]], 1 |
| 142 | +; CHECK-NEXT: [[TMP19:%.*]] = getelementptr i64, ptr [[TMP9]], i64 [[TMP18]] |
| 143 | +; CHECK-NEXT: call void @llvm.masked.store.nxv2i64.p0(<vscale x 2 x i64> [[TMP15]], ptr [[TMP9]], i32 8, <vscale x 2 x i1> [[TMP6]]) |
| 144 | +; CHECK-NEXT: call void @llvm.masked.store.nxv2i64.p0(<vscale x 2 x i64> [[TMP22]], ptr [[TMP19]], i32 8, <vscale x 2 x i1> [[TMP6]]) |
| 145 | +; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], [[TMP5]] |
| 146 | +; CHECK-NEXT: [[TMP16:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]] |
| 147 | +; CHECK-NEXT: br i1 [[TMP16]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]] |
| 148 | +; CHECK: [[MIDDLE_BLOCK]]: |
| 149 | +; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 1024, [[N_VEC]] |
| 150 | +; CHECK-NEXT: br i1 [[CMP_N]], label %[[EXIT:.*]], label %[[SCALAR_PH]] |
| 151 | +; CHECK: [[SCALAR_PH]]: |
| 152 | +; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ] |
| 153 | +; CHECK-NEXT: br label %[[LOOP:.*]] |
| 154 | +; CHECK: [[LOOP]]: |
| 155 | +; CHECK-NEXT: [[IV1:%.*]] = phi i32 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT1:%.*]], %[[LATCH:.*]] ] |
| 156 | +; CHECK-NEXT: br i1 [[C0]], label %[[THEN_0:.*]], label %[[LATCH]], !prof [[PROF5:![0-9]+]] |
| 157 | +; CHECK: [[THEN_0]]: |
| 158 | +; CHECK-NEXT: br i1 [[C1]], label %[[THEN_1:.*]], label %[[LATCH]], !prof [[PROF5]] |
| 159 | +; CHECK: [[THEN_1]]: |
| 160 | +; CHECK-NEXT: [[GEP0:%.*]] = getelementptr i64, ptr [[P0]], i32 [[IV1]] |
| 161 | +; CHECK-NEXT: [[X:%.*]] = load i64, ptr [[GEP0]], align 8 |
| 162 | +; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i64, ptr [[P1]], i32 [[IV1]] |
| 163 | +; CHECK-NEXT: [[Y:%.*]] = load i64, ptr [[GEP1]], align 8 |
| 164 | +; CHECK-NEXT: [[Z:%.*]] = udiv i64 [[X]], [[Y]] |
| 165 | +; CHECK-NEXT: store i64 [[Z]], ptr [[GEP1]], align 8 |
| 166 | +; CHECK-NEXT: br label %[[LATCH]] |
| 167 | +; CHECK: [[LATCH]]: |
| 168 | +; CHECK-NEXT: [[IV_NEXT1]] = add i32 [[IV1]], 1 |
| 169 | +; CHECK-NEXT: [[DONE:%.*]] = icmp eq i32 [[IV_NEXT1]], 1024 |
| 170 | +; CHECK-NEXT: br i1 [[DONE]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP6:![0-9]+]] |
| 171 | +; CHECK: [[EXIT]]: |
| 172 | +; CHECK-NEXT: ret void |
| 173 | +; |
| 174 | +entry: |
| 175 | + br label %loop |
| 176 | + |
| 177 | +loop: |
| 178 | + %iv = phi i32 [ 0, %entry ], [ %iv.next, %latch ] |
| 179 | + br i1 %c0, label %then.0, label %latch, !prof !4 |
| 180 | + |
| 181 | +then.0: |
| 182 | + br i1 %c1, label %then.1, label %latch, !prof !4 |
| 183 | + |
| 184 | +then.1: |
| 185 | + %gep0 = getelementptr i64, ptr %p0, i32 %iv |
| 186 | + %x = load i64, ptr %gep0 |
| 187 | + %gep1 = getelementptr i64, ptr %p1, i32 %iv |
| 188 | + %y = load i64, ptr %gep1 |
| 189 | + %z = udiv i64 %x, %y |
| 190 | + store i64 %z, ptr %gep1 |
| 191 | + br label %latch |
| 192 | + |
| 193 | +latch: |
| 194 | + %iv.next = add i32 %iv, 1 |
| 195 | + %done = icmp eq i32 %iv.next, 1024 |
| 196 | + br i1 %done, label %exit, label %loop |
| 197 | + |
| 198 | +exit: |
| 199 | + ret void |
| 200 | +} |
| 201 | + |
| 202 | +!4 = !{!"branch_weights", i32 1, i32 0} |
| 203 | + |
0 commit comments