Skip to content

Commit a90938d

Browse files
MrSidimsbader
authored andcommitted
Retain llvm.loop metadata for LoopControlINTEL instruction
In case when debug information presents in the module, the metadata was missing with translation back of LoopControlINTEL instruction due to incorrect instruction ID. Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
1 parent aebc3be commit a90938d

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVBasicBlock.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ SPIRVBasicBlock::addInstruction(SPIRVInstruction *I,
7070
// If insertion of a new instruction before the one passed to the function
7171
// is illegal, insertion before the returned instruction is guaranteed
7272
// to retain correct instruction order in a block
73-
if (Pos != InstVec.begin() && isa<OpLoopMerge>(*std::prev(Pos)))
73+
if (Pos != InstVec.begin() && (isa<OpLoopMerge>(*std::prev(Pos)) ||
74+
isa<OpLoopControlINTEL>(*std::prev(Pos))))
7475
--Pos;
7576
InstVec.insert(Pos, I);
7677
} else
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clang_cc1 -triple spir64-unknown-unknown -cl-std=CL2.0 -O0 -debug-info-kind=standalone -emit-llvm-bc %s -o %t.bc
2+
// RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_unstructured_loop_controls -o %t.spv
3+
// RUN: llvm-spirv %t.spv --to-text -o %t.spt
4+
// RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
5+
// RUN: llvm-spirv -r %t.spv -o %t.bc
6+
// RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-LLVM
7+
8+
// Test that no debug info instruction is inserted between LoopControlINTEL and
9+
// Branch instructions. Otherwise, debug info interferes with SPIRVToLLVM
10+
// translation of structured flow control. Yet, Line DebugInfo instruction is
11+
// still presenting between LoopControlINTEL and Branch instructions.
12+
13+
kernel
14+
void sample() {
15+
#pragma clang loop unroll(full)
16+
for(;;);
17+
}
18+
19+
// CHECK-SPIRV: 2 LoopControlINTEL 1
20+
// CHECK-SPIRV-NOT: ExtInst
21+
// CHECK-SPIRV: {{[0-9]+}} Line {{[0-9]+}} {{[0-9]+}} {{[0-9]+}}
22+
// CHECK-SPIRV: Branch
23+
// CHECK-LLVM: br label %{{.*}}, !dbg !{{[0-9]+}}, !llvm.loop ![[MD:[0-9]+]]
24+
// CHECK-LLVM: ![[MD]] = distinct !{![[MD]], ![[MD_unroll:[0-9]+]]}
25+
// CHECK-LLVM: ![[MD_unroll]] = !{!"llvm.loop.unroll.enable"}

0 commit comments

Comments
 (0)