@@ -516,9 +516,11 @@ class DxilFinalizeModule : public ModulePass {
516516 }
517517 }
518518
519+ GlobalVariable *GetIsHelperGV (Module &M) {
520+ return M.getGlobalVariable (DXIL::kDxIsHelperGlobalName , /* AllowLocal*/ true );
521+ }
519522 GlobalVariable *GetOrCreateIsHelperGV (Module &M, hlsl::OP *hlslOP) {
520- GlobalVariable *GV =
521- M.getGlobalVariable (DXIL::kDxIsHelperGlobalName , /* AllowLocal*/ true );
523+ GlobalVariable *GV = GetIsHelperGV (M);
522524 if (GV)
523525 return GV;
524526 DxilModule &DM = M.GetDxilModule ();
@@ -593,7 +595,11 @@ class DxilFinalizeModule : public ModulePass {
593595 for (auto uit = F->user_begin (); uit != F->user_end ();) {
594596 CallInst *CI = cast<CallInst>(*(uit++));
595597 if (!GV)
596- GV = GetOrCreateIsHelperGV (*F->getParent (), hlslOP);
598+ GV = GetIsHelperGV (*F->getParent ());
599+ // If we don't already have a global for this,
600+ // we didn't have any IsHelper() calls, so no need to add one now.
601+ if (!GV)
602+ return ;
597603 IRBuilder<> Builder (CI);
598604 Value *Cond =
599605 Builder.CreateZExt (DxilInst_Discard (CI).get_condition (), I32Ty);
@@ -618,7 +624,7 @@ class DxilFinalizeModule : public ModulePass {
618624 // in an exported function linked to a PS in another library in this case.
619625 // But it won't pass validation otherwise.
620626 if (pSM->IsLib () && DXIL::CompareVersions (ValMajor, ValMinor, 1 , 6 ) < 1 ) {
621- if (GlobalVariable *GV = M. getGlobalVariable (DXIL:: kDxIsHelperGlobalName , /* AllowLocal */ true )) {
627+ if (GlobalVariable *GV = GetIsHelperGV (M )) {
622628 GV->setLinkage (GlobalValue::InternalLinkage);
623629 }
624630 }
0 commit comments