|
| 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 -force-vector-width=4 -force-vector-interleave=2 -S %s | FileCheck --check-prefix=VF4IC2 %s |
| 3 | +; RUN: opt -p loop-vectorize -force-vector-width=8 -force-vector-interleave=1 -S %s | FileCheck --check-prefix=VF8IC1 %s |
| 4 | + |
| 5 | +; Test case from https://github.com/llvm/llvm-project/issues/153946. |
| 6 | +; %shr and thus %early.cond will be poison from %iv == 4 onwards. |
| 7 | +; TODO: Make sure the mask being poison does not propagate across lanes in the |
| 8 | +; OR reduction when computing the early exit condition in the vector loop. |
| 9 | +define noundef i32 @f(i32 noundef %g) { |
| 10 | +; VF4IC2-LABEL: define noundef i32 @f( |
| 11 | +; VF4IC2-SAME: i32 noundef [[G:%.*]]) { |
| 12 | +; VF4IC2-NEXT: [[ENTRY:.*:]] |
| 13 | +; VF4IC2-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] |
| 14 | +; VF4IC2: [[VECTOR_PH]]: |
| 15 | +; VF4IC2-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[G]], i64 0 |
| 16 | +; VF4IC2-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer |
| 17 | +; VF4IC2-NEXT: br label %[[VECTOR_BODY:.*]] |
| 18 | +; VF4IC2: [[VECTOR_BODY]]: |
| 19 | +; VF4IC2-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] |
| 20 | +; VF4IC2-NEXT: [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ] |
| 21 | +; VF4IC2-NEXT: [[STEP_ADD:%.*]] = add <4 x i32> [[VEC_IND]], splat (i32 4) |
| 22 | +; VF4IC2-NEXT: [[TMP0:%.*]] = shl nuw nsw <4 x i32> [[VEC_IND]], splat (i32 3) |
| 23 | +; VF4IC2-NEXT: [[TMP1:%.*]] = shl nuw nsw <4 x i32> [[STEP_ADD]], splat (i32 3) |
| 24 | +; VF4IC2-NEXT: [[TMP2:%.*]] = ashr <4 x i32> [[BROADCAST_SPLAT]], [[TMP0]] |
| 25 | +; VF4IC2-NEXT: [[TMP3:%.*]] = ashr <4 x i32> [[BROADCAST_SPLAT]], [[TMP1]] |
| 26 | +; VF4IC2-NEXT: [[TMP4:%.*]] = icmp ne <4 x i32> [[TMP2]], zeroinitializer |
| 27 | +; VF4IC2-NEXT: [[TMP5:%.*]] = icmp ne <4 x i32> [[TMP3]], zeroinitializer |
| 28 | +; VF4IC2-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8 |
| 29 | +; VF4IC2-NEXT: [[TMP6:%.*]] = or <4 x i1> [[TMP4]], [[TMP5]] |
| 30 | +; VF4IC2-NEXT: [[TMP7:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP6]]) |
| 31 | +; VF4IC2-NEXT: [[VEC_IND_NEXT]] = add <4 x i32> [[STEP_ADD]], splat (i32 4) |
| 32 | +; VF4IC2-NEXT: br i1 true, label %[[MIDDLE_SPLIT:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]] |
| 33 | +; VF4IC2: [[MIDDLE_SPLIT]]: |
| 34 | +; VF4IC2-NEXT: [[TMP8:%.*]] = extractelement <4 x i32> [[TMP3]], i32 3 |
| 35 | +; VF4IC2-NEXT: br i1 [[TMP7]], label %[[VECTOR_EARLY_EXIT:.*]], label %[[MIDDLE_BLOCK:.*]] |
| 36 | +; VF4IC2: [[MIDDLE_BLOCK]]: |
| 37 | +; VF4IC2-NEXT: br label %[[RETURN:.*]] |
| 38 | +; VF4IC2: [[VECTOR_EARLY_EXIT]]: |
| 39 | +; VF4IC2-NEXT: [[TMP9:%.*]] = call i64 @llvm.experimental.cttz.elts.i64.v4i1(<4 x i1> [[TMP5]], i1 true) |
| 40 | +; VF4IC2-NEXT: [[TMP10:%.*]] = add i64 4, [[TMP9]] |
| 41 | +; VF4IC2-NEXT: [[TMP11:%.*]] = call i64 @llvm.experimental.cttz.elts.i64.v4i1(<4 x i1> [[TMP4]], i1 true) |
| 42 | +; VF4IC2-NEXT: [[TMP12:%.*]] = add i64 0, [[TMP11]] |
| 43 | +; VF4IC2-NEXT: [[TMP13:%.*]] = icmp ne i64 [[TMP11]], 4 |
| 44 | +; VF4IC2-NEXT: [[TMP14:%.*]] = select i1 [[TMP13]], i64 [[TMP12]], i64 [[TMP10]] |
| 45 | +; VF4IC2-NEXT: [[TMP15:%.*]] = trunc i64 [[TMP14]] to i32 |
| 46 | +; VF4IC2-NEXT: [[TMP16:%.*]] = add i32 [[INDEX]], [[TMP15]] |
| 47 | +; VF4IC2-NEXT: br label %[[RETURN]] |
| 48 | +; VF4IC2: [[SCALAR_PH]]: |
| 49 | +; VF4IC2-NEXT: br label %[[LOOP_HEADER:.*]] |
| 50 | +; VF4IC2: [[LOOP_HEADER]]: |
| 51 | +; VF4IC2-NEXT: [[IV:%.*]] = phi i32 [ 0, %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP_LATCH:.*]] ] |
| 52 | +; VF4IC2-NEXT: [[MUL:%.*]] = shl nuw nsw i32 [[IV]], 3 |
| 53 | +; VF4IC2-NEXT: [[SHR:%.*]] = ashr i32 [[G]], [[MUL]] |
| 54 | +; VF4IC2-NEXT: [[EARLY_COND:%.*]] = icmp eq i32 [[SHR]], 0 |
| 55 | +; VF4IC2-NEXT: br i1 [[EARLY_COND]], label %[[LOOP_LATCH]], label %[[RETURN]] |
| 56 | +; VF4IC2: [[LOOP_LATCH]]: |
| 57 | +; VF4IC2-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1 |
| 58 | +; VF4IC2-NEXT: [[EC:%.*]] = icmp eq i32 [[IV_NEXT]], 8 |
| 59 | +; VF4IC2-NEXT: br i1 [[EC]], label %[[RETURN]], label %[[LOOP_HEADER]], !llvm.loop [[LOOP3:![0-9]+]] |
| 60 | +; VF4IC2: [[RETURN]]: |
| 61 | +; VF4IC2-NEXT: [[RES:%.*]] = phi i32 [ [[SHR]], %[[LOOP_LATCH]] ], [ [[IV]], %[[LOOP_HEADER]] ], [ [[TMP8]], %[[MIDDLE_BLOCK]] ], [ [[TMP16]], %[[VECTOR_EARLY_EXIT]] ] |
| 62 | +; VF4IC2-NEXT: ret i32 [[RES]] |
| 63 | +; |
| 64 | +; VF8IC1-LABEL: define noundef i32 @f( |
| 65 | +; VF8IC1-SAME: i32 noundef [[G:%.*]]) { |
| 66 | +; VF8IC1-NEXT: [[ENTRY:.*:]] |
| 67 | +; VF8IC1-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] |
| 68 | +; VF8IC1: [[VECTOR_PH]]: |
| 69 | +; VF8IC1-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <8 x i32> poison, i32 [[G]], i64 0 |
| 70 | +; VF8IC1-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <8 x i32> [[BROADCAST_SPLATINSERT]], <8 x i32> poison, <8 x i32> zeroinitializer |
| 71 | +; VF8IC1-NEXT: br label %[[VECTOR_BODY:.*]] |
| 72 | +; VF8IC1: [[VECTOR_BODY]]: |
| 73 | +; VF8IC1-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] |
| 74 | +; VF8IC1-NEXT: [[VEC_IND:%.*]] = phi <8 x i32> [ <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>, %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ] |
| 75 | +; VF8IC1-NEXT: [[TMP0:%.*]] = shl nuw nsw <8 x i32> [[VEC_IND]], splat (i32 3) |
| 76 | +; VF8IC1-NEXT: [[TMP1:%.*]] = ashr <8 x i32> [[BROADCAST_SPLAT]], [[TMP0]] |
| 77 | +; VF8IC1-NEXT: [[TMP2:%.*]] = icmp ne <8 x i32> [[TMP1]], zeroinitializer |
| 78 | +; VF8IC1-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8 |
| 79 | +; VF8IC1-NEXT: [[TMP3:%.*]] = call i1 @llvm.vector.reduce.or.v8i1(<8 x i1> [[TMP2]]) |
| 80 | +; VF8IC1-NEXT: [[VEC_IND_NEXT]] = add <8 x i32> [[VEC_IND]], splat (i32 8) |
| 81 | +; VF8IC1-NEXT: br i1 true, label %[[MIDDLE_SPLIT:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]] |
| 82 | +; VF8IC1: [[MIDDLE_SPLIT]]: |
| 83 | +; VF8IC1-NEXT: [[TMP4:%.*]] = extractelement <8 x i32> [[TMP1]], i32 7 |
| 84 | +; VF8IC1-NEXT: br i1 [[TMP3]], label %[[VECTOR_EARLY_EXIT:.*]], label %[[MIDDLE_BLOCK:.*]] |
| 85 | +; VF8IC1: [[MIDDLE_BLOCK]]: |
| 86 | +; VF8IC1-NEXT: br label %[[RETURN:.*]] |
| 87 | +; VF8IC1: [[VECTOR_EARLY_EXIT]]: |
| 88 | +; VF8IC1-NEXT: [[TMP5:%.*]] = call i64 @llvm.experimental.cttz.elts.i64.v8i1(<8 x i1> [[TMP2]], i1 true) |
| 89 | +; VF8IC1-NEXT: [[TMP6:%.*]] = trunc i64 [[TMP5]] to i32 |
| 90 | +; VF8IC1-NEXT: [[TMP7:%.*]] = add i32 [[INDEX]], [[TMP6]] |
| 91 | +; VF8IC1-NEXT: br label %[[RETURN]] |
| 92 | +; VF8IC1: [[SCALAR_PH]]: |
| 93 | +; VF8IC1-NEXT: br label %[[LOOP_HEADER:.*]] |
| 94 | +; VF8IC1: [[LOOP_HEADER]]: |
| 95 | +; VF8IC1-NEXT: [[IV:%.*]] = phi i32 [ 0, %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP_LATCH:.*]] ] |
| 96 | +; VF8IC1-NEXT: [[MUL:%.*]] = shl nuw nsw i32 [[IV]], 3 |
| 97 | +; VF8IC1-NEXT: [[SHR:%.*]] = ashr i32 [[G]], [[MUL]] |
| 98 | +; VF8IC1-NEXT: [[EARLY_COND:%.*]] = icmp eq i32 [[SHR]], 0 |
| 99 | +; VF8IC1-NEXT: br i1 [[EARLY_COND]], label %[[LOOP_LATCH]], label %[[RETURN]] |
| 100 | +; VF8IC1: [[LOOP_LATCH]]: |
| 101 | +; VF8IC1-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1 |
| 102 | +; VF8IC1-NEXT: [[EC:%.*]] = icmp eq i32 [[IV_NEXT]], 8 |
| 103 | +; VF8IC1-NEXT: br i1 [[EC]], label %[[RETURN]], label %[[LOOP_HEADER]], !llvm.loop [[LOOP3:![0-9]+]] |
| 104 | +; VF8IC1: [[RETURN]]: |
| 105 | +; VF8IC1-NEXT: [[RES:%.*]] = phi i32 [ [[SHR]], %[[LOOP_LATCH]] ], [ [[IV]], %[[LOOP_HEADER]] ], [ [[TMP4]], %[[MIDDLE_BLOCK]] ], [ [[TMP7]], %[[VECTOR_EARLY_EXIT]] ] |
| 106 | +; VF8IC1-NEXT: ret i32 [[RES]] |
| 107 | +; |
| 108 | +entry: |
| 109 | + br label %loop.header |
| 110 | + |
| 111 | +loop.header: |
| 112 | + %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ] |
| 113 | + %mul = shl nuw nsw i32 %iv, 3 |
| 114 | + %shr = ashr i32 %g, %mul |
| 115 | + %early.cond = icmp eq i32 %shr, 0 |
| 116 | + br i1 %early.cond, label %loop.latch, label %return |
| 117 | + |
| 118 | +loop.latch: |
| 119 | + %iv.next = add nuw nsw i32 %iv, 1 |
| 120 | + %ec = icmp eq i32 %iv.next, 8 |
| 121 | + br i1 %ec, label %return, label %loop.header |
| 122 | + |
| 123 | +return: |
| 124 | + %res = phi i32 [ %shr, %loop.latch ], [ %iv, %loop.header ] |
| 125 | + ret i32 %res |
| 126 | +} |
| 127 | + |
| 128 | + |
0 commit comments