Skip to content

Commit 2b19f8f

Browse files
committed
Fix coverage bing used to init dx.ishelper when only discard is used (#3589)
1 parent facf8b7 commit 2b19f8f

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

lib/HLSL/DxilPreparePasses.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %dxc -E ps -T ps_6_0 %s | FileCheck %s
2+
3+
// Make sure we don't initialize @dx.ishelper with coverage when IsHelperLane is not used, but discard is.
4+
// CHECK-NOT: call i32 @dx.op.coverage.i32
5+
6+
float4 a;
7+
8+
[shader("pixel")]
9+
float4 ps(float f : IN): SV_Target
10+
{
11+
if (f < 0.0)
12+
discard;
13+
float4 result = a;
14+
return ddx(result);
15+
}

0 commit comments

Comments
 (0)