@@ -40,19 +40,18 @@ static void AssertRelease(bool Cond, const char *Msg) {
4040
4141StringRef getStringLiteralArg (const CallInst *CI, unsigned ArgNo,
4242 SmallVectorImpl<Instruction *> &DelInsts,
43- GlobalVariable *&DelGlob ) {
43+ GlobalVariable *&SymGlob ) {
4444 Value *V = CI->getArgOperand (ArgNo)->stripPointerCasts ();
4545
4646 if (auto *L = dyn_cast<LoadInst>(V)) {
4747 // Must be a
4848 // vvvvvvvvvvvvvvvvvvvv
49- // @.str = private unnamed_addr constant[18 x i8]
50- // c"_ZTS11MyBoolConst\00", align 1
49+ // @.str = private unnamed_addr constant[10 x i8] c"SpecConst\00", align 1
5150 // ...
5251 // %TName = alloca i8 addrspace(4)*, align 8
5352 // ...
5453 // store i8 addrspace(4)* addrspacecast(
55- // i8* getelementptr inbounds([18 x i8], [18 x i8] * @.str, i32 0, i32 0)
54+ // i8* getelementptr inbounds([10 x i8], [10 x i8] * @.str, i32 0, i32 0)
5655 // to i8 addrspace(4)*), i8 addrspace(4)** %TName, align 8, !tbaa !10
5756 // %1 = load i8 addrspace(4)*, i8 addrspace(4)** %TName, align 8, !tbaa !10
5857 // %call = call spir_func zeroext
@@ -96,7 +95,7 @@ StringRef getStringLiteralArg(const CallInst *CI, unsigned ArgNo,
9695 V = Store->getValueOperand ()->stripPointerCasts ();
9796 }
9897 const Constant *Init = cast<GlobalVariable>(V)->getInitializer ();
99- DelGlob = cast<GlobalVariable>(V);
98+ SymGlob = cast<GlobalVariable>(V);
10099 StringRef Res = cast<ConstantDataArray>(Init)->getAsString ();
101100 if (Res.size () > 0 && Res[Res.size () - 1 ] == ' \0 ' )
102101 Res = Res.substr (0 , Res.size () - 1 );
@@ -214,8 +213,8 @@ PreservedAnalyses SpecConstantsPass::run(Module &M,
214213 // code can't use this intrinsic directly.
215214 SmallVector<Instruction *, 3 > DelInsts;
216215 DelInsts.push_back (CI);
217- GlobalVariable *DelGlob = nullptr ;
218- StringRef SymID = getStringLiteralArg (CI, 0 , DelInsts, DelGlob );
216+ GlobalVariable *SymGlob = nullptr ;
217+ StringRef SymID = getStringLiteralArg (CI, 0 , DelInsts, SymGlob );
219218 Type *SCTy = CI->getType ();
220219
221220 if (SetValAtRT) {
@@ -262,9 +261,8 @@ PreservedAnalyses SpecConstantsPass::run(Module &M,
262261 I->removeFromParent ();
263262 I->deleteValue ();
264263 }
265- DelGlob->replaceAllUsesWith (ConstantPointerNull::get (DelGlob->getType ()));
266- DelGlob->removeFromParent ();
267- DelGlob->deleteValue ();
264+ // Don't delete SymGlob here, as it may be referenced from multiple
265+ // functions if __sycl_getSpecConstantValue is inlined.
268266 }
269267 }
270268 return IRModified ? PreservedAnalyses::none () : PreservedAnalyses::all ();
0 commit comments