Skip to content

Commit 83b4b75

Browse files
authored
[sycl-post-link] Improve spec constants pattern recognition (#3360)
1113d0a changes addrspacecast instruction generation. This impacts the pattern recognition if LLVM IR is not optimized before SpecConstantsPass. Now both load and store instructions accepting cast pointer instead of a pointer produced by alloca instruction. This change make pattern recognition to support both versions of LLVM IR.
1 parent 6e79f42 commit 83b4b75

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ StringRef getStringLiteralArg(const CallInst *CI, unsigned ArgNo,
5757
// @.str = private unnamed_addr constant[10 x i8] c"SpecConst\00", align 1
5858
// ...
5959
// %TName = alloca i8 addrspace(4)*, align 8
60+
// %TName.ascast = addrspacecast i8 addrspace(4)** %TName to
61+
// i8 addrspace(4)* addrspace(4)*
62+
// ...
63+
// store i8 addrspace(4)* getelementptr inbounds ([19 x i8], [19 x i8]
64+
// addrspace(4)* addrspacecast ([19 x i8] addrspace(1)* @str to [19 x i8]
65+
// addrspace(4)*), i64 0, i64 0), i8 addrspace(4)* addrspace(4)*
66+
// %TName.ascast, align 8
67+
// %0 = load i8 addrspace(4)*, i8 addrspace(4)* addrspace(4)* %TName.ascast,
68+
// align 8
69+
// %call = call spir_func zeroext
70+
// i1 @_Z27__sycl_getSpecConstantValueIbET_PKc(i8 addrspace(4)* %0)
71+
// ^^^^^^^^^^^^^^^^^^^^
72+
// or (optimized version)
73+
// vvvvvvvvvvvvvvvvvvvv
74+
// @.str = private unnamed_addr constant[10 x i8] c"SpecConst\00", align 1
75+
// ...
76+
// %TName = alloca i8 addrspace(4)*, align 8
6077
// ...
6178
// store i8 addrspace(4)* addrspacecast(
6279
// i8* getelementptr inbounds([10 x i8], [10 x i8] * @.str, i32 0, i32 0)
@@ -68,8 +85,14 @@ StringRef getStringLiteralArg(const CallInst *CI, unsigned ArgNo,
6885
// sequence, w/o any intervening stores and calls between the store and load
6986
// so that %1 is trivially known to be the address of the @.str literal.
7087

71-
AllocaInst *TmpPtr =
72-
cast<AllocaInst>(L->getPointerOperand()->stripPointerCasts());
88+
Value *TmpPtr = L->getPointerOperand();
89+
AssertRelease((isa<AddrSpaceCastInst>(TmpPtr) &&
90+
isa<AllocaInst>(cast<AddrSpaceCastInst>(TmpPtr)
91+
->getPointerOperand()
92+
->stripPointerCasts())) ||
93+
isa<AllocaInst>(TmpPtr),
94+
"unexpected instruction type");
95+
7396
// find the store of the literal address into TmpPtr
7497
StoreInst *Store = nullptr;
7598

0 commit comments

Comments
 (0)