|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2 |
| 2 | +; RUN: opt < %s -passes=loop-vectorize,instcombine -force-vector-width=2 -force-vector-interleave=1 -S | FileCheck %s |
| 3 | + |
| 4 | +; A call whose argument can remain a scalar for a vectorized function variant |
| 5 | +; with a uniform argument because it's loop invariant |
| 6 | +define void @test_uniform(ptr noalias %dst, ptr readonly %src, i64 %uniform , i64 %n) { |
| 7 | +; CHECK-LABEL: define void @test_uniform |
| 8 | +; CHECK-SAME: (ptr noalias [[DST:%.*]], ptr readonly [[SRC:%.*]], i64 [[UNIFORM:%.*]], i64 [[N:%.*]]) { |
| 9 | +; CHECK-NEXT: entry: |
| 10 | +; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 2 |
| 11 | +; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]] |
| 12 | +; CHECK: vector.ph: |
| 13 | +; CHECK-NEXT: [[N_VEC:%.*]] = and i64 [[N]], -2 |
| 14 | +; CHECK-NEXT: br label [[VECTOR_BODY:%.*]] |
| 15 | +; CHECK: vector.body: |
| 16 | +; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] |
| 17 | +; CHECK-NEXT: [[TMP0:%.*]] = getelementptr double, ptr [[SRC]], i64 [[INDEX]] |
| 18 | +; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x double>, ptr [[TMP0]], align 8 |
| 19 | +; CHECK-NEXT: [[TMP1:%.*]] = extractelement <2 x double> [[WIDE_LOAD]], i64 0 |
| 20 | +; CHECK-NEXT: [[TMP2:%.*]] = call double @foo(double [[TMP1]], i64 [[UNIFORM]]) #[[ATTR0:[0-9]+]] |
| 21 | +; CHECK-NEXT: [[TMP3:%.*]] = extractelement <2 x double> [[WIDE_LOAD]], i64 1 |
| 22 | +; CHECK-NEXT: [[TMP4:%.*]] = call double @foo(double [[TMP3]], i64 [[UNIFORM]]) #[[ATTR0]] |
| 23 | +; CHECK-NEXT: [[TMP5:%.*]] = insertelement <2 x double> poison, double [[TMP2]], i64 0 |
| 24 | +; CHECK-NEXT: [[TMP6:%.*]] = insertelement <2 x double> [[TMP5]], double [[TMP4]], i64 1 |
| 25 | +; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds double, ptr [[DST]], i64 [[INDEX]] |
| 26 | +; CHECK-NEXT: store <2 x double> [[TMP6]], ptr [[TMP7]], align 8 |
| 27 | +; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2 |
| 28 | +; CHECK-NEXT: [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] |
| 29 | +; CHECK-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]] |
| 30 | +; CHECK: middle.block: |
| 31 | +; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[N]] |
| 32 | +; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP:%.*]], label [[SCALAR_PH]] |
| 33 | +; CHECK: scalar.ph: |
| 34 | +; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ] |
| 35 | +; CHECK-NEXT: br label [[FOR_BODY:%.*]] |
| 36 | +; CHECK: for.body: |
| 37 | +; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ] |
| 38 | +; CHECK-NEXT: [[GEPSRC:%.*]] = getelementptr double, ptr [[SRC]], i64 [[INDVARS_IV]] |
| 39 | +; CHECK-NEXT: [[DATA:%.*]] = load double, ptr [[GEPSRC]], align 8 |
| 40 | +; CHECK-NEXT: [[CALL:%.*]] = call double @foo(double [[DATA]], i64 [[UNIFORM]]) #[[ATTR0]] |
| 41 | +; CHECK-NEXT: [[GEPDST:%.*]] = getelementptr inbounds double, ptr [[DST]], i64 [[INDVARS_IV]] |
| 42 | +; CHECK-NEXT: store double [[CALL]], ptr [[GEPDST]], align 8 |
| 43 | +; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1 |
| 44 | +; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[N]] |
| 45 | +; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]] |
| 46 | +; CHECK: for.cond.cleanup: |
| 47 | +; CHECK-NEXT: ret void |
| 48 | +; |
| 49 | +entry: |
| 50 | + br label %for.body |
| 51 | + |
| 52 | +for.body: |
| 53 | + %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] |
| 54 | + %gepsrc = getelementptr double, ptr %src, i64 %indvars.iv |
| 55 | + %data = load double, ptr %gepsrc, align 8 |
| 56 | + %call = call double @foo(double %data, i64 %uniform) #0 |
| 57 | + %gepdst = getelementptr inbounds double, ptr %dst, i64 %indvars.iv |
| 58 | + store double %call, ptr %gepdst |
| 59 | + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 60 | + %exitcond = icmp eq i64 %indvars.iv.next, %n |
| 61 | + br i1 %exitcond, label %for.cond.cleanup, label %for.body |
| 62 | + |
| 63 | +for.cond.cleanup: |
| 64 | + ret void |
| 65 | +} |
| 66 | + |
| 67 | +; If the parameter is not uniform, then we can't use the vector variant and |
| 68 | +; must fall back to scalarization. |
| 69 | +define void @test_uniform_not_invariant(ptr noalias %dst, ptr readonly %src, i64 %n) { |
| 70 | +; CHECK-LABEL: define void @test_uniform_not_invariant |
| 71 | +; CHECK-SAME: (ptr noalias [[DST:%.*]], ptr readonly [[SRC:%.*]], i64 [[N:%.*]]) { |
| 72 | +; CHECK-NEXT: entry: |
| 73 | +; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 2 |
| 74 | +; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]] |
| 75 | +; CHECK: vector.ph: |
| 76 | +; CHECK-NEXT: [[N_VEC:%.*]] = and i64 [[N]], -2 |
| 77 | +; CHECK-NEXT: br label [[VECTOR_BODY:%.*]] |
| 78 | +; CHECK: vector.body: |
| 79 | +; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] |
| 80 | +; CHECK-NEXT: [[TMP0:%.*]] = or i64 [[INDEX]], 1 |
| 81 | +; CHECK-NEXT: [[TMP1:%.*]] = getelementptr double, ptr [[SRC]], i64 [[INDEX]] |
| 82 | +; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x double>, ptr [[TMP1]], align 8 |
| 83 | +; CHECK-NEXT: [[TMP2:%.*]] = extractelement <2 x double> [[WIDE_LOAD]], i64 0 |
| 84 | +; CHECK-NEXT: [[TMP3:%.*]] = call double @foo(double [[TMP2]], i64 [[INDEX]]) #[[ATTR0]] |
| 85 | +; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x double> [[WIDE_LOAD]], i64 1 |
| 86 | +; CHECK-NEXT: [[TMP5:%.*]] = call double @foo(double [[TMP4]], i64 [[TMP0]]) #[[ATTR0]] |
| 87 | +; CHECK-NEXT: [[TMP6:%.*]] = insertelement <2 x double> poison, double [[TMP3]], i64 0 |
| 88 | +; CHECK-NEXT: [[TMP7:%.*]] = insertelement <2 x double> [[TMP6]], double [[TMP5]], i64 1 |
| 89 | +; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds double, ptr [[DST]], i64 [[INDEX]] |
| 90 | +; CHECK-NEXT: store <2 x double> [[TMP7]], ptr [[TMP8]], align 8 |
| 91 | +; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2 |
| 92 | +; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] |
| 93 | +; CHECK-NEXT: br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]] |
| 94 | +; CHECK: middle.block: |
| 95 | +; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[N]] |
| 96 | +; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP:%.*]], label [[SCALAR_PH]] |
| 97 | +; CHECK: scalar.ph: |
| 98 | +; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ] |
| 99 | +; CHECK-NEXT: br label [[FOR_BODY:%.*]] |
| 100 | +; CHECK: for.body: |
| 101 | +; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ] |
| 102 | +; CHECK-NEXT: [[GEPSRC:%.*]] = getelementptr double, ptr [[SRC]], i64 [[INDVARS_IV]] |
| 103 | +; CHECK-NEXT: [[DATA:%.*]] = load double, ptr [[GEPSRC]], align 8 |
| 104 | +; CHECK-NEXT: [[CALL:%.*]] = call double @foo(double [[DATA]], i64 [[INDVARS_IV]]) #[[ATTR0]] |
| 105 | +; CHECK-NEXT: [[GEPDST:%.*]] = getelementptr inbounds double, ptr [[DST]], i64 [[INDVARS_IV]] |
| 106 | +; CHECK-NEXT: store double [[CALL]], ptr [[GEPDST]], align 8 |
| 107 | +; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1 |
| 108 | +; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[N]] |
| 109 | +; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP]], label [[FOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]] |
| 110 | +; CHECK: for.cond.cleanup: |
| 111 | +; CHECK-NEXT: ret void |
| 112 | +; |
| 113 | +entry: |
| 114 | + br label %for.body |
| 115 | + |
| 116 | +for.body: |
| 117 | + %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] |
| 118 | + %gepsrc = getelementptr double, ptr %src, i64 %indvars.iv |
| 119 | + %data = load double, ptr %gepsrc, align 8 |
| 120 | + %call = call double @foo(double %data, i64 %indvars.iv) #0 |
| 121 | + %gepdst = getelementptr inbounds double, ptr %dst, i64 %indvars.iv |
| 122 | + store double %call, ptr %gepdst |
| 123 | + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 124 | + %exitcond = icmp eq i64 %indvars.iv.next, %n |
| 125 | + br i1 %exitcond, label %for.cond.cleanup, label %for.body |
| 126 | + |
| 127 | +for.cond.cleanup: |
| 128 | + ret void |
| 129 | +} |
| 130 | + |
| 131 | +; Scalar functions |
| 132 | +declare double @foo(double, i64) |
| 133 | + |
| 134 | +; Vector variants |
| 135 | +declare <2 x double> @foo_uniform(<2 x double>, i64) |
| 136 | + |
| 137 | +; Mappings |
| 138 | +attributes #0 = { nounwind "vector-function-abi-variant"="_ZGV_LLVM_N2vu_foo(foo_uniform)" } |
0 commit comments