teak-llvm/clang/test/CodeGenCXX/pragma-unroll-and-jam.cpp
Michael Kruse 58e7642669 [CodeGen] Generate follow-up metadata for loops with more than one transformation.
Before this patch, CGLoop would dump all transformations for a loop into
a single LoopID without encoding any order in which to apply them.
rL348944 added the possibility to encode a transformation order using
followup-attributes.

When a loop has more than one transformation, use the follow-up
attribute define the order in which they are applied. The emitted order
is the defacto order as defined by the current LLVM pass pipeline,
which is:

  LoopFullUnrollPass
  LoopDistributePass
  LoopVectorizePass
  LoopUnrollAndJamPass
  LoopUnrollPass
  MachinePipeliner

This patch should therefore not change the assembly output, assuming
that all explicit transformations can be applied, and no implicit
transformations in-between. In the former case,
WarnMissedTransformationsPass should emit a warning (except for
MachinePipeliner which is not implemented yet). The latter could be
avoided by adding 'llvm.loop.disable_nonforced' attributes.

Because LoopUnrollAndJamPass processes a loop nest, generation of the
MDNode is delayed to after the inner loop metadata have been processed.
A temporary LoopID is therefore used to annotate instructions and
RAUW'ed by the actual LoopID later.

Differential Revision: https://reviews.llvm.org/D57978

llvm-svn: 357415
2019-04-01 17:47:41 +00:00

56 lines
1.9 KiB
C++

// RUN: %clang_cc1 -triple arm-none-eabi -std=c++11 -emit-llvm -o - %s | FileCheck %s
void unroll_and_jam(int *List, int Length, int Value) {
// CHECK-LABEL: define {{.*}} @_Z14unroll_and_jam
#pragma unroll_and_jam
for (int i = 0; i < Length; i++) {
for (int j = 0; j < Length; j++) {
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_1:.*]]
List[i * Length + j] = Value;
}
}
}
void unroll_and_jam_count(int *List, int Length, int Value) {
// CHECK-LABEL: define {{.*}} @_Z20unroll_and_jam_count
#pragma unroll_and_jam(4)
for (int i = 0; i < Length; i++) {
for (int j = 0; j < Length; j++) {
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_2:.*]]
List[i * Length + j] = Value;
}
}
}
void nounroll_and_jam(int *List, int Length, int Value) {
// CHECK-LABEL: define {{.*}} @_Z16nounroll_and_jam
#pragma nounroll_and_jam
for (int i = 0; i < Length; i++) {
for (int j = 0; j < Length; j++) {
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_3:.*]]
List[i * Length + j] = Value;
}
}
}
void clang_unroll_plus_nounroll_and_jam(int *List, int Length, int Value) {
// CHECK-LABEL: define {{.*}} @_Z34clang_unroll_plus_nounroll_and_jam
#pragma nounroll_and_jam
#pragma unroll(4)
for (int i = 0; i < Length; i++) {
for (int j = 0; j < Length; j++) {
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_7:.*]]
List[i * Length + j] = Value;
}
}
}
// CHECK: ![[LOOP_1]] = distinct !{![[LOOP_1]], ![[UNJ_ENABLE:.*]]}
// CHECK: ![[UNJ_ENABLE]] = !{!"llvm.loop.unroll_and_jam.enable"}
// CHECK: ![[LOOP_2]] = distinct !{![[LOOP_2]], ![[UNJ_4:.*]]}
// CHECK: ![[UNJ_4]] = !{!"llvm.loop.unroll_and_jam.count", i32 4}
// CHECK: ![[LOOP_3]] = distinct !{![[LOOP_3]], ![[UNJ_DISABLE:.*]]}
// CHECK: ![[UNJ_DISABLE]] = !{!"llvm.loop.unroll_and_jam.disable"}
// CHECK: ![[LOOP_7]] = distinct !{![[LOOP_7]], ![[UNJ_DISABLE:.*]], ![[UNROLL_4:.*]]}
// CHECK: ![[UNROLL_4]] = !{!"llvm.loop.unroll.count", i32 4}