Skip to content

Commit f42c225

Browse files
[SM6.9] Fix LV cast crash (microsoft#8008)
Fixes microsoft#7915 There is a detailed writeup in the issue but in summary, native vectors in SM6.9 shouldn't be optimized in the way this path enables and weren't cleanly being rejected. This change now rejects them --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 28dc9f7 commit f42c225

2 files changed

Lines changed: 44 additions & 12 deletions

File tree

lib/Transforms/Scalar/Float2Int.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,25 @@ static Instruction::BinaryOps mapBinOpcode(unsigned Opcode) {
129129

130130
// Find the roots - instructions that convert from the FP domain to
131131
// integer domain.
132+
// findRoots updated from upstream to skip vectors
132133
void Float2Int::findRoots(Function &F, SmallPtrSet<Instruction*,8> &Roots) {
133-
for (auto &I : inst_range(F)) {
134-
switch (I.getOpcode()) {
135-
default: break;
136-
case Instruction::FPToUI:
137-
case Instruction::FPToSI:
138-
Roots.insert(&I);
139-
break;
140-
case Instruction::FCmp:
141-
if (mapFCmpPred(cast<CmpInst>(&I)->getPredicate()) !=
142-
CmpInst::BAD_ICMP_PREDICATE)
134+
for (BasicBlock &BB : F) {
135+
for (Instruction &I : BB) {
136+
if (isa<VectorType>(I.getType()))
137+
continue;
138+
switch (I.getOpcode()) {
139+
default:
140+
break;
141+
case Instruction::FPToUI:
142+
case Instruction::FPToSI:
143143
Roots.insert(&I);
144-
break;
144+
break;
145+
case Instruction::FCmp:
146+
if (mapFCmpPred(cast<CmpInst>(&I)->getPredicate()) !=
147+
CmpInst::BAD_ICMP_PREDICATE)
148+
Roots.insert(&I);
149+
break;
150+
}
145151
}
146152
}
147153
}
@@ -400,7 +406,7 @@ bool Float2Int::validateAndTransform() {
400406
R.isFullSet() || R.isSignWrappedSet())
401407
continue;
402408
assert(ConvertedToTy && "Must have set the convertedtoty by this point!");
403-
409+
404410
// The number of bits required is the maximum of the upper and
405411
// lower limits, plus one so it can be signed.
406412
unsigned MinBW = std::max(R.getLower().getMinSignedBits(),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %dxc -T cs_6_9 -DFTYPE=float2 %s | FileCheck %s
2+
// RUN: %dxc -T cs_6_9 -DFTYPE=half2 -enable-16bit-types %s | FileCheck %s
3+
4+
5+
// https://github.com/microsoft/DirectXShaderCompiler/issues/7915
6+
// Test long vector casting between uint2 and float2
7+
// which would crash as reported by a user.
8+
9+
// CHECK: call %dx.types.Handle @dx.op.createHandleFromBinding
10+
// CHECK: fptoui
11+
// CHECK: uitofp
12+
// CHECK: fptoui
13+
// CHECK: uitofp
14+
// CHECK: call void @dx.op.rawBufferVectorStore
15+
16+
RWStructuredBuffer<FTYPE> input;
17+
RWStructuredBuffer<FTYPE> output;
18+
19+
FTYPE f1(uint2 p) { return p; }
20+
uint2 f2(FTYPE p) { return f1(p); }
21+
22+
[numthreads(1,1,1)]
23+
void main()
24+
{
25+
output[0] = f2(input[0]);
26+
}

0 commit comments

Comments
 (0)