Skip to content

Commit a89e18e

Browse files
authored
Disallow 64bit msad, ibfe, and ubfe (microsoft#7774)
These instructions should never be gnereated and it was almost certainly an error that we marked them as allowed by the DXIL validator.
1 parent 7f771fb commit a89e18e

3 files changed

Lines changed: 101 additions & 7 deletions

File tree

lib/DXIL/DxilOperations.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,16 +477,16 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
477477
"tertiary",
478478
Attribute::ReadNone,
479479
1,
480-
{{0xc0}},
481-
{{0x0}}}, // Overloads: il
480+
{{0x40}},
481+
{{0x0}}}, // Overloads: i
482482
{OC::Ibfe,
483483
"Ibfe",
484484
OCC::Tertiary,
485485
"tertiary",
486486
Attribute::ReadNone,
487487
1,
488-
{{0xc0}},
489-
{{0x0}}}, // Overloads: il
488+
{{0x40}},
489+
{{0x0}}}, // Overloads: i
490490

491491
// Tertiary uint
492492
{OC::Ubfe,
@@ -495,8 +495,8 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
495495
"tertiary",
496496
Attribute::ReadNone,
497497
1,
498-
{{0xc0}},
499-
{{0x0}}}, // Overloads: il
498+
{{0x40}},
499+
{{0x0}}}, // Overloads: i
500500

501501
// Quaternary
502502
{OC::Bfi,
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
; REQUIRES: dxil-1-9
2+
; RUN: not %dxv %s 2>&1 | FileCheck %s
3+
4+
; CHECK: Function: main: error: DXIL intrinsic overload must be valid.
5+
; CHECK: note: at '%24 = call i64 @dx.op.tertiary.i64(i32 52, i64 %19, i64 %20, i64 %20)' in block '#0' of function 'main'.
6+
; CHECK: Function: main: error: DXIL intrinsic overload must be valid.
7+
; CHECK: note: at '%23 = call i64 @dx.op.tertiary.i64(i32 51, i64 %19, i64 %20, i64 %20)' in block '#0' of function 'main'.
8+
; CHECK: Function: main: error: DXIL intrinsic overload must be valid.
9+
; CHECK: note: at '%22 = call i64 @dx.op.tertiary.i64(i32 50, i64 %19, i64 %20, i64 %20)' in block '#0' of function 'main'.
10+
target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64"
11+
target triple = "dxil-ms-dx"
12+
13+
%dx.types.Handle = type { i8* }
14+
%dx.types.ResRet.i32 = type { i32, i32, i32, i32, i32 }
15+
%"class.RWStructuredBuffer<SMsad4>" = type { %struct.SMsad4 }
16+
%struct.SMsad4 = type { i32, <2 x i32>, <4 x i32>, <4 x i32> }
17+
18+
define void @main() {
19+
%1 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 0, i32 0, i1 false) ; CreateHandle(resourceClass,rangeId,index,nonUniformIndex)
20+
%2 = call i32 @dx.op.flattenedThreadIdInGroup.i32(i32 96) ; FlattenedThreadIdInGroup()
21+
%3 = call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68, %dx.types.Handle %1, i32 %2, i32 0) ; BufferLoad(srv,index,wot)
22+
%4 = extractvalue %dx.types.ResRet.i32 %3, 0
23+
%5 = call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68, %dx.types.Handle %1, i32 %2, i32 4) ; BufferLoad(srv,index,wot)
24+
%6 = extractvalue %dx.types.ResRet.i32 %5, 0
25+
%7 = extractvalue %dx.types.ResRet.i32 %5, 1
26+
%8 = call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68, %dx.types.Handle %1, i32 %2, i32 12) ; BufferLoad(srv,index,wot)
27+
%9 = extractvalue %dx.types.ResRet.i32 %8, 0
28+
%10 = extractvalue %dx.types.ResRet.i32 %8, 1
29+
%11 = extractvalue %dx.types.ResRet.i32 %8, 2
30+
%12 = extractvalue %dx.types.ResRet.i32 %8, 3
31+
%13 = lshr i32 %6, 8
32+
%14 = call i32 @dx.op.quaternary.i32(i32 53, i32 8, i32 24, i32 %7, i32 %13) ; Bfi(width,offset,value,replacedValue)
33+
%15 = lshr i32 %6, 16
34+
%16 = call i32 @dx.op.quaternary.i32(i32 53, i32 16, i32 16, i32 %7, i32 %15) ; Bfi(width,offset,value,replacedValue)
35+
%17 = lshr i32 %6, 24
36+
%18 = call i32 @dx.op.quaternary.i32(i32 53, i32 24, i32 8, i32 %7, i32 %17) ; Bfi(width,offset,value,replacedValue)
37+
%19 = zext i32 %4 to i64
38+
%20 = zext i32 %14 to i64
39+
%21 = zext i32 %10 to i64
40+
41+
%22 = call i64 @dx.op.tertiary.i64(i32 50, i64 %19, i64 %20, i64 %20) ; Msad(a,b,c)
42+
%23 = call i64 @dx.op.tertiary.i64(i32 51, i64 %19, i64 %20, i64 %20) ; Ubfe(a,b,c)
43+
%24 = call i64 @dx.op.tertiary.i64(i32 52, i64 %19, i64 %20, i64 %20) ; Ibfe(a,b,c)
44+
45+
%25 = trunc i64 %22 to i32
46+
%26 = trunc i64 %23 to i32
47+
%27 = trunc i64 %24 to i32
48+
call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %1, i32 %2, i32 0, i32 %25, i32 undef, i32 undef, i32 undef, i8 1) ; BufferStore(uav,coord0,coord1,value0,value1,value2,value3,mask)
49+
call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %1, i32 %2, i32 4, i32 %26, i32 %7, i32 undef, i32 undef, i8 3) ; BufferStore(uav,coord0,coord1,value0,value1,value2,value3,mask)
50+
call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %1, i32 %2, i32 12, i32 %27, i32 %10, i32 %11, i32 %12, i8 15) ; BufferStore(uav,coord0,coord1,value0,value1,value2,value3,mask)
51+
ret void
52+
}
53+
54+
; Function Attrs: nounwind readnone
55+
declare i32 @dx.op.flattenedThreadIdInGroup.i32(i32) #0
56+
57+
; Function Attrs: nounwind readnone
58+
declare i32 @dx.op.quaternary.i32(i32, i32, i32, i32, i32) #0
59+
60+
; Function Attrs: nounwind readnone
61+
declare i64 @dx.op.tertiary.i64(i32, i64, i64, i64) #0
62+
63+
; Function Attrs: nounwind readonly
64+
declare %dx.types.Handle @dx.op.createHandle(i32, i8, i32, i32, i1) #1
65+
66+
; Function Attrs: nounwind readonly
67+
declare %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32, %dx.types.Handle, i32, i32) #1
68+
69+
; Function Attrs: nounwind
70+
declare void @dx.op.bufferStore.i32(i32, %dx.types.Handle, i32, i32, i32, i32, i32, i32, i8) #2
71+
72+
attributes #0 = { nounwind readnone }
73+
attributes #1 = { nounwind readonly }
74+
attributes #2 = { nounwind }
75+
76+
!llvm.ident = !{!0}
77+
!dx.version = !{!1}
78+
!dx.valver = !{!2}
79+
!dx.shaderModel = !{!3}
80+
!dx.resources = !{!4}
81+
!dx.entryPoints = !{!8}
82+
83+
!0 = !{!"dxc(private) 1.8.0.14883 (main, e50f599ff30-dirty)"}
84+
!1 = !{i32 1, i32 0}
85+
!2 = !{i32 1, i32 9}
86+
!3 = !{!"cs", i32 6, i32 0}
87+
!4 = !{null, !5, null, null}
88+
!5 = !{!6}
89+
!6 = !{i32 0, %"class.RWStructuredBuffer<SMsad4>"* undef, !"", i32 0, i32 0, i32 1, i32 12, i1 false, i1 false, i1 false, !7}
90+
!7 = !{i32 1, i32 44}
91+
!8 = !{void ()* @main, !"main", null, !4, !9}
92+
!9 = !{i32 0, i64 144, i32 4, !10}
93+
!10 = !{i32 8, i32 8, i32 1}
94+

utils/hct/hctdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ def UFI(name, **mappings):
17581758
next_op_idx,
17591759
"Tertiary",
17601760
"performs an integral " + i,
1761-
"il",
1761+
"i",
17621762
"rn",
17631763
[
17641764
db_dxil_param(0, "$o", "", "the operation result"),

0 commit comments

Comments
 (0)