brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.1 KiB · 33250b3 Raw
200 lines · plain
1; Check that if option prefer-no-gather/scatter can disable gather/scatter instructions.2; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2,+fast-gather %s -o - | FileCheck %s --check-prefixes=GATHER3; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2,+fast-gather,+prefer-no-gather %s -o - | FileCheck %s --check-prefixes=NO-GATHER4; RUN: llc -mtriple=x86_64-unknown-linux-gnu  -mattr=+avx512vl,+avx512dq < %s | FileCheck %s --check-prefix=SCATTER5; RUN: llc -mtriple=x86_64-unknown-linux-gnu  -mattr=+avx512vl,+avx512dq,+prefer-no-gather < %s | FileCheck %s --check-prefix=SCATTER-NO-GATHER6; RUN: llc -mtriple=x86_64-unknown-linux-gnu  -mattr=+avx512vl,+avx512dq,+prefer-no-scatter < %s | FileCheck %s --check-prefix=GATHER-NO-SCATTER7; RUN: llc -mtriple=x86_64-unknown-linux-gnu  -mattr=+avx512vl,+avx512dq,+prefer-no-gather,+prefer-no-scatter < %s | FileCheck %s --check-prefix=NO-SCATTER-GATHER8 9@A = global [1024 x i8] zeroinitializer, align 12810@B = global [1024 x i64] zeroinitializer, align 12811@C = global [1024 x i64] zeroinitializer, align 12812 13; This tests the function that if prefer-no-gather can disable lowerMGather14define void @test() #0 {15; GATHER-LABEL: test:16; GATHER: vpgatherdq17;18; NO-GATHER-LABEL: test:19; NO-GATHER-NOT: vpgatherdq20;21; GATHER-NO-SCATTER-LABEL: test:22; GATHER-NO-SCATTER: vpgatherdq23;24; NO-SCATTER-GATHER-LABEL: test:25; NO-SCATTER-GATHER-NOT: vpgatherdq26iter.check:27  br i1 false, label %vec.epilog.scalar.ph, label %vector.main.loop.iter.check28 29vector.main.loop.iter.check:                      ; preds = %iter.check30  br i1 false, label %vec.epilog.ph, label %vector.ph31 32vector.ph:                                        ; preds = %vector.main.loop.iter.check33  br label %vector.body34 35vector.body:                                      ; preds = %vector.body, %vector.ph36  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]37  %0 = add i64 %index, 038  %1 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %039  %2 = getelementptr inbounds i8, ptr %1, i32 040  %wide.load = load <32 x i8>, ptr %2, align 141  %3 = sext <32 x i8> %wide.load to <32 x i64>42  %4 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, <32 x i64> %343  %wide.masked.gather = call <32 x i64> @llvm.masked.gather.v32i64.v32p0(<32 x ptr> %4, i32 8, <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <32 x i64> poison)44  %5 = getelementptr inbounds [1024 x i64], ptr @C, i64 0, i64 %045  %6 = getelementptr inbounds i64, ptr %5, i32 046  store <32 x i64> %wide.masked.gather, ptr %6, align 847  %index.next = add nuw i64 %index, 3248  %7 = icmp eq i64 %index.next, 102449  br i1 %7, label %middle.block, label %vector.body, !llvm.loop !050 51middle.block:                                     ; preds = %vector.body52  %cmp.n = icmp eq i64 1024, 102453  br i1 %cmp.n, label %for.cond.cleanup, label %vec.epilog.iter.check54 55vec.epilog.iter.check:                            ; preds = %middle.block56  br i1 true, label %vec.epilog.scalar.ph, label %vec.epilog.ph57 58vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check59  %vec.epilog.resume.val = phi i64 [ 1024, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]60  br label %vec.epilog.vector.body61 62vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph63  %index2 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next5, %vec.epilog.vector.body ]64  %8 = add i64 %index2, 065  %9 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %866  %10 = getelementptr inbounds i8, ptr %9, i32 067  %wide.load3 = load <16 x i8>, ptr %10, align 168  %11 = sext <16 x i8> %wide.load3 to <16 x i64>69  %12 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, <16 x i64> %1170  %wide.masked.gather4 = call <16 x i64> @llvm.masked.gather.v16i64.v16p0(<16 x ptr> %12, i32 8, <16 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <16 x i64> poison)71  %13 = getelementptr inbounds [1024 x i64], ptr @C, i64 0, i64 %872  %14 = getelementptr inbounds i64, ptr %13, i32 073  store <16 x i64> %wide.masked.gather4, ptr %14, align 874  %index.next5 = add nuw i64 %index2, 1675  %15 = icmp eq i64 %index.next5, 102476  br i1 %15, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !277 78vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body79  %cmp.n1 = icmp eq i64 1024, 102480  br i1 %cmp.n1, label %for.cond.cleanup, label %vec.epilog.scalar.ph81 82vec.epilog.scalar.ph:                             ; preds = %iter.check, %vec.epilog.iter.check, %vec.epilog.middle.block83  %bc.resume.val = phi i64 [ 1024, %vec.epilog.middle.block ], [ 1024, %vec.epilog.iter.check ], [ 0, %iter.check ]84  br label %for.body85 86for.body:                                         ; preds = %for.body, %vec.epilog.scalar.ph87  %iv = phi i64 [ %bc.resume.val, %vec.epilog.scalar.ph ], [ %iv.next, %for.body ]88  %inA = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv89  %valA = load i8, ptr %inA, align 190  %valA.ext = sext i8 %valA to i6491  %inB = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %valA.ext92  %valB = load i64, ptr %inB, align 893  %out = getelementptr inbounds [1024 x i64], ptr @C, i64 0, i64 %iv94  store i64 %valB, ptr %out, align 895  %iv.next = add nuw nsw i64 %iv, 196  %cmp = icmp ult i64 %iv.next, 102497  br i1 %cmp, label %for.body, label %for.cond.cleanup, !llvm.loop !498 99for.cond.cleanup:                                 ; preds = %vec.epilog.middle.block, %middle.block, %for.body100  ret void101}102 103declare <32 x i64> @llvm.masked.gather.v32i64.v32p0(<32 x ptr>, i32 immarg, <32 x i1>, <32 x i64>) #1104 105declare <16 x i64> @llvm.masked.gather.v16i64.v16p0(<16 x ptr>, i32 immarg, <16 x i1>, <16 x i64>) #1106!0 = distinct !{!0, !1}107!1 = !{!"llvm.loop.isvectorized", i32 1}108!2 = distinct !{!2, !1, !3}109!3 = !{!"llvm.loop.unroll.runtime.disable"}110!4 = distinct !{!4, !3, !1}111 112; This tests the function that if prefer-no-gather can disable ScalarizeMaskedGather113define <4 x float> @gather_v4f32_ptr_v4i32(<4 x ptr> %ptr, <4 x i32> %trigger, <4 x float> %passthru) {114; GATHER-LABEL: gather_v4f32_ptr_v4i32:115; GATHER: vgatherqps116;117; NO-GATHER-LABEL: gather_v4f32_ptr_v4i32:118; NO-GATHER-NOT: vgatherqps119;120; GATHER-NO-SCATTER-LABEL: gather_v4f32_ptr_v4i32:121; GATHER-NO-SCATTER: vgatherqps122;123; NO-SCATTER-GATHER-LABEL: gather_v4f32_ptr_v4i32:124; NO-SCATTER-GATHER-NOT: vgatherqps125  %mask = icmp eq <4 x i32> %trigger, zeroinitializer126  %res = call <4 x float> @llvm.masked.gather.v4f32.v4p0(<4 x ptr> %ptr, i32 4, <4 x i1> %mask, <4 x float> %passthru)127  ret <4 x float> %res128}129 130declare <4 x float> @llvm.masked.gather.v4f32.v4p0(<4 x ptr>, i32, <4 x i1>, <4 x float>)131 132%struct.a = type { [4 x i32], [4 x i8], %struct.b, i32 }133%struct.b = type { i32, i32 }134@c = external dso_local global %struct.a, align 4135 136; This tests the function that if prefer-no-gather can disable ScalarizeMaskedGather137define <8 x i32> @gather_v8i32_v8i32(<8 x i32> %trigger) {138; GATHER-LABEL: gather_v8i32_v8i32:139; GATHER: vpgatherdd140;141; NO-GATHER-LABEL: gather_v8i32_v8i32:142; NO-GATHER-NOT: vpgatherdd143;144; NO-SCATTER-GATHER-LABEL: gather_v8i32_v8i32:145; NO-SCATTER-GATHER-NOT: vpgatherdd146  %1 = icmp eq <8 x i32> %trigger, zeroinitializer147  %2 = call <8 x i32> @llvm.masked.gather.v8i32.v8p0(<8 x ptr> getelementptr (%struct.a, <8 x ptr> <ptr @c, ptr @c, ptr @c, ptr @c, ptr @c, ptr @c, ptr @c, ptr @c>, <8 x i64> zeroinitializer, i32 0, <8 x i64> <i64 3, i64 3, i64 3, i64 3, i64 3, i64 3, i64 3, i64 3>), i32 4, <8 x i1> %1, <8 x i32> undef)148  %3 = call <8 x i32> @llvm.masked.gather.v8i32.v8p0(<8 x ptr> getelementptr (%struct.a, <8 x ptr> <ptr @c, ptr @c, ptr @c, ptr @c, ptr @c, ptr @c, ptr @c, ptr @c>, <8 x i64> zeroinitializer, i32 3), i32 4, <8 x i1> %1, <8 x i32> undef)149  %4 = add <8 x i32> %2, %3150  %5 = call <8 x i32> @llvm.masked.gather.v8i32.v8p0(<8 x ptr> getelementptr (%struct.a, <8 x ptr> <ptr @c, ptr @c, ptr @c, ptr @c, ptr @c, ptr @c, ptr @c, ptr @c>, <8 x i64> zeroinitializer, i32 3), i32 4, <8 x i1> %1, <8 x i32> undef)151  %6 = add <8 x i32> %4, %5152  ret <8 x i32> %6153}154 155declare <8 x i32> @llvm.masked.gather.v8i32.v8p0(<8 x ptr>, i32, <8 x i1>, <8 x i32>)156 157; scatter test cases 158define void @scatter_test1(ptr %base, <16 x i32> %ind, i16 %mask, <16 x i32>%val) {159; SCATTER-LABEL: scatter_test1:160; SCATTER: vpscatterdd161;162; SCATTER-NO-GATHER-LABEL: scatter_test1:163; SCATTER-NO-GATHER: vpscatterdd164;165; GATHER-NO-SCATTER-LABEL: scatter_test1:166; GATHER-NO-SCATTER-NOT: vpscatterdd167;168; NO-SCATTER-GATHER-LABEL: scatter_test1:169; NO-SCATTER-GATHER-NOT: vpscatterdd170  %broadcast.splatinsert = insertelement <16 x ptr> undef, ptr %base, i32 0171  %broadcast.splat = shufflevector <16 x ptr> %broadcast.splatinsert, <16 x ptr> undef, <16 x i32> zeroinitializer172 173  %gep.random = getelementptr i32, <16 x ptr> %broadcast.splat, <16 x i32> %ind174  %imask = bitcast i16 %mask to <16 x i1>175  call void @llvm.masked.scatter.v16i32.v16p0(<16 x i32>%val, <16 x ptr> %gep.random, i32 4, <16 x i1> %imask)176  call void @llvm.masked.scatter.v16i32.v16p0(<16 x i32>%val, <16 x ptr> %gep.random, i32 4, <16 x i1> %imask)177  ret void178}179 180declare void @llvm.masked.scatter.v8i32.v8p0(<8 x i32> , <8 x ptr> , i32 , <8 x i1> )181declare void @llvm.masked.scatter.v16i32.v16p0(<16 x i32> , <16 x ptr> , i32 , <16 x i1> )182 183define <8 x i32> @scatter_test2(<8 x i32>%a1, <8 x ptr> %ptr) {184; SCATTER-LABEL: scatter_test2:185; SCATTER: vpscatterqd186;187; SCATTER-NO-GATHER-LABEL: scatter_test2:188; SCATTER-NO-GATHER: vpscatterqd189;190; GATHER-NO-SCATTER-LABEL: scatter_test2:191; GATHER-NO-SCATTER-NOT: vpscatterqd192;193; NO-SCATTER-GATHER-LABEL: scatter_test2:194; NO-SCATTER-GATHER-NOT: vpscatterqd195  %a = call <8 x i32> @llvm.masked.gather.v8i32.v8p0(<8 x ptr> %ptr, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)196 197  call void @llvm.masked.scatter.v8i32.v8p0(<8 x i32> %a1, <8 x ptr> %ptr, i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>)198  ret <8 x i32>%a199}200