[clang] [llvm] [HLSL] implement elementwise firstbithigh hlsl builtin (PR #111082)
Steven Perron via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 4 13:03:35 PDT 2024
================
@@ -0,0 +1,37 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK: OpMemoryModel Logical GLSL450
+
+define noundef i32 @firstbituhigh_i32(i32 noundef %a) {
+entry:
+; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FindUMsb %[[#]]
+ %elt.firstbituhigh = call i32 @llvm.spv.firstbituhigh.i32(i32 %a)
+ ret i32 %elt.firstbituhigh
+}
+
+define noundef i16 @firstbituhigh_i16(i16 noundef %a) {
+entry:
+; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FindUMsb %[[#]]
+ %elt.firstbituhigh = call i16 @llvm.spv.firstbituhigh.i16(i16 %a)
----------------
s-perron wrote:
If this is just passing in `%a` direcectly, is not valid spir-v. If we want to implement this for 16-bit types, we will need to zero-extend the value to 32-bits, and then use FindUMsb. The same for all types smaller than 32-bit.
https://github.com/llvm/llvm-project/pull/111082
More information about the cfe-commits
mailing list