Skip to content

[sycl-post-link] Improve spec constants pattern recognition #3360

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

Merged
merged 2 commits into from
Mar 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions llvm/tools/sycl-post-link/SpecConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ StringRef getStringLiteralArg(const CallInst *CI, unsigned ArgNo,
// @.str = private unnamed_addr constant[10 x i8] c"SpecConst\00", align 1
// ...
// %TName = alloca i8 addrspace(4)*, align 8
// %TName.ascast = addrspacecast i8 addrspace(4)** %TName to
// i8 addrspace(4)* addrspace(4)*
// ...
// store i8 addrspace(4)* getelementptr inbounds ([19 x i8], [19 x i8]
// addrspace(4)* addrspacecast ([19 x i8] addrspace(1)* @str to [19 x i8]
// addrspace(4)*), i64 0, i64 0), i8 addrspace(4)* addrspace(4)*
// %TName.ascast, align 8
// %0 = load i8 addrspace(4)*, i8 addrspace(4)* addrspace(4)* %TName.ascast,
// align 8
// %call = call spir_func zeroext
// i1 @_Z27__sycl_getSpecConstantValueIbET_PKc(i8 addrspace(4)* %0)
// ^^^^^^^^^^^^^^^^^^^^
// or (optimized version)
// vvvvvvvvvvvvvvvvvvvv
// @.str = private unnamed_addr constant[10 x i8] c"SpecConst\00", align 1
// ...
// %TName = alloca i8 addrspace(4)*, align 8
// ...
// store i8 addrspace(4)* addrspacecast(
// i8* getelementptr inbounds([10 x i8], [10 x i8] * @.str, i32 0, i32 0)
Expand All @@ -68,8 +85,14 @@ StringRef getStringLiteralArg(const CallInst *CI, unsigned ArgNo,
// sequence, w/o any intervening stores and calls between the store and load
// so that %1 is trivially known to be the address of the @.str literal.

AllocaInst *TmpPtr =
cast<AllocaInst>(L->getPointerOperand()->stripPointerCasts());
Value *TmpPtr = L->getPointerOperand();
AssertRelease((isa<AddrSpaceCastInst>(TmpPtr) &&
isa<AllocaInst>(cast<AddrSpaceCastInst>(TmpPtr)
->getPointerOperand()
->stripPointerCasts())) ||
isa<AllocaInst>(TmpPtr),
"unexpected instruction type");

// find the store of the literal address into TmpPtr
StoreInst *Store = nullptr;

Expand Down