[llvm] 76be3a0 - [DirectX] Fix crash in DXILOpBuilder for vector types (#107334)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 22:12:05 PDT 2024


Author: Justin Bogner
Date: 2024-09-04T22:12:01-07:00
New Revision: 76be3a0024fe0027bcba9a597fee32a8b2d962ae

URL: https://github.com/llvm/llvm-project/commit/76be3a0024fe0027bcba9a597fee32a8b2d962ae
DIFF: https://github.com/llvm/llvm-project/commit/76be3a0024fe0027bcba9a597fee32a8b2d962ae.diff

LOG: [DirectX] Fix crash in DXILOpBuilder for vector types (#107334)

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

Added: 
    llvm/test/CodeGen/DirectX/sin_vector_error.ll

Modified: 
    llvm/lib/Target/DirectX/DXILOpBuilder.cpp

Removed: 
    


################################################################################
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