Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions include/dxc/DXIL/DxilUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ namespace dxilutil {

void ReplaceRawBufferLoad64Bit(llvm::Function *F, llvm::Type *EltTy, hlsl::OP *hlslOP);
void ReplaceRawBufferStore64Bit(llvm::Function *F, llvm::Type *ETy, hlsl::OP *hlslOP);

bool IsConvergentMarker(llvm::Value *V);
llvm::Value *GetConvergentSource(llvm::Value *V);
}

}
19 changes: 0 additions & 19 deletions include/dxc/HLSL/DxilConvergent.h

This file was deleted.

21 changes: 21 additions & 0 deletions lib/DXIL/DxilUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "dxc/DXIL/DxilUtil.h"
#include "dxc/DXIL/DxilModule.h"
#include "dxc/DXIL/DxilOperations.h"
#include "dxc/HLSL/DxilConvergentName.h"
#include "dxc/Support/Global.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
Expand Down Expand Up @@ -1171,6 +1172,26 @@ void ReplaceRawBufferStore64Bit(llvm::Function *F, llvm::Type *ETy, hlsl::OP *hl
}
}

bool IsConvergentMarker(const char *Name) {
StringRef RName = Name;
return RName.startswith(kConvergentFunctionPrefix);
}

bool IsConvergentMarker(const Function *F) {
return F && F->getName().startswith(kConvergentFunctionPrefix);
}

bool IsConvergentMarker(Value *V) {
CallInst *CI = dyn_cast<CallInst>(V);
if (!CI)
return false;
return IsConvergentMarker(CI->getCalledFunction());
}

Value *GetConvergentSource(Value *V) {
return cast<CallInst>(V)->getOperand(0);
}

}
}

Expand Down
11 changes: 0 additions & 11 deletions lib/HLSL/DxilConvergent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,13 @@
#include "dxc/HLSL/DxilGenerationPass.h"
#include "dxc/HLSL/HLOperations.h"
#include "dxc/HLSL/HLModule.h"
#include "dxc/HLSL/DxilConvergent.h"
#include "dxc/HlslIntrinsicOp.h"
#include "dxc/HLSL/DxilConvergentName.h"

using namespace llvm;
using namespace hlsl;

bool hlsl::IsConvergentMarker(Value *V) {
CallInst *CI = dyn_cast<CallInst>(V);
if (!CI)
return false;
Function *F = CI->getCalledFunction();
return F->getName().startswith(kConvergentFunctionPrefix);
}

Value *hlsl::GetConvergentSource(Value *V) {
return cast<CallInst>(V)->getOperand(0);
}

///////////////////////////////////////////////////////////////////////////////
// DxilConvergent.
Expand Down
5 changes: 2 additions & 3 deletions lib/HLSL/HLOperationLower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "dxc/HLSL/HLOperationLowerExtension.h"
#include "dxc/HLSL/HLOperations.h"
#include "dxc/HlslIntrinsicOp.h"
#include "dxc/HLSL/DxilConvergent.h"
#include "dxc/DXIL/DxilResourceProperties.h"

#include "llvm/IR/GetElementPtrTypeIterator.h"
Expand Down Expand Up @@ -844,8 +843,8 @@ Value *FindScalarSource(Value *src, unsigned vecIdx = 0) {
vecIdx = (unsigned)cast<ConstantInt>(EE->getIndexOperand())
->getUniqueInteger().getLimitedValue();
src = EE->getVectorOperand();
} else if (hlsl::IsConvergentMarker(src)) {
src = hlsl::GetConvergentSource(src);
} else if (hlsl::dxilutil::IsConvergentMarker(src)) {
src = hlsl::dxilutil::GetConvergentSource(src);
} else {
break; // Found it.
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "llvm/Support/raw_ostream.h"

#include "dxc/DXIL/DxilMetadataHelper.h" // HLSL Change - combine dxil metadata.
#include "dxc/DXIL/DxilUtil.h" // HLSL Change - special handling of convergent marker
using namespace llvm;

#define DEBUG_TYPE "local"
Expand Down Expand Up @@ -331,6 +332,10 @@ bool llvm::isInstructionTriviallyDead(Instruction *I,
if (Constant *C = dyn_cast<Constant>(CI->getArgOperand(0)))
return C->isNullValue() || isa<UndefValue>(C);

// HLSL change - don't force unused convergenet markers to stay
if (CallInst *CI = dyn_cast<CallInst>(I))
if (hlsl::dxilutil::IsConvergentMarker(CI)) return true;

return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %dxc /T ps_6_0 %s | FileCheck %s

// Tests that a convergent marker added by a derivative call
// is removed in time to let the rest of the dead code be removed


// Since everything is ignored, there should be no conditionals
// and just a single return void

// CHECK: void @main
// CHECK-NOT: br
// CHECK: storeOutput
// CHECK: ret void

float main(float d : DEPTH0) : SV_Target {
if (d > 0)
d = max(d, 3.0);
ddx(d+1);
return 0.0;
}