brintos

brintos / llvm-project-archived public Read only

0
0
Text · 13.3 KiB · 8cb3346 Raw
314 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s2 3// Verify while loop is recognized after sequence of pragma clang loop directives.4void while_test(int *List, int Length) {5  // CHECK: define {{.*}} @_Z10while_test6  int i = 0;7 8#pragma clang loop vectorize(enable)9#pragma clang loop interleave_count(4)10#pragma clang loop vectorize_width(4)11#pragma clang loop unroll(full)12#pragma clang loop distribute(enable)13  while (i < Length) {14    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_1:.*]]15    List[i] = i * 2;16    i++;17  }18}19 20// Verify do loop is recognized after multi-option pragma clang loop directive.21void do_test(int *List, int Length) {22  int i = 0;23 24#pragma clang loop vectorize_width(8) interleave_count(4) unroll(disable) distribute(disable)25  do {26    // CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_2:.*]]27    List[i] = i * 2;28    i++;29  } while (i < Length);30}31 32enum struct Tuner : short { Interleave = 4, Unroll = 8 };33 34// Verify for loop is recognized after sequence of pragma clang loop directives.35void for_test(int *List, int Length) {36#pragma clang loop interleave(enable)37#pragma clang loop interleave_count(static_cast<int>(Tuner::Interleave))38#pragma clang loop unroll_count(static_cast<int>(Tuner::Unroll))39  for (int i = 0; i < Length; i++) {40    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_3:.*]]41    List[i] = i * 2;42  }43}44 45// Verify c++11 for range loop is recognized after46// sequence of pragma clang loop directives.47void for_range_test() {48  double List[100];49 50#pragma clang loop vectorize_width(2) interleave_count(2)51  for (int i : List) {52    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_4:.*]]53    List[i] = i;54  }55}56 57// Verify disable pragma clang loop directive generates correct metadata58void disable_test(int *List, int Length) {59#pragma clang loop vectorize(disable) unroll(disable) distribute(disable)60  for (int i = 0; i < Length; i++) {61    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_5:.*]]62    List[i] = i * 2;63  }64}65 66#define VECWIDTH 267#define INTCOUNT 268#define UNROLLCOUNT 869 70// Verify defines are correctly resolved in pragma clang loop directive71void for_define_test(int *List, int Length, int Value) {72#pragma clang loop vectorize_width(VECWIDTH) interleave_count(INTCOUNT)73#pragma clang loop unroll_count(UNROLLCOUNT)74  for (int i = 0; i < Length; i++) {75    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_6:.*]]76    List[i] = i * Value;77  }78}79 80// Verify constant expressions are handled correctly.81void for_contant_expression_test(int *List, int Length) {82#pragma clang loop vectorize_width(1 + 4)83  for (int i = 0; i < Length; i++) {84    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_7:.*]]85    List[i] = i;86  }87 88#pragma clang loop vectorize_width(3 + VECWIDTH)89  for (int i = 0; i < Length; i++) {90    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_8:.*]]91    List[i] += i;92  }93}94 95// Verify metadata is generated when template is used.96template <typename A>97void for_template_test(A *List, int Length, A Value) {98#pragma clang loop vectorize_width(8) interleave_count(8) unroll_count(8)99  for (int i = 0; i < Length; i++) {100    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_9:.*]]101    List[i] = i * Value;102  }103}104 105// Verify define is resolved correctly when template is used.106template <typename A, typename T>107void for_template_define_test(A *List, int Length, A Value) {108  const T VWidth = VECWIDTH;109  const T ICount = INTCOUNT;110  const T UCount = UNROLLCOUNT;111#pragma clang loop vectorize_width(VWidth) interleave_count(ICount)112#pragma clang loop unroll_count(UCount)113  for (int i = 0; i < Length; i++) {114    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_10:.*]]115    List[i] = i * Value;116  }117}118 119// Verify templates and constant expressions are handled correctly.120template <typename A, int V, int I, int U>121void for_template_constant_expression_test(A *List, int Length) {122#pragma clang loop vectorize_width(V) interleave_count(I) unroll_count(U)123  for (int i = 0; i < Length; i++) {124    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_11:.*]]125    List[i] = i;126  }127 128#pragma clang loop vectorize_width(V * 2 + VECWIDTH) interleave_count(I * 2 + INTCOUNT) unroll_count(U * 2 + UNROLLCOUNT)129  for (int i = 0; i < Length; i++) {130    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_12:.*]]131    List[i] += i;132  }133 134  const int Scale = 4;135#pragma clang loop vectorize_width(Scale * V) interleave_count(Scale * I) unroll_count(Scale * U)136  for (int i = 0; i < Length; i++) {137    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_13:.*]]138    List[i] += i;139  }140 141#pragma clang loop vectorize_width((Scale * V) + 2)142  for (int i = 0; i < Length; i++) {143    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_14:.*]]144    List[i] += i;145  }146}147 148#undef VECWIDTH149#undef INTCOUNT150#undef UNROLLCOUNT151 152// Use templates defined above. Test verifies metadata is generated correctly.153void template_test(double *List, int Length) {154  double Value = 10;155 156  for_template_test<double>(List, Length, Value);157  for_template_define_test<double, int>(List, Length, Value);158  for_template_constant_expression_test<double, 2, 4, 8>(List, Length);159}160 161// Verify for loop is performing fixed width vectorization162void for_test_fixed_16(int *List, int Length) {163#pragma clang loop vectorize_width(16, fixed) interleave_count(4) unroll(disable) distribute(disable)164  for (int i = 0; i < Length; i++) {165    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_15:.*]]166    List[i] = i * 2;167  }168}169 170// Verify for loop is performing scalable vectorization171void for_test_scalable_16(int *List, int Length) {172#pragma clang loop vectorize_width(16, scalable) interleave_count(4) unroll(disable) distribute(disable)173  for (int i = 0; i < Length; i++) {174    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_16:.*]]175    List[i] = i * 2;176  }177}178 179// Verify for loop is performing fixed width vectorization180void for_test_fixed(int *List, int Length) {181#pragma clang loop vectorize_width(fixed) interleave_count(4) unroll(disable) distribute(disable)182  for (int i = 0; i < Length; i++) {183    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_17:.*]]184    List[i] = i * 2;185  }186}187 188// Verify for loop is performing scalable vectorization189void for_test_scalable(int *List, int Length) {190#pragma clang loop vectorize_width(scalable) interleave_count(4) unroll(disable) distribute(disable)191  for (int i = 0; i < Length; i++) {192    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_18:.*]]193    List[i] = i * 2;194  }195}196 197// Verify for loop is performing scalable vectorization198void for_test_scalable_1(int *List, int Length) {199#pragma clang loop vectorize_width(1, scalable) interleave_count(4) unroll(disable) distribute(disable)200  for (int i = 0; i < Length; i++) {201    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_19:.*]]202    List[i] = i * 2;203  }204}205 206// Verify for loop is not performing vectorization207void for_test_width_1(int *List, int Length) {208#pragma clang loop vectorize_width(1) interleave_count(4) unroll(disable) distribute(disable)209  for (int i = 0; i < Length; i++) {210    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_20:.*]]211    List[i] = i * 2;212  }213}214 215// Verify for loop is not performing vectorization216void for_test_fixed_1(int *List, int Length) {217#pragma clang loop vectorize_width(1, fixed) interleave_count(4) unroll(disable) distribute(disable)218  for (int i = 0; i < Length; i++) {219    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_21:.*]]220    List[i] = i * 2;221  }222}223 224 225// Verify unroll attributes are directly attached to the loop metadata226void for_test_vectorize_disable_unroll(int *List, int Length) {227#pragma clang loop vectorize(disable) unroll_count(8)228  for (int i = 0; i < Length; i++) {229    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_22:.*]]230    List[i] = i * 2;231  }232}233 234// Verify unroll attributes are directly attached to the loop metadata235void for_test_interleave_vectorize_disable_unroll(int *List, int Length) {236#pragma clang loop vectorize(disable) interleave_count(4) unroll_count(8)237  for (int i = 0; i < Length; i++) {238    // CHECK: br label {{.*}}, !llvm.loop ![[LOOP_23:.*]]239    List[i] = i * 2;240  }241}242 243// CHECK-DAG: ![[MP:[0-9]+]] = !{!"llvm.loop.mustprogress"}244 245// CHECK-DAG: ![[UNROLL_DISABLE:[0-9]+]] = !{!"llvm.loop.unroll.disable"}246// CHECK-DAG: ![[UNROLL_8:[0-9]+]] = !{!"llvm.loop.unroll.count", i32 8}247// CHECK-DAG: ![[UNROLL_24:[0-9]+]] = !{!"llvm.loop.unroll.count", i32 24}248// CHECK-DAG: ![[UNROLL_32:[0-9]+]] = !{!"llvm.loop.unroll.count", i32 32}249// CHECK-DAG: ![[UNROLL_FULL:[0-9]+]] = !{!"llvm.loop.unroll.full"}250 251// CHECK-DAG: ![[DISTRIBUTE_DISABLE:[0-9]+]] = !{!"llvm.loop.distribute.enable", i1 false}252 253// CHECK-DAG: ![[INTERLEAVE_2:[0-9]+]] = !{!"llvm.loop.interleave.count", i32 2}254// CHECK-DAG: ![[INTERLEAVE_4:[0-9]+]] = !{!"llvm.loop.interleave.count", i32 4}255// CHECK-DAG: ![[INTERLEAVE_8:[0-9]+]] = !{!"llvm.loop.interleave.count", i32 8}256// CHECK-DAG: ![[INTERLEAVE_10:[0-9]+]] = !{!"llvm.loop.interleave.count", i32 10}257// CHECK-DAG: ![[INTERLEAVE_16:[0-9]+]] = !{!"llvm.loop.interleave.count", i32 16}258 259// CHECK-DAG: ![[VECTORIZE_ENABLE:[0-9]+]] = !{!"llvm.loop.vectorize.enable", i1 true}260// CHECK-DAG: ![[FIXED_VEC:[0-9]+]] = !{!"llvm.loop.vectorize.scalable.enable", i1 false}261// CHECK-DAG: ![[SCALABLE_VEC:[0-9]+]] = !{!"llvm.loop.vectorize.scalable.enable", i1 true}262// CHECK-DAG: ![[WIDTH_1:[0-9]+]] = !{!"llvm.loop.vectorize.width", i32 1}263// CHECK-DAG: ![[WIDTH_2:[0-9]+]] = !{!"llvm.loop.vectorize.width", i32 2}264// CHECK-DAG: ![[WIDTH_5:[0-9]+]] = !{!"llvm.loop.vectorize.width", i32 5}265// CHECK-DAG: ![[WIDTH_6:[0-9]+]] = !{!"llvm.loop.vectorize.width", i32 6}266// CHECK-DAG: ![[WIDTH_8:[0-9]+]] = !{!"llvm.loop.vectorize.width", i32 8}267// CHECK-DAG: ![[WIDTH_10:[0-9]+]] = !{!"llvm.loop.vectorize.width", i32 10}268// CHECK-DAG: ![[WIDTH_16:[0-9]+]] = !{!"llvm.loop.vectorize.width", i32 16}269 270// CHECK-DAG: ![[ISVECTORIZED:[0-9]+]] = !{!"llvm.loop.isvectorized"}271 272// CHECK-DAG: ![[LOOP_1]] = distinct !{![[LOOP_1]], ![[MP]], ![[UNROLL_FULL]]}273 274// CHECK-DAG: ![[LOOP_2]] = distinct !{![[LOOP_2]], ![[MP]], ![[UNROLL_DISABLE]], ![[DISTRIBUTE_DISABLE]], ![[WIDTH_8]], ![[FIXED_VEC]], ![[INTERLEAVE_4]], ![[VECTORIZE_ENABLE]]}275 276// CHECK-DAG: ![[LOOP_3]] = distinct !{![[LOOP_3]], ![[MP]], ![[INTERLEAVE_4]], ![[VECTORIZE_ENABLE]], ![[FOLLOWUP_VECTOR_3:[0-9]+]]}277// CHECK-DAG: ![[FOLLOWUP_VECTOR_3]] = !{!"llvm.loop.vectorize.followup_all", ![[MP]], ![[ISVECTORIZED]], ![[UNROLL_8]]}278 279// CHECK-DAG: ![[LOOP_4]] = distinct !{![[LOOP_4]], ![[WIDTH_2]], ![[FIXED_VEC]], ![[INTERLEAVE_2]], ![[VECTORIZE_ENABLE]]}280 281// CHECK-DAG: ![[LOOP_5]] = distinct !{![[LOOP_5]], ![[MP]], ![[UNROLL_DISABLE]], ![[DISTRIBUTE_DISABLE]], ![[WIDTH_1]]}282 283// CHECK-DAG: ![[LOOP_6]] = distinct !{![[LOOP_6]], ![[MP]], ![[WIDTH_2]], ![[FIXED_VEC]], ![[INTERLEAVE_2]], ![[VECTORIZE_ENABLE]], ![[FOLLOWUP_VECTOR_3]]}284 285// CHECK-DAG: ![[LOOP_7]] = distinct !{![[LOOP_7]], ![[MP]], ![[WIDTH_5]], ![[FIXED_VEC]], ![[VECTORIZE_ENABLE]]}286 287// CHECK-DAG: ![[LOOP_8]] = distinct !{![[LOOP_8]], ![[MP]], ![[WIDTH_5]], ![[FIXED_VEC]], ![[VECTORIZE_ENABLE]]}288 289// CHECK-DAG: ![[LOOP_9]] = distinct !{![[LOOP_9]], ![[MP]], ![[WIDTH_8]], ![[FIXED_VEC]], ![[INTERLEAVE_8]], ![[VECTORIZE_ENABLE]], ![[FOLLOWUP_VECTOR_3]]}290 291// CHECK-DAG: ![[LOOP_10]] = distinct !{![[LOOP_10]], ![[MP]], ![[WIDTH_2]], ![[FIXED_VEC]], ![[INTERLEAVE_2]], ![[VECTORIZE_ENABLE]], ![[FOLLOWUP_VECTOR_3]]}292 293// CHECK-DAG: ![[LOOP_11]] = distinct !{![[LOOP_11]], ![[MP]], ![[WIDTH_2]], ![[FIXED_VEC]], ![[INTERLEAVE_4]], ![[VECTORIZE_ENABLE]], ![[FOLLOWUP_VECTOR_3]]}294 295// CHECK-DAG: ![[LOOP_12]] = distinct !{![[LOOP_12]], ![[MP]], ![[WIDTH_6]], ![[FIXED_VEC]], ![[INTERLEAVE_10]], ![[VECTORIZE_ENABLE]], ![[FOLLOWUP_VECTOR_12:[0-9]+]]}296// CHECK-DAG: ![[FOLLOWUP_VECTOR_12]] = !{!"llvm.loop.vectorize.followup_all", ![[MP]], ![[ISVECTORIZED]], ![[UNROLL_24]]}297 298// CHECK-DAG: ![[LOOP_13]] = distinct !{![[LOOP_13]], ![[MP]], ![[WIDTH_8]], ![[FIXED_VEC]], ![[INTERLEAVE_16]], ![[VECTORIZE_ENABLE]], ![[FOLLOWUP_VECTOR_13:[0-9]+]]}299// CHECK-DAG: ![[FOLLOWUP_VECTOR_13]] = !{!"llvm.loop.vectorize.followup_all", ![[MP]], ![[ISVECTORIZED]], ![[UNROLL_32]]}300 301// CHECK-DAG: ![[LOOP_14]] = distinct !{![[LOOP_14]], ![[MP]], ![[WIDTH_10]], ![[FIXED_VEC]], ![[VECTORIZE_ENABLE]]}302 303// CHECK-DAG: ![[LOOP_15]] = distinct !{![[LOOP_15]], ![[MP]], ![[UNROLL_DISABLE]], ![[DISTRIBUTE_DISABLE]], ![[WIDTH_16]], ![[FIXED_VEC]], ![[INTERLEAVE_4]], ![[VECTORIZE_ENABLE]]}304 305// CHECK-DAG: ![[LOOP_16]] = distinct !{![[LOOP_16]], ![[MP]], ![[UNROLL_DISABLE]], ![[DISTRIBUTE_DISABLE]], ![[WIDTH_16]], ![[SCALABLE_VEC]], ![[INTERLEAVE_4]], ![[VECTORIZE_ENABLE]]}306 307// CHECK-DAG: ![[LOOP_17]] = distinct !{![[LOOP_17]], ![[MP]], ![[UNROLL_DISABLE]], ![[DISTRIBUTE_DISABLE]], ![[FIXED_VEC]], ![[INTERLEAVE_4]], ![[VECTORIZE_ENABLE]]}308// CHECK-DAG: ![[LOOP_18]] = distinct !{![[LOOP_18]], ![[MP]], ![[UNROLL_DISABLE]], ![[DISTRIBUTE_DISABLE]], ![[SCALABLE_VEC]], ![[INTERLEAVE_4]], ![[VECTORIZE_ENABLE]]}309// CHECK-DAG: ![[LOOP_19]] = distinct !{![[LOOP_19]], ![[MP]], ![[UNROLL_DISABLE]], ![[DISTRIBUTE_DISABLE]], ![[WIDTH_1]], ![[SCALABLE_VEC]], ![[INTERLEAVE_4]], ![[VECTORIZE_ENABLE]]}310// CHECK-DAG: ![[LOOP_20]] = distinct !{![[LOOP_20]], ![[MP]], ![[UNROLL_DISABLE]], ![[DISTRIBUTE_DISABLE]], ![[WIDTH_1]], ![[FIXED_VEC]], ![[INTERLEAVE_4]]}311// CHECK-DAG: ![[LOOP_21]] = distinct !{![[LOOP_21]], ![[MP]], ![[UNROLL_DISABLE]], ![[DISTRIBUTE_DISABLE]], ![[WIDTH_1]], ![[FIXED_VEC]], ![[INTERLEAVE_4]]}312// CHECK-DAG: ![[LOOP_22]] = distinct !{![[LOOP_22]], ![[MP]], ![[WIDTH_1]], ![[ISVECTORIZED]], ![[UNROLL_8]]}313// CHECK-DAG: ![[LOOP_23]] = distinct !{![[LOOP_23]], ![[MP]], ![[WIDTH_1]], ![[INTERLEAVE_4]], ![[ISVECTORIZED]], ![[UNROLL_8]]}314