Skip to content

Commit 80e9148

Browse files
authored
[SYCL] Fix removal of llvm.used for case with spec consts having 2+ u… (#6069)
* [SYCL] Fix removal of llvm.used for case with spec consts having 2+ users llvm.used array elements may be either bitcasts of spec constants or kernels. Bitcasts of kernels must be deleted, while bitcasts of spec constants removal is not required. This patch removes bitcasts of spec constants only if they have 1 user and it is safe to remove them. Signed-off-by: Vyacheslav N Klochkov <vyacheslav.n.klochkov@intel.com>
1 parent 584e890 commit 80e9148

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,17 @@ static bool removeSYCLKernelsConstRefArray(GlobalVariable *GV) {
519519
"Cannot remove initializer of llvm.used global");
520520
Initializer->destroyConstant();
521521
for (auto It = IOperands.begin(); It != IOperands.end(); It++) {
522-
assert(llvm::isSafeToDestroyConstant(*It) &&
523-
"Cannot remove an element of initializer of llvm.used global");
524522
auto Op = (*It)->getOperand(0);
525-
(*It)->destroyConstant();
526-
// Remove unused kernel declarations to avoid LLVM IR check fails.
527523
auto *F = dyn_cast<Function>(Op);
524+
if (llvm::isSafeToDestroyConstant(*It)) {
525+
(*It)->destroyConstant();
526+
} else if (F) {
527+
// The element in "llvm.used" array has other users. That is Ok for
528+
// specialization constants, but is wrong for kernels.
529+
llvm::report_fatal_error("Unexpected usage of SYCL kernel");
530+
}
531+
532+
// Remove unused kernel declarations to avoid LLVM IR check fails.
528533
if (F && F->isDeclaration())
529534
F->eraseFromParent();
530535
}

0 commit comments

Comments
 (0)