Skip to content

Commit

Permalink
make an llvm error when length input is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
bob80905 committed Aug 2, 2024
1 parent d04a061 commit dc3a89d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ static bool expandLengthIntrinsic(CallInst *Orig) {
Value *Elt = Builder.CreateExtractElement(X, (uint64_t)0);
auto *XVec = dyn_cast<FixedVectorType>(Ty);
unsigned XVecSize = XVec->getNumElements();
assert(Ty->isVectorTy() && XVecSize > 1 &&
"dx.length requires a vector of length 2 or more");
if (!(Ty->isVectorTy() && XVecSize > 1))
report_fatal_error(Twine("Invalid input type for length intrinsic"),
/* gen_crash_diag=*/false);

Value *Sum = Builder.CreateFMul(Elt, Elt);
for (unsigned I = 1; I < XVecSize; I++) {
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error.ll
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
; RUN: not opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s 2>&1 | FileCheck %s

; DXIL operation length does not support scalar types
; CHECK: error: invalid intrinsic signature
; DXIL operation length does not support 1-element vector types.
; CHECK: LLVM ERROR: Invalid input type for length intrinsic

define noundef float @test_length_float(float noundef %p0) {
define noundef float @test_length_float(<1 x float> noundef %p0) {
entry:
%hlsl.length = call float @llvm.dx.length.f32(float %p0)
%hlsl.length = call float @llvm.dx.length.v1f32(<1 x float> %p0)
ret float %hlsl.length
}
10 changes: 10 additions & 0 deletions llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error_scalar.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; RUN: not opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s 2>&1 | FileCheck %s

; DXIL operation length does not support scalar types
; CHECK: error: invalid intrinsic signature

define noundef float @test_length_float(float noundef %p0) {
entry:
%hlsl.length = call float @llvm.dx.length.f32(float %p0)
ret float %hlsl.length
}

0 comments on commit dc3a89d

Please sign in to comment.