-
Notifications
You must be signed in to change notification settings - Fork 788
[SYCL] Fix sycl-post-link to work when a spec const is referenced twice. #1524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
; This test checks that the tool does not crash and removes the unused spec | ||
; constant global symbol when it is referenced more than once. | ||
|
||
; RUN: sycl-post-link -spec-const=rt --ir-output-only %s -S -o - \ | ||
; RUN: | FileCheck %s | ||
|
||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" | ||
target triple = "spir64-unknown-unknown-sycldevice" | ||
|
||
%"sycl::experimental::spec_constant" = type { i8 } | ||
|
||
@SCSymID = private unnamed_addr constant [10 x i8] c"SpecConst\00", align 1 | ||
; CHECK-NOT: @SCSymID | ||
|
||
declare dso_local spir_func float @_Z27__sycl_getSpecConstantValueIfET_PKc(i8 addrspace(4)*) | ||
|
||
; Function Attrs: norecurse | ||
define weak_odr dso_local spir_kernel void @Kernel() { | ||
%1 = call spir_func float @_Z27__sycl_getSpecConstantValueIfET_PKc(i8 addrspace(4)* addrspacecast (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @SCSymID, i64 0, i64 0) to i8 addrspace(4)*)) | ||
ret void | ||
} | ||
|
||
; Function Attrs: norecurse | ||
define dso_local spir_func float @foo_float(%"sycl::experimental::spec_constant" addrspace(4)* nocapture readnone dereferenceable(1) %0) local_unnamed_addr #3 { | ||
%2 = tail call spir_func float @_Z27__sycl_getSpecConstantValueIfET_PKc(i8 addrspace(4)* addrspacecast (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @SCSymID, i64 0, i64 0) to i8 addrspace(4)*)) | ||
ret float %2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
; This test checks that the post-link tool works correctly when both | ||
; device code splitting and specialization constant processing are | ||
; requested. | ||
; | ||
; RUN: sycl-post-link -split=kernel -spec-const=rt -S %s -o %t.files.table | ||
; RUN: FileCheck %s -input-file=%t.files_0.ll --check-prefixes CHECK0,CHECK | ||
; RUN: FileCheck %s -input-file=%t.files_1.ll --check-prefixes CHECK1,CHECK | ||
|
||
@SCSymID = private unnamed_addr constant [10 x i8] c"SpecConst\00", align 1 | ||
; CHECK-NOT: @SCSymID | ||
|
||
declare dso_local spir_func zeroext i1 @_Z27__sycl_getSpecConstantValueIbET_PKc(i8 addrspace(4)*) | ||
|
||
define dso_local spir_kernel void @KERNEL_AAA() { | ||
%1 = call spir_func zeroext i1 @_Z27__sycl_getSpecConstantValueIbET_PKc(i8 addrspace(4)* addrspacecast (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @SCSymID, i64 0, i64 0) to i8 addrspace(4)*)) | ||
; CHECK0: %{{[0-9]+}} = call i1 @_Z20__spirv_SpecConstantib(i32 0, i1 false), !SYCL_SPEC_CONST_SYM_ID ![[MD_ID:[0-9]+]] | ||
ret void | ||
} | ||
|
||
define dso_local spir_kernel void @KERNEL_BBB() { | ||
%1 = call spir_func zeroext i1 @_Z27__sycl_getSpecConstantValueIbET_PKc(i8 addrspace(4)* addrspacecast (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @SCSymID, i64 0, i64 0) to i8 addrspace(4)*)) | ||
; CHECK1: %{{[0-9]+}} = call i1 @_Z20__spirv_SpecConstantib(i32 0, i1 false), !SYCL_SPEC_CONST_SYM_ID ![[MD_ID:[0-9]+]] | ||
ret void | ||
} | ||
|
||
; CHECK: ![[MD_ID]] = !{!"SpecConst", i32 0} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
#include "llvm/Support/SystemUtils.h" | ||
#include "llvm/Support/WithColor.h" | ||
#include "llvm/Transforms/IPO.h" | ||
#include "llvm/Transforms/IPO/GlobalDCE.h" | ||
#include "llvm/Transforms/Utils/Cloning.h" | ||
#include <memory> | ||
|
||
|
@@ -427,6 +428,9 @@ int main(int argc, char **argv) { | |
// Register required analysis | ||
MAM.registerPass([&] { return PassInstrumentationAnalysis(); }); | ||
RunSpecConst.addPass(SCP); | ||
if (!DoSplit) | ||
// This pass deletes unreachable globals. Code splitter runs it later. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great if we add a test with spec constants handling and split both. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not really apply to this fix. But this is important missing test case - agree, so I'll add a test. |
||
RunSpecConst.addPass(GlobalDCEPass()); | ||
PreservedAnalyses Res = RunSpecConst.run(*MPtr, MAM); | ||
SpecConstsMet = !Res.areAllPreserved(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes the following comment with LLVM IR invalid for types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok