Skip to content

Commit 0f4ef28

Browse files
committed
Validate HitObject/NumCoherenceBits is not undef / Validate
CoherenceBits when NumBits != 0 / move tests to LitDXILValidation and update them
1 parent 6d96524 commit 0f4ef28

4 files changed

Lines changed: 40 additions & 12 deletions

File tree

lib/DxilValidation/DxilValidation.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,14 +1874,25 @@ static void ValidateDxilOperationCallInProfile(CallInst *CI,
18741874

18751875
// Shader Execution Reordering
18761876
case DXIL::OpCode::MaybeReorderThread: {
1877+
Value *HitObject = CI->getArgOperand(1);
18771878
Value *CoherenceHintBits = CI->getArgOperand(2);
18781879
Value *NumCoherenceHintBits = CI->getArgOperand(3);
18791880

1880-
if (isa<UndefValue>(CoherenceHintBits) ||
1881-
isa<UndefValue>(NumCoherenceHintBits)) {
1881+
if (isa<UndefValue>(HitObject))
1882+
ValCtx.EmitInstrError(CI, ValidationRule::InstrUndefHitObject);
1883+
1884+
if (isa<UndefValue>(NumCoherenceHintBits))
1885+
ValCtx.EmitInstrError(
1886+
CI, ValidationRule::InstrMayReorderThreadUndefCoherenceHintParam);
1887+
1888+
ConstantInt *NumCoherenceHintBitsConst =
1889+
dyn_cast<ConstantInt>(NumCoherenceHintBits);
1890+
const bool HasCoherenceHint =
1891+
NumCoherenceHintBitsConst &&
1892+
NumCoherenceHintBitsConst->getLimitedValue() != 0;
1893+
if (HasCoherenceHint && isa<UndefValue>(CoherenceHintBits))
18821894
ValCtx.EmitInstrError(
18831895
CI, ValidationRule::InstrMayReorderThreadUndefCoherenceHintParam);
1884-
}
18851896
} break;
18861897

18871898
case DXIL::OpCode::AtomicBinOp:

tools/clang/test/DXILValidation/ser_maybereorder_failing.ll renamed to tools/clang/test/LitDXILValidation/ser_maybereorder_failing.ll

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1+
; REQUIRES: dxil-1-9
12
; RUN: not %dxv %s 2>&1 | FileCheck %s
23

34
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"
45
target triple = "dxil-ms-dx"
56

67
%dx.types.HitObject = type { i8* }
78

9+
; CHECK: Function: ?main@@YAXXZ: error: Use of undef coherence hint or num coherence hint bits in MaybeReorderThread.
10+
; CHECK-NEXT: note: at 'call void @dx.op.maybeReorderThread(i32 268, %dx.types.HitObject %nop, i32 1, i32 undef)'
11+
12+
; CHECK: Function: ?main@@YAXXZ: error: Use of undef coherence hint or num coherence hint bits in MaybeReorderThread.
13+
; CHECK-NEXT: note: at 'call void @dx.op.maybeReorderThread(i32 268, %dx.types.HitObject %nop, i32 undef, i32 1)'
14+
15+
; CHECK: Function: ?main@@YAXXZ: error: HitObject is undef.
16+
; CHECK-NEXT: note: at 'call void @dx.op.maybeReorderThread(i32 268, %dx.types.HitObject undef, i32 11, i32 0)'
17+
18+
; CHECK: Validation failed.
19+
820
; Function Attrs: nounwind
921
define void @"\01?main@@YAXXZ"() #0 {
1022
%nop = call %dx.types.HitObject @dx.op.hitObject_MakeNop(i32 266) ; HitObject_MakeNop()
1123

12-
; Validate that coherence hint is not undef.
13-
call void @dx.op.maybeReorderThread(i32 268, %dx.types.HitObject %nop, i32 undef, i32 0) ; MaybeReorderThread(hitObject,coherenceHint,numCoherenceHintBitsFromLSB)
14-
; CHECK: Function: ?main@@YAXXZ: error: Use of undef coherence hint or num coherence hint bits in MaybeReorderThread.
15-
; CHECK-NEXT: note: at 'call void @dx.op.maybeReorderThread(i32 268, %dx.types.HitObject %nop, i32 undef, i32 0)'
24+
; Validate that hit object is not undef.
25+
call void @dx.op.maybeReorderThread(i32 268, %dx.types.HitObject undef, i32 11, i32 0) ; MaybeReorderThread(hitObject,coherenceHint,numCoherenceHintBitsFromLSB)
1626

17-
; Validate that num coherence hint bits from LSB is not undef.
27+
; Validate that coherence hint is not undef while numCoherenceHintBitsFromLSB is not 0.
28+
call void @dx.op.maybeReorderThread(i32 268, %dx.types.HitObject %nop, i32 undef, i32 1) ; MaybeReorderThread(hitObject,coherenceHint,numCoherenceHintBitsFromLSB)
29+
30+
; Validate that num coherence hint bits from LSB is not undef.
1831
call void @dx.op.maybeReorderThread(i32 268, %dx.types.HitObject %nop, i32 1, i32 undef) ; MaybeReorderThread(hitObject,coherenceHint,numCoherenceHintBitsFromLSB)
19-
; CHECK-NEXT: Function: ?main@@YAXXZ: error: Use of undef coherence hint or num coherence hint bits in MaybeReorderThread.
20-
; CHECK-NEXT: note: at 'call void @dx.op.maybeReorderThread(i32 268, %dx.types.HitObject %nop, i32 1, i32 undef)'
2132
ret void
2233
}
23-
; CHECK-NEXT: Validation failed.
2434

2535
; Function Attrs: nounwind readnone
2636
declare %dx.types.HitObject @dx.op.hitObject_MakeNop(i32) #1

tools/clang/test/DXILValidation/ser_maybereorder_passing.ll renamed to tools/clang/test/LitDXILValidation/ser_maybereorder_passing.ll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
; REQUIRES: dxil-1-9
12
; RUN: %dxv %s | FileCheck %s
23

34
; CHECK: Validation succeeded.
@@ -11,7 +12,9 @@ target triple = "dxil-ms-dx"
1112
define void @"\01?main@@YAXXZ"() #0 {
1213
%nop = call %dx.types.HitObject @dx.op.hitObject_MakeNop(i32 266) ; HitObject_MakeNop()
1314
call void @dx.op.maybeReorderThread(i32 268, %dx.types.HitObject %nop, i32 241, i32 3) ; MaybeReorderThread(hitObject,coherenceHint,numCoherenceHintBitsFromLSB)
14-
call void @dx.op.maybeReorderThread(i32 268, %dx.types.HitObject undef, i32 242, i32 7) ; MaybeReorderThread(hitObject,coherenceHint,numCoherenceHintBitsFromLSB)
15+
16+
; Coherence hint disabled, accept 'undef' coherence hint bits.
17+
call void @dx.op.maybeReorderThread(i32 268, %dx.types.HitObject %nop, i32 undef, i32 0) ; MaybeReorderThread(hitObject,coherenceHint,numCoherenceHintBitsFromLSB)
1518
ret void
1619
}
1720

utils/hct/hctdb.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7831,6 +7831,10 @@ def build_valrules(self):
78317831
)
78327832

78337833
# Shader Execution Reordering
7834+
self.add_valrule(
7835+
"Instr.UndefHitObject",
7836+
"HitObject is undef.",
7837+
)
78347838
self.add_valrule(
78357839
"Instr.MayReorderThreadUndefCoherenceHintParam",
78367840
"Use of undef coherence hint or num coherence hint bits in MaybeReorderThread.",

0 commit comments

Comments
 (0)