Skip to content

Commit 69f0295

Browse files
committed
[DirectX] only allow intrinsics defined in DXIL.td
Fixes #128071 The current behavior lets intrinsics that don't map to a DXILOP slip through. Nothing catches this until we hit the DXIL validator. This change fails earlier so we don't encode invalid llvm intrinsics that can slip through because of clang builtins like `__builtin_reduce_and` example: https://hlsl.godbolt.org/z/13rPj18vn
1 parent 724b91b commit 69f0295

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

llvm/lib/Target/DirectX/DXILOpLowering.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,11 @@ class OpLowerer {
770770
continue;
771771
Intrinsic::ID ID = F.getIntrinsicID();
772772
switch (ID) {
773-
default:
774-
continue;
773+
default: {
774+
DiagnosticInfoUnsupported Diag(F, "Unknown intrinsic?");
775+
M.getContext().diagnose(Diag);
776+
break;
777+
}
775778
#define DXIL_OP_INTRINSIC(OpCode, Intrin, ...) \
776779
case Intrin: \
777780
HasErrors |= replaceFunctionWithOp( \
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; RUN: not opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s 2>&1 | FileCheck %s
2+
3+
; CHECK: error: <unknown>:0:0: in function llvm.vector.reduce.and.v4i32 i32 (<4 x i32>): Unknown intrinsic?
4+
define i32 @fn_and(<4 x i32> %0) local_unnamed_addr #0 {
5+
%2 = tail call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %0)
6+
ret i32 %2
7+
}
8+
9+
declare i32 @llvm.vector.reduce.and.v4i32(<4 x i32>)
10+
11+
attributes #0 = { convergent norecurse nounwind "hlsl.export"}

0 commit comments

Comments
 (0)