[llvm] [DirectX] Fix crash in DXILOpBuilder for vector types (PR #107334)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 17:19:07 PDT 2024


https://github.com/bogner created https://github.com/llvm/llvm-project/pull/107334

This function needs to return the "undefined" sigil for unknown types so that the actual error handling triggers instead of a crash.

>From 348b639b56cb6e4182c84460b80e4c6cf479fb04 Mon Sep 17 00:00:00 2001
From: Justin Bogner <mail at justinbogner.com>
Date: Wed, 4 Sep 2024 16:56:15 -0700
Subject: [PATCH] [DirectX] Fix crash in DXILOpBuilder for vector types

This function needs to return the "undefined" sigil for unknown types so that
the actual error handling triggers instead of a crash.
---
 llvm/lib/Target/DirectX/DXILOpBuilder.cpp     |  3 +--
 llvm/test/CodeGen/DirectX/sin_vector_error.ll | 11 +++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/CodeGen/DirectX/sin_vector_error.ll

diff --git a/llvm/lib/Target/DirectX/DXILOpBuilder.cpp b/llvm/lib/Target/DirectX/DXILOpBuilder.cpp
index ab3ea61d05fc45..efe019a07acaa9 100644
--- a/llvm/lib/Target/DirectX/DXILOpBuilder.cpp
+++ b/llvm/lib/Target/DirectX/DXILOpBuilder.cpp
@@ -123,8 +123,7 @@ static OverloadKind getOverloadKind(Type *Ty) {
   case Type::StructTyID:
     return OverloadKind::ObjectType;
   default:
-    llvm_unreachable("invalid overload type");
-    return OverloadKind::VOID;
+    return OverloadKind::UNDEFINED;
   }
 }
 
diff --git a/llvm/test/CodeGen/DirectX/sin_vector_error.ll b/llvm/test/CodeGen/DirectX/sin_vector_error.ll
new file mode 100644
index 00000000000000..45b8d403390b91
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/sin_vector_error.ll
@@ -0,0 +1,11 @@
+; RUN: not opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.0-library %s 2>&1 | FileCheck %s
+; The sin intrinsic needs to be scalarized before op lowering
+
+; CHECK: error:
+; CHECK-SAME: in function sin_vector
+; CHECK-SAME: Cannot create Sin operation: Invalid overload type
+
+define <4 x float> @sin_vector(<4 x float> %a) {
+  %x = call <4 x float> @llvm.sin.v4f32(<4 x float> %a)
+  ret <4 x float> %x
+}



More information about the llvm-commits mailing list