Skip to content

Commit b12054a

Browse files
MrSidimspreethi-intel
authored andcommitted
Translate llvm.loop.unroll.full metadata (intel#1664)
It can be generated via #pragma clang unroll(full) pragma. llvm.loop.unroll.full means attempt to do full unroll of the loop and disable the unrolling if the trip count is not known at compile time. Unroll mask to which it was previously mapped doesn't much the description. The way the patch represents it in SPIR-V is: Unroll mask + PartialCount mask with '1' parameter This patch also removes some overtesting for unroll metadata. Signed-off-by: Sidorov, Dmitry <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@eed0081
1 parent ff0439c commit b12054a

9 files changed

+59
-366
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ void SPIRVToLLVM::setLLVMLoopMetadata(const LoopInstType *LM,
690690
// i.e. check smaller-numbered bits first.
691691
// Unroll and UnrollCount loop controls can't be applied simultaneously with
692692
// DontUnroll loop control.
693-
if (LC & LoopControlUnrollMask)
693+
if (LC & LoopControlUnrollMask && !(LC & LoopControlPartialCountMask))
694694
Metadata.push_back(getMetadataFromName("llvm.loop.unroll.enable"));
695695
else if (LC & LoopControlDontUnrollMask)
696696
Metadata.push_back(getMetadataFromName("llvm.loop.unroll.disable"));
@@ -728,9 +728,11 @@ void SPIRVToLLVM::setLLVMLoopMetadata(const LoopInstType *LM,
728728
"Missing loop control parameter!");
729729
}
730730
if (LC & LoopControlPartialCountMask && !(LC & LoopControlDontUnrollMask)) {
731-
// If unroll factor is set as '1' - disable loop unrolling
732-
if (1 == LoopControlParameters[NumParam])
733-
Metadata.push_back(getMetadataFromName("llvm.loop.unroll.disable"));
731+
// If unroll factor is set as '1' and Unroll mask is applied attempt to do
732+
// full unrolling and disable it if the trip count is not known at compile
733+
// time.
734+
if (1 == LoopControlParameters[NumParam] && (LC & LoopControlUnrollMask))
735+
Metadata.push_back(getMetadataFromName("llvm.loop.unroll.full"));
734736
else
735737
Metadata.push_back(llvm::MDNode::get(
736738
*Context,

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,18 @@ LLVMToSPIRVBase::getLoopControl(const BranchInst *Branch,
14131413
// appear first.
14141414
if (S == "llvm.loop.unroll.disable")
14151415
LoopControl |= spv::LoopControlDontUnrollMask;
1416-
else if (S == "llvm.loop.unroll.full" || S == "llvm.loop.unroll.enable")
1416+
else if (S == "llvm.loop.unroll.enable")
14171417
LoopControl |= spv::LoopControlUnrollMask;
1418+
// Attempt to do full unroll of the loop and disable unrolling if the trip
1419+
// count is not known at compile time by setting PartialCount to 1
1420+
else if (S == "llvm.loop.unroll.full") {
1421+
LoopControl |= spv::LoopControlUnrollMask;
1422+
if (BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_4)) {
1423+
BM->setMinSPIRVVersion(VersionNumber::SPIRV_1_4);
1424+
ParametersToSort.emplace_back(spv::LoopControlPartialCountMask, 1);
1425+
LoopControl |= spv::LoopControlPartialCountMask;
1426+
}
1427+
}
14181428
// PartialCount must not be used with the DontUnroll bit
14191429
else if (S == "llvm.loop.unroll.count" &&
14201430
!(LoopControl & LoopControlDontUnrollMask)) {

llvm-spirv/test/DebugInfo/DebugControlFlow.cl

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
kernel
1515
void sample() {
1616
int arr[10];
17-
#pragma clang loop unroll(full)
17+
#pragma clang loop unroll(enable)
1818
for (int i = 0; i < 10; i++)
1919
arr[i] = 0;
2020
int j = 0;
21-
#pragma clang loop unroll(full)
21+
#pragma clang loop unroll(enable)
2222
do {
2323
arr[j] = 0;
2424
} while (j++ < 10);

llvm-spirv/test/DebugInfo/DebugUnstructuredControlFlow.cl

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ void sample() {
1818
// Check that all Line items are retained
1919
// CHECK-SPIRV: Line [[File:[0-9]+]] 15 0
2020
// Loop control
21-
// CHECK-SPIRV: 2 LoopControlINTEL 1
21+
// CHECK-SPIRV: LoopControlINTEL 257 1
2222
// CHECK-SPIRV-NEXT: Branch
2323

2424
// CHECK-LLVM: br label %{{.*}}, !dbg !{{[0-9]+}}, !llvm.loop ![[MD:[0-9]+]]
2525
// CHECK-LLVM: ![[MD]] = distinct !{![[MD]], ![[MD_unroll:[0-9]+]]}
26-
// CHECK-LLVM: ![[MD_unroll]] = !{!"llvm.loop.unroll.enable"}
26+
// CHECK-LLVM: ![[MD_unroll]] = !{!"llvm.loop.unroll.full"}

llvm-spirv/test/OpLoopMergeDontUnroll.spt

-92
This file was deleted.

llvm-spirv/test/OpLoopMergeDontUnrollHint1.spt

-88
This file was deleted.

llvm-spirv/test/OpLoopMergePartialUnroll.spt

-88
This file was deleted.

0 commit comments

Comments
 (0)