diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp index 501231298ed25a..ac85859af8a53e 100644 --- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp +++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp @@ -171,8 +171,9 @@ static bool expandLengthIntrinsic(CallInst *Orig) { Value *Elt = Builder.CreateExtractElement(X, (uint64_t)0); auto *XVec = dyn_cast(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++) { diff --git a/llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error.ll b/llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error.ll index ac3a0513eb6b27..277fbaa462b0fa 100644 --- a/llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error.ll +++ b/llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error.ll @@ -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 } diff --git a/llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error_scalar.ll b/llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error_scalar.ll new file mode 100644 index 00000000000000..ac3a0513eb6b27 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error_scalar.ll @@ -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 +}