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
30 changes: 18 additions & 12 deletions lib/Transforms/Scalar/Float2Int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,25 @@ static Instruction::BinaryOps mapBinOpcode(unsigned Opcode) {

// Find the roots - instructions that convert from the FP domain to
// integer domain.
// findRoots updated from upstream to skip vectors
void Float2Int::findRoots(Function &F, SmallPtrSet<Instruction*,8> &Roots) {
for (auto &I : inst_range(F)) {
switch (I.getOpcode()) {
default: break;
case Instruction::FPToUI:
case Instruction::FPToSI:
Roots.insert(&I);
break;
case Instruction::FCmp:
if (mapFCmpPred(cast<CmpInst>(&I)->getPredicate()) !=
CmpInst::BAD_ICMP_PREDICATE)
for (BasicBlock &BB : F) {
for (Instruction &I : BB) {
if (isa<VectorType>(I.getType()))
continue;
switch (I.getOpcode()) {
default:
break;
case Instruction::FPToUI:
case Instruction::FPToSI:
Roots.insert(&I);
break;
break;
case Instruction::FCmp:
if (mapFCmpPred(cast<CmpInst>(&I)->getPredicate()) !=
CmpInst::BAD_ICMP_PREDICATE)
Roots.insert(&I);
break;
}
}
}
}
Expand Down Expand Up @@ -400,7 +406,7 @@ bool Float2Int::validateAndTransform() {
R.isFullSet() || R.isSignWrappedSet())
continue;
assert(ConvertedToTy && "Must have set the convertedtoty by this point!");

// The number of bits required is the maximum of the upper and
// lower limits, plus one so it can be signed.
unsigned MinBW = std::max(R.getLower().getMinSignedBits(),
Expand Down
26 changes: 26 additions & 0 deletions tools/clang/test/HLSLFileCheck/hlsl/types/cast/cast8.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %dxc -T cs_6_9 -DFTYPE=float2 %s | FileCheck %s
// RUN: %dxc -T cs_6_9 -DFTYPE=half2 -enable-16bit-types %s | FileCheck %s


// https://github.com/microsoft/DirectXShaderCompiler/issues/7915
// Test long vector casting between uint2 and float2
// which would crash as reported by a user.

// CHECK: call %dx.types.Handle @dx.op.createHandleFromBinding
// CHECK: fptoui
// CHECK: uitofp
// CHECK: fptoui
// CHECK: uitofp
// CHECK: call void @dx.op.rawBufferVectorStore

RWStructuredBuffer<FTYPE> input;
RWStructuredBuffer<FTYPE> output;

FTYPE f1(uint2 p) { return p; }
uint2 f2(FTYPE p) { return f1(p); }

[numthreads(1,1,1)]
void main()
{
output[0] = f2(input[0]);
}