[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-x86_64-debian-dylib` running on `gribozavr4` while building `clang,llvm` at step 7 "test-build-unified-tree-check-llvm". Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/17567 Here is the relevant piece of the build log for the reference ``` Step 7 (test-build-unified-tree-check-llvm) failure: test (failure) TEST 'LLVM :: CodeGen/SPIRV/opencl/reflect-error.ll' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: not /b/1/llvm-x86_64-debian-dylib/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown /b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null 2>&1 | /b/1/llvm-x86_64-debian-dylib/build/bin/FileCheck /b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll + not /b/1/llvm-x86_64-debian-dylib/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown /b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null + /b/1/llvm-x86_64-debian-dylib/build/bin/FileCheck /b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll RUN: at line 2: not /b/1/llvm-x86_64-debian-dylib/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown /b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null 2>&1 | /b/1/llvm-x86_64-debian-dylib/build/bin/FileCheck /b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll + not /b/1/llvm-x86_64-debian-dylib/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown /b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null + /b/1/llvm-x86_64-debian-dylib/build/bin/FileCheck /b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll RUN: at line 3: not + not -- ``` https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-expensive-checks-debian` running on `gribozavr4` while building `clang,llvm` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/16/builds/12395 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'LLVM :: CodeGen/SPIRV/opencl/reflect-error.ll' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: not /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null 2>&1 | /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll + not /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null + /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll RUN: at line 2: not /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null 2>&1 | /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll + not /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null + /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll RUN: at line 3: not + not -- ``` https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `ml-opt-rel-x86-64` running on `ml-opt-rel-x86-64-b1` while building `clang,llvm` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/185/builds/11836 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'LLVM :: CodeGen/SPIRV/opencl/reflect-error.ll' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: not /b/ml-opt-rel-x86-64-b1/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown /b/ml-opt-rel-x86-64-b1/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null 2>&1 | /b/ml-opt-rel-x86-64-b1/build/bin/FileCheck /b/ml-opt-rel-x86-64-b1/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll + not /b/ml-opt-rel-x86-64-b1/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown /b/ml-opt-rel-x86-64-b1/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null + /b/ml-opt-rel-x86-64-b1/build/bin/FileCheck /b/ml-opt-rel-x86-64-b1/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll RUN: at line 2: not /b/ml-opt-rel-x86-64-b1/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown /b/ml-opt-rel-x86-64-b1/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null 2>&1 | /b/ml-opt-rel-x86-64-b1/build/bin/FileCheck /b/ml-opt-rel-x86-64-b1/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll + not /b/ml-opt-rel-x86-64-b1/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown /b/ml-opt-rel-x86-64-b1/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null + /b/ml-opt-rel-x86-64-b1/build/bin/FileCheck /b/ml-opt-rel-x86-64-b1/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll RUN: at line 3: not + not -- ``` https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-gcc-ubuntu` running on `sie-linux-worker3` while building `clang,llvm` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/11773 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'LLVM :: CodeGen/SPIRV/opencl/reflect-error.ll' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: not /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null 2>&1 | /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll + not /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null + /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll RUN: at line 2: not /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null 2>&1 | /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll + /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll + not /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll -o /dev/null RUN: at line 3: not + not -- ``` https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
Icohedron wrote: > Will a follow-up issue be created to move the useful Sema helpers into a > common file? I just created issue #123831 for this. https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/farzonl approved this pull request. LGTM, but I want to see the `[[maybe_unused]]` and the `#include "llvm/Support/raw_ostream.h"` removed before you merge. https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -34,6 +34,7 @@ #include "llvm/IR/IntrinsicsSPIRV.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" Icohedron wrote: I don't recall adding that. I think my IDE did that for me :P I will remove it https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -3030,6 +3031,15 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register
ResVReg,
return selectExtInst(ResVReg, ResType, I, CL::fract, GL::Fract);
case Intrinsic::spv_normalize:
return selectExtInst(ResVReg, ResType, I, CL::normalize, GL::Normalize);
+ case Intrinsic::spv_reflect:
+if
(!STI.canUseExtInstSet(SPIRV::InstructionSet::InstructionSet::GLSL_std_450)) {
farzonl wrote:
Not a bad idea, but in another pr. so that the changes here are more focused to
the reflect feature. Feel free to file an issue and identify some tests to add.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -3030,6 +3039,8 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg, return selectExtInst(ResVReg, ResType, I, CL::fract, GL::Fract); case Intrinsic::spv_normalize: return selectExtInst(ResVReg, ResType, I, CL::normalize, GL::Normalize); + case Intrinsic::spv_reflect: +return selectExtInst(ResVReg, ResType, I, GL::Reflect); farzonl wrote: go to this line: https://github.com/llvm/llvm-project/blob/6518b121f037717fd211c36659f7b25266424719/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp#L273 and remove the `[[maybe_unused]]` https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -34,6 +34,7 @@ #include "llvm/IR/IntrinsicsSPIRV.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" farzonl wrote: Not sure why you need an include your changes to `selectExtInst` are the same string stream as the default intrinsic error reporting case: https://github.com/llvm/llvm-project/blob/6518b121f037717fd211c36659f7b25266424719/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp#L3124C5-L3128C48 https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,22 @@
+; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s
-o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s
-o /dev/null 2>&1 | FileCheck %s
+; RUN: not %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o
/dev/null 2>&1 -filetype=obj %}
+; RUN: not %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o
/dev/null 2>&1 -filetype=obj %}
+
+; CHECK: LLVM ERROR: Intrinsic selection not supported for this instruction
set: %{{.*}} = G_INTRINSIC intrinsic(@llvm.spv.reflect), %{{.*}}, %{{.*}}
Icohedron wrote:
I have changed the error message to read `LLVM ERROR: %{{.*}} = G_INTRINSIC
intrinsic(@llvm.spv.reflect), %{{.*}}, %{{.*}} is only supported with the GLSL
extended instruction set.`
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/Icohedron edited https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/Icohedron updated
https://github.com/llvm/llvm-project/pull/122992
>From f9fd109c4038f5646586c70c40bc298c20996d40 Mon Sep 17 00:00:00 2001
From: Icohedron
Date: Mon, 13 Jan 2025 21:23:31 +
Subject: [PATCH 1/2] Implement the `reflect` HLSL function
---
clang/include/clang/Basic/BuiltinsSPIRV.td| 6 +
clang/lib/CodeGen/CGBuiltin.cpp | 13 ++
clang/lib/Headers/hlsl/hlsl_detail.h | 16 ++
clang/lib/Headers/hlsl/hlsl_intrinsics.h | 43 +
clang/lib/Sema/SemaSPIRV.cpp | 32
clang/test/CodeGenHLSL/builtins/reflect.hlsl | 177 ++
clang/test/CodeGenSPIRV/Builtins/reflect.c| 32
.../SemaHLSL/BuiltIns/reflect-errors.hlsl | 33
.../test/SemaSPIRV/BuiltIns/reflect-errors.c | 23 +++
llvm/include/llvm/IR/IntrinsicsSPIRV.td | 1 +
.../Target/SPIRV/SPIRVInstructionSelector.cpp | 12 ++
.../CodeGen/SPIRV/hlsl-intrinsics/reflect.ll | 33
.../CodeGen/SPIRV/opencl/reflect-error.ll | 22 +++
13 files changed, 443 insertions(+)
create mode 100644 clang/test/CodeGenHLSL/builtins/reflect.hlsl
create mode 100644 clang/test/CodeGenSPIRV/Builtins/reflect.c
create mode 100644 clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl
create mode 100644 clang/test/SemaSPIRV/BuiltIns/reflect-errors.c
create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll
create mode 100644 llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll
diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td
b/clang/include/clang/Basic/BuiltinsSPIRV.td
index f72c555921dfe6..34933e889ba314 100644
--- a/clang/include/clang/Basic/BuiltinsSPIRV.td
+++ b/clang/include/clang/Basic/BuiltinsSPIRV.td
@@ -19,3 +19,9 @@ def SPIRVLength : Builtin {
let Attributes = [NoThrow, Const];
let Prototype = "void(...)";
}
+
+def SPIRVReflect : Builtin {
+ let Spellings = ["__builtin_spirv_reflect"];
+ let Attributes = [NoThrow, Const];
+ let Prototype = "void(...)";
+}
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index b80833fd91884d..ab61609ab35a99 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20538,6 +20538,19 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned
BuiltinID,
/*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_length,
ArrayRef{X}, nullptr, "spv.length");
}
+ case SPIRV::BI__builtin_spirv_reflect: {
+Value *I = EmitScalarExpr(E->getArg(0));
+Value *N = EmitScalarExpr(E->getArg(1));
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+ E->getArg(1)->getType()->hasFloatingRepresentation() &&
+ "Reflect operands must have a float representation");
+assert(E->getArg(0)->getType()->isVectorType() &&
+ E->getArg(1)->getType()->isVectorType() &&
+ "Reflect operands must be a vector");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/I->getType(), Intrinsic::spv_reflect,
+ArrayRef{I, N}, nullptr, "spv.reflect");
+ }
}
return nullptr;
}
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h
b/clang/lib/Headers/hlsl/hlsl_detail.h
index b2c8cc6c5c3dbb..0d568539cd66a8 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -79,6 +79,22 @@ constexpr enable_if_t::value ||
is_same::value, T>
distance_vec_impl(vector X, vector Y) {
return length_vec_impl(X - Y);
}
+
+template
+constexpr enable_if_t::value || is_same::value, T>
+reflect_impl(T I, T N) {
+ return I - 2 * N * I * N;
+}
+
+template
+constexpr vector reflect_vec_impl(vector I, vector N) {
+#if (__has_builtin(__builtin_spirv_reflect))
+ return __builtin_spirv_reflect(I, N);
+#else
+ return I - 2 * N * __builtin_hlsl_dot(I, N);
+#endif
+}
+
} // namespace __detail
} // namespace hlsl
#endif //_HLSL_HLSL_DETAILS_H_
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d1e4eb08aa7646..3b47074f07ecf4 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -2008,6 +2008,49 @@ double3 rcp(double3);
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
double4 rcp(double4);
+//===--===//
+// reflect builtin
+//===--===//
+
+/// \fn T reflect(T I, T N)
+/// \brief Returns a reflection using an incident ray, \a I, and a surface
+/// normal, \a N.
+/// \param I The incident ray.
+/// \param N The surface normal.
+///
+/// The return value is a floating-point vector that represents the reflection
+/// of the incident ray, \a I, off a surface with the normal \a N.
+///
+/// This function calculates the reflection vector using the following formula:
+/// V = I - 2 * N * dot(I N) .
+///
+/// N must already be normalized in order to achieve the desired result.
+///
+/// The operands must a
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -3030,6 +3031,15 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register
ResVReg,
return selectExtInst(ResVReg, ResType, I, CL::fract, GL::Fract);
case Intrinsic::spv_normalize:
return selectExtInst(ResVReg, ResType, I, CL::normalize, GL::Normalize);
+ case Intrinsic::spv_reflect:
+if
(!STI.canUseExtInstSet(SPIRV::InstructionSet::InstructionSet::GLSL_std_450)) {
Icohedron wrote:
Should I add a similar conditional to the OpenCL overloaded version of
selectExtInst? Just to keep the OpenCL and GLSL functions similar.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/farzonl edited https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,22 @@
+; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s
-o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s
-o /dev/null 2>&1 | FileCheck %s
+; RUN: not %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o
/dev/null 2>&1 -filetype=obj %}
+; RUN: not %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o
/dev/null 2>&1 -filetype=obj %}
+
+; CHECK: LLVM ERROR: Intrinsic selection not supported for this instruction
set: %{{.*}} = G_INTRINSIC intrinsic(@llvm.spv.reflect), %{{.*}}, %{{.*}}
+
+define noundef <4 x half> @reflect_half4(<4 x half> noundef %a, <4 x half>
noundef %b) {
+entry:
+ %spv.reflect = call <4 x half> @llvm.spv.reflect.f16(<4 x half> %a, <4 x
half> %b)
+ ret <4 x half> %spv.reflect
+}
+
+define noundef <4 x float> @reflect_float4(<4 x float> noundef %a, <4 x float>
noundef %b) {
+entry:
+ %spv.reflect = call <4 x float> @llvm.spv.reflect.f32(<4 x float> %a, <4 x
float> %b)
farzonl wrote:
This function will never be evaluated. The `report_fatal_error` means we stop
codegen after line 10. Please delete.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/farzonl edited https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,22 @@
+; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s
-o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s
-o /dev/null 2>&1 | FileCheck %s
+; RUN: not %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o
/dev/null 2>&1 -filetype=obj %}
+; RUN: not %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o
/dev/null 2>&1 -filetype=obj %}
+
+; CHECK: LLVM ERROR: Intrinsic selection not supported for this instruction
set: %{{.*}} = G_INTRINSIC intrinsic(@llvm.spv.reflect), %{{.*}}, %{{.*}}
farzonl wrote:
This is my bad now that I'm seeing it the lannguage is a bit obtuse and it
doesn't look like instruction is encoded. We should simplify this error message.
Maybe:
```suggestion
; CHECK: LLVM ERROR: %{{.*}} = G_INTRINSIC intrinsic(@llvm.spv.reflect), % is
only supported for GL instructions.
```
Or if you have something better go with that.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -3030,6 +3031,15 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register
ResVReg,
return selectExtInst(ResVReg, ResType, I, CL::fract, GL::Fract);
case Intrinsic::spv_normalize:
return selectExtInst(ResVReg, ResType, I, CL::normalize, GL::Normalize);
+ case Intrinsic::spv_reflect:
+if
(!STI.canUseExtInstSet(SPIRV::InstructionSet::InstructionSet::GLSL_std_450)) {
farzonl wrote:
I was hoping to put this conditional in the GL overloaded version of
selectExtInst so that other GL only extention instructions could benefit.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
github-actions[bot] wrote:
:warning: C/C++ code formatter, clang-format found issues in your code.
:warning:
You can test this locally with the following command:
``bash
git-clang-format --diff 22d4ff155aadf0f098dd5dc48d9038da15108937
782e1a28d4f8ddbeb92a9c57b3f071ba837ce129 --extensions h,cpp,c --
clang/test/CodeGenSPIRV/Builtins/reflect.c
clang/test/SemaSPIRV/BuiltIns/reflect-errors.c clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/hlsl/hlsl_detail.h clang/lib/Headers/hlsl/hlsl_intrinsics.h
clang/lib/Sema/SemaSPIRV.cpp llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
``
View the diff from clang-format here.
``diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 960c51e952..720494e45d 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -3032,11 +3032,13 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register
ResVReg,
case Intrinsic::spv_normalize:
return selectExtInst(ResVReg, ResType, I, CL::normalize, GL::Normalize);
case Intrinsic::spv_reflect:
-if
(!STI.canUseExtInstSet(SPIRV::InstructionSet::InstructionSet::GLSL_std_450)) {
+if (!STI.canUseExtInstSet(
+SPIRV::InstructionSet::InstructionSet::GLSL_std_450)) {
std::string DiagMsg;
raw_string_ostream OS(DiagMsg);
I.print(OS);
- DiagMsg = "Intrinsic selection not supported for this instruction set: "
+ DiagMsg;
+ DiagMsg = "Intrinsic selection not supported for this instruction set: "
+
+DiagMsg;
report_fatal_error(DiagMsg.c_str(), false);
}
return selectExtInst(ResVReg, ResType, I, GL::Reflect);
``
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/Icohedron updated
https://github.com/llvm/llvm-project/pull/122992
>From 7ddd5b264731ef375d99d012d9fbfd54c744e5b2 Mon Sep 17 00:00:00 2001
From: Icohedron
Date: Mon, 13 Jan 2025 21:23:31 +
Subject: [PATCH 1/5] Implement `reflect` HLSL function
---
clang/include/clang/Basic/BuiltinsSPIRV.td| 6 +
clang/lib/CodeGen/CGBuiltin.cpp | 13 ++
clang/lib/Headers/hlsl/hlsl_detail.h | 17 ++
clang/lib/Headers/hlsl/hlsl_intrinsics.h | 43
clang/lib/Sema/SemaSPIRV.cpp | 32 +++
clang/test/CodeGenHLSL/builtins/reflect.hlsl | 195 ++
clang/test/CodeGenSPIRV/Builtins/reflect.c| 32 +++
.../SemaHLSL/BuiltIns/reflect-errors.hlsl | 33 +++
.../test/SemaSPIRV/BuiltIns/reflect-errors.c | 23 +++
llvm/include/llvm/IR/IntrinsicsSPIRV.td | 1 +
.../Target/SPIRV/SPIRVInstructionSelector.cpp | 2 +
.../CodeGen/SPIRV/hlsl-intrinsics/reflect.ll | 33 +++
12 files changed, 430 insertions(+)
create mode 100644 clang/test/CodeGenHLSL/builtins/reflect.hlsl
create mode 100644 clang/test/CodeGenSPIRV/Builtins/reflect.c
create mode 100644 clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl
create mode 100644 clang/test/SemaSPIRV/BuiltIns/reflect-errors.c
create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll
diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td
b/clang/include/clang/Basic/BuiltinsSPIRV.td
index f72c555921dfe68..34933e889ba314b 100644
--- a/clang/include/clang/Basic/BuiltinsSPIRV.td
+++ b/clang/include/clang/Basic/BuiltinsSPIRV.td
@@ -19,3 +19,9 @@ def SPIRVLength : Builtin {
let Attributes = [NoThrow, Const];
let Prototype = "void(...)";
}
+
+def SPIRVReflect : Builtin {
+ let Spellings = ["__builtin_spirv_reflect"];
+ let Attributes = [NoThrow, Const];
+ let Prototype = "void(...)";
+}
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index b80833fd91884d8..ab61609ab35a99f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20538,6 +20538,19 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned
BuiltinID,
/*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_length,
ArrayRef{X}, nullptr, "spv.length");
}
+ case SPIRV::BI__builtin_spirv_reflect: {
+Value *I = EmitScalarExpr(E->getArg(0));
+Value *N = EmitScalarExpr(E->getArg(1));
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+ E->getArg(1)->getType()->hasFloatingRepresentation() &&
+ "Reflect operands must have a float representation");
+assert(E->getArg(0)->getType()->isVectorType() &&
+ E->getArg(1)->getType()->isVectorType() &&
+ "Reflect operands must be a vector");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/I->getType(), Intrinsic::spv_reflect,
+ArrayRef{I, N}, nullptr, "spv.reflect");
+ }
}
return nullptr;
}
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h
b/clang/lib/Headers/hlsl/hlsl_detail.h
index b2c8cc6c5c3dbb0..3e09f8b10735122 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -79,6 +79,23 @@ constexpr enable_if_t::value ||
is_same::value, T>
distance_vec_impl(vector X, vector Y) {
return length_vec_impl(X - Y);
}
+
+template
+constexpr enable_if_t::value || is_same::value, T>
+reflect_impl(T I, T N) {
+ return I - 2 * N * I * N;
+}
+
+template
+constexpr enable_if_t::value || is_same::value, T>
+reflect_vec_impl(vector I, vector N) {
+#if (__has_builtin(__builtin_spirv_reflect))
+ return __builtin_spirv_reflect(I, N);
+#else
+ return I - 2 * N * __builtin_hlsl_dot(I, N);
+#endif
+}
+
} // namespace __detail
} // namespace hlsl
#endif //_HLSL_HLSL_DETAILS_H_
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d1e4eb08aa7646a..54454cf0ea0d0bd 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -2008,6 +2008,49 @@ double3 rcp(double3);
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
double4 rcp(double4);
+//===--===//
+// reflect builtin
+//===--===//
+
+/// \fn T reflect(T I, T N)
+/// \brief Returns a reflection using an incident ray, \a I, and a surface
+/// normal, \a N.
+/// \param I The incident ray.
+/// \param N The surface normal.
+///
+/// The return value is a floating-point vector that represents the reflection
+/// of the incident ray, \a I, off a surface with the normal \a N.
+///
+/// This function calculates the reflection vector using the following formula:
+/// V = I - 2 * N * dot(I N) .
+///
+/// N must already be normalized in order to achieve the desired result.
+///
+/// The operands must all be a scalar or vector whose component type is
+/// floating-point.
+///
+/// Result type
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
farzonl wrote: > Will a follow-up issue be created to move the useful `Sema` helpers into a > common file? I'm fine if you want to do this as a follow up. https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
farzonl wrote: > This pr LGTM once the graceful exit comment is handled. > > With respect to [this > comment](https://github.com/llvm/llvm-project/pull/122992#discussion_r1917127000). > Is the final solution to just gracefully exit or is this an intermediate > step and an issue will be used to track an update using inst combine later? The graceful exit should be sufficient. We don't expose the clang builtin when targeting spirv32 or spirv64 and for now we are the only consumers of this intrinsic. Like I said in the last comment to only way to trigger this crash is with hand spun llvmir. To me making this not crash if you aren't in a supported environment is good enough. https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,32 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 + +// RUN: %clang_cc1 -O1 -triple spirv-pc-vulkan-compute %s -emit-llvm -o - | FileCheck %s farzonl wrote: The clang codgen tests should be sufficient. Thats one of the advantages of moving the intrinsics into the header. https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/inbelic approved this pull request. This pr LGTM once the graceful exit comment is handled. With respect to [this comment](https://github.com/llvm/llvm-project/pull/122992#discussion_r1917127000). Is the final solution to just gracefully exit or is this an intermediate step and an issue will be used to track an update using inst combine later? Will a follow-up issue be created to move the useful `Sema` helpers into a common file? https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,32 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 + +// RUN: %clang_cc1 -O1 -triple spirv-pc-vulkan-compute %s -emit-llvm -o - | FileCheck %s inbelic wrote: Do we also want to test a DirectX target? Or is the purpose of this test just to check we generate the intrinsic rather than expansion. https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/inbelic edited https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/farzonl edited https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -2944,6 +2944,10 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register
ResVReg,
return selectExtInst(ResVReg, ResType, I, CL::fract, GL::Fract);
case Intrinsic::spv_normalize:
return selectExtInst(ResVReg, ResType, I, CL::normalize, GL::Normalize);
+ case Intrinsic::spv_reflect:
+if (STI.isVulkanEnv()) // There is no CL equivalent of Reflect
farzonl wrote:
I don't think this if statement does what you think it does. As long as the
intrinsic remains in the MIR you won't be able to proceed with codegen.
instead if you want to gracefully exit you should modify the GLSL version of
`selectExtInst ` to do something like this
```cpp
if (!STI.canUseExtInstSet(SPIRV::InstructionSet::GLSL_std_450)) {
std::string DiagMsg;
raw_string_ostream OS(DiagMsg);
I.print(OS);
DiagMsg = "Intrinsic selection not supported for this instruction set: " +
DiagMsg;
report_fatal_error(DiagMsg.c_str(), false);
}
//original behavior of selectExtInst
```
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/farzonl edited https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/farzonl edited https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/Icohedron ready_for_review https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/Icohedron edited https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/Icohedron updated
https://github.com/llvm/llvm-project/pull/122992
>From 3f3b8c75c14bb9b3ed611c9cddec49d0e9339705 Mon Sep 17 00:00:00 2001
From: Icohedron
Date: Mon, 13 Jan 2025 21:23:31 +
Subject: [PATCH 1/4] Implement `reflect` HLSL function
---
clang/include/clang/Basic/BuiltinsSPIRV.td| 6 +
clang/lib/CodeGen/CGBuiltin.cpp | 13 ++
clang/lib/Headers/hlsl/hlsl_detail.h | 17 ++
clang/lib/Headers/hlsl/hlsl_intrinsics.h | 43
clang/lib/Sema/SemaSPIRV.cpp | 32 +++
clang/test/CodeGenHLSL/builtins/reflect.hlsl | 195 ++
clang/test/CodeGenSPIRV/Builtins/reflect.c| 32 +++
.../SemaHLSL/BuiltIns/reflect-errors.hlsl | 33 +++
.../test/SemaSPIRV/BuiltIns/reflect-errors.c | 23 +++
llvm/include/llvm/IR/IntrinsicsSPIRV.td | 1 +
.../Target/SPIRV/SPIRVInstructionSelector.cpp | 2 +
.../CodeGen/SPIRV/hlsl-intrinsics/reflect.ll | 33 +++
12 files changed, 430 insertions(+)
create mode 100644 clang/test/CodeGenHLSL/builtins/reflect.hlsl
create mode 100644 clang/test/CodeGenSPIRV/Builtins/reflect.c
create mode 100644 clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl
create mode 100644 clang/test/SemaSPIRV/BuiltIns/reflect-errors.c
create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll
diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td
b/clang/include/clang/Basic/BuiltinsSPIRV.td
index 1e66939b822ef8..ce00459fc8ede7 100644
--- a/clang/include/clang/Basic/BuiltinsSPIRV.td
+++ b/clang/include/clang/Basic/BuiltinsSPIRV.td
@@ -13,3 +13,9 @@ def SPIRVDistance : Builtin {
let Attributes = [NoThrow, Const];
let Prototype = "void(...)";
}
+
+def SPIRVReflect : Builtin {
+ let Spellings = ["__builtin_spirv_reflect"];
+ let Attributes = [NoThrow, Const];
+ let Prototype = "void(...)";
+}
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1b25d365932c30..b9e680685b05e0 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20487,6 +20487,19 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned
BuiltinID,
/*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_distance,
ArrayRef{X, Y}, nullptr, "spv.distance");
}
+ case SPIRV::BI__builtin_spirv_reflect: {
+Value *I = EmitScalarExpr(E->getArg(0));
+Value *N = EmitScalarExpr(E->getArg(1));
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+ E->getArg(1)->getType()->hasFloatingRepresentation() &&
+ "Reflect operands must have a float representation");
+assert(E->getArg(0)->getType()->isVectorType() &&
+ E->getArg(1)->getType()->isVectorType() &&
+ "Reflect operands must be a vector");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/I->getType(), Intrinsic::spv_reflect,
+ArrayRef{I, N}, nullptr, "spv.reflect");
+ }
}
return nullptr;
}
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 19d83ea5471c7c..624a7b05b56ad0 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -68,6 +68,23 @@ distance_vec_impl(vector X, vector Y) {
return length_vec_impl(X - Y);
#endif
}
+
+template
+constexpr enable_if_t::value || is_same::value, T>
+reflect_impl(T I, T N) {
+ return I - 2 * N * I * N;
+}
+
+template
+constexpr enable_if_t::value || is_same::value, T>
+reflect_vec_impl(vector I, vector N) {
+#if (__has_builtin(__builtin_spirv_reflect))
+ return __builtin_spirv_reflect(I, N);
+#else
+ return I - 2 * N * __builtin_hlsl_dot(I, N);
+#endif
+}
+
} // namespace __detail
} // namespace hlsl
#endif //_HLSL_HLSL_DETAILS_H_
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d2d3abd92ea6a8..484ae708342a59 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1919,6 +1919,49 @@ double3 rcp(double3);
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
double4 rcp(double4);
+//===--===//
+// reflect builtin
+//===--===//
+
+/// \fn T reflect(T I, T N)
+/// \brief Returns a reflection using an incident ray, \a I, and a surface
+/// normal, \a N.
+/// \param I The incident ray.
+/// \param N The surface normal.
+///
+/// The return value is a floating-point vector that represents the reflection
+/// of the incident ray, \a I, off a surface with the normal \a N.
+///
+/// This function calculates the reflection vector using the following formula:
+/// V = I - 2 * N * dot(I N) .
+///
+/// N must already be normalized in order to achieve the desired result.
+///
+/// The operands must all be a scalar or vector whose component type is
+/// floating-point.
+///
+/// Result type and the type of all operands must be the sam
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/Icohedron updated
https://github.com/llvm/llvm-project/pull/122992
>From 3f3b8c75c14bb9b3ed611c9cddec49d0e9339705 Mon Sep 17 00:00:00 2001
From: Icohedron
Date: Mon, 13 Jan 2025 21:23:31 +
Subject: [PATCH 1/3] Implement `reflect` HLSL function
---
clang/include/clang/Basic/BuiltinsSPIRV.td| 6 +
clang/lib/CodeGen/CGBuiltin.cpp | 13 ++
clang/lib/Headers/hlsl/hlsl_detail.h | 17 ++
clang/lib/Headers/hlsl/hlsl_intrinsics.h | 43
clang/lib/Sema/SemaSPIRV.cpp | 32 +++
clang/test/CodeGenHLSL/builtins/reflect.hlsl | 195 ++
clang/test/CodeGenSPIRV/Builtins/reflect.c| 32 +++
.../SemaHLSL/BuiltIns/reflect-errors.hlsl | 33 +++
.../test/SemaSPIRV/BuiltIns/reflect-errors.c | 23 +++
llvm/include/llvm/IR/IntrinsicsSPIRV.td | 1 +
.../Target/SPIRV/SPIRVInstructionSelector.cpp | 2 +
.../CodeGen/SPIRV/hlsl-intrinsics/reflect.ll | 33 +++
12 files changed, 430 insertions(+)
create mode 100644 clang/test/CodeGenHLSL/builtins/reflect.hlsl
create mode 100644 clang/test/CodeGenSPIRV/Builtins/reflect.c
create mode 100644 clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl
create mode 100644 clang/test/SemaSPIRV/BuiltIns/reflect-errors.c
create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll
diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td
b/clang/include/clang/Basic/BuiltinsSPIRV.td
index 1e66939b822ef8..ce00459fc8ede7 100644
--- a/clang/include/clang/Basic/BuiltinsSPIRV.td
+++ b/clang/include/clang/Basic/BuiltinsSPIRV.td
@@ -13,3 +13,9 @@ def SPIRVDistance : Builtin {
let Attributes = [NoThrow, Const];
let Prototype = "void(...)";
}
+
+def SPIRVReflect : Builtin {
+ let Spellings = ["__builtin_spirv_reflect"];
+ let Attributes = [NoThrow, Const];
+ let Prototype = "void(...)";
+}
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1b25d365932c30..b9e680685b05e0 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20487,6 +20487,19 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned
BuiltinID,
/*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_distance,
ArrayRef{X, Y}, nullptr, "spv.distance");
}
+ case SPIRV::BI__builtin_spirv_reflect: {
+Value *I = EmitScalarExpr(E->getArg(0));
+Value *N = EmitScalarExpr(E->getArg(1));
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+ E->getArg(1)->getType()->hasFloatingRepresentation() &&
+ "Reflect operands must have a float representation");
+assert(E->getArg(0)->getType()->isVectorType() &&
+ E->getArg(1)->getType()->isVectorType() &&
+ "Reflect operands must be a vector");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/I->getType(), Intrinsic::spv_reflect,
+ArrayRef{I, N}, nullptr, "spv.reflect");
+ }
}
return nullptr;
}
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 19d83ea5471c7c..624a7b05b56ad0 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -68,6 +68,23 @@ distance_vec_impl(vector X, vector Y) {
return length_vec_impl(X - Y);
#endif
}
+
+template
+constexpr enable_if_t::value || is_same::value, T>
+reflect_impl(T I, T N) {
+ return I - 2 * N * I * N;
+}
+
+template
+constexpr enable_if_t::value || is_same::value, T>
+reflect_vec_impl(vector I, vector N) {
+#if (__has_builtin(__builtin_spirv_reflect))
+ return __builtin_spirv_reflect(I, N);
+#else
+ return I - 2 * N * __builtin_hlsl_dot(I, N);
+#endif
+}
+
} // namespace __detail
} // namespace hlsl
#endif //_HLSL_HLSL_DETAILS_H_
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d2d3abd92ea6a8..484ae708342a59 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1919,6 +1919,49 @@ double3 rcp(double3);
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
double4 rcp(double4);
+//===--===//
+// reflect builtin
+//===--===//
+
+/// \fn T reflect(T I, T N)
+/// \brief Returns a reflection using an incident ray, \a I, and a surface
+/// normal, \a N.
+/// \param I The incident ray.
+/// \param N The surface normal.
+///
+/// The return value is a floating-point vector that represents the reflection
+/// of the incident ray, \a I, off a surface with the normal \a N.
+///
+/// This function calculates the reflection vector using the following formula:
+/// V = I - 2 * N * dot(I N) .
+///
+/// N must already be normalized in order to achieve the desired result.
+///
+/// The operands must all be a scalar or vector whose component type is
+/// floating-point.
+///
+/// Result type and the type of all operands must be the sam
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -51,6 +51,38 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(unsigned
BuiltinID,
TheCall->setType(RetTy);
break;
}
+ case SPIRV::BI__builtin_spirv_reflect: {
+if (SemaRef.checkArgCount(TheCall, 2))
+ return true;
+
+ExprResult A = TheCall->getArg(0);
+QualType ArgTyA = A.get()->getType();
+auto *VTyA = ArgTyA->getAs();
inbelic wrote:
Ah yes, they are in `SemaHLSL.cpp`. I would assume the entire
`CheckArgTypeIsCorrect` and `CheckAllArgTypesAreCorrect` functions + helpers
would be helpful here as well.
These diagnostics could be implemented using that. So I do think it would be
worthwhile making those common.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/farzonl edited https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/farzonl edited https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/farzonl edited https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,33 @@ +; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s farzonl wrote: This won't be a problem for opencl because they don't have a reflect api to trigger this crash. This could be a problem if folks try to target spirv32/spirv64 via c because we just exposed a clang builtin. Since we just enabled this and are so far the only users of the spirv target builtins i'm not to worried about this. That said there are a few ways we could address this. 1. remove the reflect spirv target builtin and wait for this pr to merge: https://github.com/llvm/llvm-project/pull/122839/files then add an instcombine pattern for `I - 2 * N * dot(I, N);` to map to reflect. 2. ignore this case 3. lower the intrinsic back to `I - 2 * N * dot(I, N);` if its not targeting GLSL. (This is my least favorite option). https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -51,6 +51,38 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(unsigned
BuiltinID,
TheCall->setType(RetTy);
break;
}
+ case SPIRV::BI__builtin_spirv_reflect: {
+if (SemaRef.checkArgCount(TheCall, 2))
+ return true;
+
+ExprResult A = TheCall->getArg(0);
+QualType ArgTyA = A.get()->getType();
+auto *VTyA = ArgTyA->getAs();
farzonl wrote:
I think the helpers you are thinking about might be in SemaHLSL.cpp.
SemaSPIRV.cpp is very barebones. If you think there is a helper that could be
used across both files, we probably want to move it to a more generic place.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,195 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s --check-prefix=SPVCHECK
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// CHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// CHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// CHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// CHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// CHECK-NEXT:ret half [[SUB_I]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// SPVCHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// SPVCHECK-NEXT: [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// SPVCHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// SPVCHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// SPVCHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// SPVCHECK-NEXT:ret half [[SUB_I]]
+//
+half test_reflect_half(half I, half N) {
+return reflect(I, N);
+}
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <2 x half>
@_Z18test_reflect_half2Dv2_DhS_(
+// CHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[I:%.*]], <2 x half>
noundef nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp
afn half @llvm.dx.fdot.v2f16(<2 x half> [[I]], <2 x half> [[N]])
+// CHECK-NEXT:[[TMP0:%.*]] = extractelement <2 x half> [[I]], i64 0
+// CHECK-NEXT:[[TMP1:%.*]] = extractelement <2 x half> [[N]], i64 0
+// CHECK-NEXT:[[TMP2:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP1]], 0xH4000
farzonl wrote:
I'm expecting the codegen to look like this
```llvmir
%N.i0 = extractelement <2 x half> %N, i32 0
%.i01 = fmul fast half 2.00e+00, %N.i0
%N.i1 = extractelement <2 x half> %N, i32 1
%.i12 = fmul fast half 2.00e+00, %N.i1
%D= half @llvm.dx.fdot.v2f16(<2 x half> %I, <2 x half> %N)
%.i03 = fmul fast half %.i01, %D
%.i04 = fmul fast half %.i12, %D
%Dv = shufflevector <2 x half> %i03 <2 x half> %i04
%.i05 = fsub fast <2 x half> %I, %.Dv
```
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,33 @@ +; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s Icohedron wrote: Changing the triple to `-mtriple=spirv32-unknown-unknown` does indeed cause the test to fail at instruction selection ``` FAIL: LLVM :: CodeGen/SPIRV/hlsl-intrinsics/reflect.ll (282 of 582) TEST 'LLVM :: CodeGen/SPIRV/hlsl-intrinsics/reflect.ll' FAILED Exit Code: 2 Command Output (stderr): -- RUN: at line 1: /workspace/feature-reflect/build/bin/llc -O0 -mtriple=spirv32-unknown-unknown /workspace/feature-reflect/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll -o - | /workspace/feature-reflect/build/bin/FileCheck /workspace/feature-reflect/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll + /workspace/feature-reflect/build/bin/FileCheck /workspace/feature-reflect/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll + /workspace/feature-reflect/build/bin/llc -O0 -mtriple=spirv32-unknown-unknown /workspace/feature-reflect/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll -o - LLVM ERROR: cannot select: %6:id(<2 x s64>) = G_INTRINSIC intrinsic(@llvm.spv.reflect), %0:vfid(<2 x s64>), %1:vfid(<2 x s64>) (in function: reflect_half4) PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /workspace/feature-reflect/build/bin/llc -O0 -mtriple=spirv32-unknown-unknown /workspace/feature-reflect/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll -o - 1. Running pass 'Function Pass Manager' on module '/workspace/feature-reflect/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll'. 2. Running pass 'InstructionSelect' on function '@reflect_half4' #0 0x5a7a8f13318f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /workspace/feature-reflect/llvm/lib/Support/Unix/Signals.inc:804:3 #1 0x5a7a8f130a5f llvm::sys::RunSignalHandlers() /workspace/feature-reflect/llvm/lib/Support/Signals.cpp:105:20 #2 0x5a7a8f130db6 SignalHandler(int) /workspace/feature-reflect/llvm/lib/Support/Unix/Signals.inc:417:1 #3 0x71ee82242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x71ee822969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #5 0x71ee82242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #6 0x71ee822287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #7 0x5a7a8f08b463 (/workspace/feature-reflect/build/bin/llc+0x3631463) #8 0x5a7a8f664b32 reportGISelDiagnostic(llvm::DiagnosticSeverity, llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, llvm::MachineOptimizationRemarkMissed&) /workspace/feature-reflect/llvm/lib/CodeGen/GlobalISel/Utils.cpp:248:23 #9 0x5a7a8f666a55 llvm::DiagnosticInfoOptimizationBase::~DiagnosticInfoOptimizationBase() /workspace/feature-reflect/llvm/include/llvm/IR/DiagnosticInfo.h:486:7 #10 0x5a7a8f666a55 llvm::DiagnosticInfoMIROptimization::~DiagnosticInfoMIROptimization() /workspace/feature-reflect/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h:31:7 #11 0x5a7a8f666a55 llvm::MachineOptimizationRemarkMissed::~MachineOptimizationRemarkMissed() /workspace/feature-reflect/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h:85:7 #12 0x5a7a8f666a55 llvm::reportGISelFailure(llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, char const*, llvm::StringRef, llvm::MachineInstr const&) /workspace/feature-reflect/llvm/lib/CodeGen/GlobalISel/Utils.cpp:277:1 #13 0x5a7a8f5ce077 llvm::SmallVectorTemplateCommon, void>::begin() /workspace/feature-reflect/llvm/include/llvm/ADT/SmallVector.h:267:45 #14 0x5a7a8f5ce077 llvm::SmallVectorTemplateCommon, void>::end() /workspace/feature-reflect/llvm/include/llvm/ADT/SmallVector.h:269:32 #15 0x5a7a8f5ce077 llvm::SmallVector, 8u>::~SmallVector() /workspace/feature-reflect/llvm/include/llvm/ADT/SmallVector.h:1202:24 #16 0x5a7a8f5ce077 llvm::po_iterator, false, llvm::GraphTraits>::~po_iterator() /workspace/feature-reflect/llvm/include/llvm/ADT/PostOrderIterator.h:97:7 #17 0x5a7a8f5ce077 llvm::InstructionSelect::selectMachineFunction(llvm::MachineFunction&) /workspace/feature-reflect/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp:225:5 #18 0x5a7a8f5cf70c operator() /workspace/feature-reflect/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp:145:59 #19 0x5a7a8f5cf70c ~scope_exit /workspace/feature-reflect/llvm/include/llvm/ADT/ScopeExit.h:46:19 #20 0x5a7a8f5cf70c llvm::InstructionSelect::runOnMachineFunction(llvm::MachineFunction&) /workspace/feature-reflect/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp:157:1 #21 0x5a7a8f5cf70c llvm::InstructionSelect::runOnMachineFunction(llvm::MachineFunction&) /workspace/feature-reflect/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp:134:6 #22 0x5a7a8dfbf72a llvm::MachineFunction
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -finclude-default-header -triple
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only
-disable-llvm-passes -verify
+
+float test_no_second_arg(float2 p0) {
+ return reflect(p0);
+ // expected-error@-1 {{no matching function for call to 'reflect'}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable:
requires 2 arguments, but 1 was provided}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable:
requires 2 arguments, but 1 was provided}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not
viable: requires 2 arguments, but 1 was provided}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not
viable: requires 2 arguments, but 1 was provided}}
+}
+
+float test_too_many_arg(float2 p0) {
+ return reflect(p0, p0, p0);
+ // expected-error@-1 {{no matching function for call to 'reflect'}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable:
requires 2 arguments, but 3 were provided}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable:
requires 2 arguments, but 3 were provided}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not
viable: requires 2 arguments, but 3 were provided}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not
viable: requires 2 arguments, but 3 were provided}}
+}
+
+float test_double_inputs(double p0, double p1) {
+ return reflect(p0, p1);
+ // expected-error@-1 {{call to 'reflect' is ambiguous}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
+}
+
+float test_int_inputs(int p0, int p1) {
+ return reflect(p0, p1);
+ // expected-error@-1 {{call to 'reflect' is ambiguous}}
farzonl wrote:
This is correct. see `ScalarOverloadResolution.hlsl` When there are more than
one overload we get ambiguous. and when there is just one implementation, we
get expected warning.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -51,6 +51,38 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(unsigned
BuiltinID,
TheCall->setType(RetTy);
break;
}
+ case SPIRV::BI__builtin_spirv_reflect: {
+if (SemaRef.checkArgCount(TheCall, 2))
+ return true;
+
+ExprResult A = TheCall->getArg(0);
+QualType ArgTyA = A.get()->getType();
+auto *VTyA = ArgTyA->getAs();
inbelic wrote:
If you look through this file, there should be a helper function that will
check what you are checking here
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -finclude-default-header -triple
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only
-disable-llvm-passes -verify
+
+float test_no_second_arg(float2 p0) {
+ return reflect(p0);
+ // expected-error@-1 {{no matching function for call to 'reflect'}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable:
requires 2 arguments, but 1 was provided}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable:
requires 2 arguments, but 1 was provided}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not
viable: requires 2 arguments, but 1 was provided}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not
viable: requires 2 arguments, but 1 was provided}}
+}
+
+float test_too_many_arg(float2 p0) {
+ return reflect(p0, p0, p0);
+ // expected-error@-1 {{no matching function for call to 'reflect'}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable:
requires 2 arguments, but 3 were provided}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable:
requires 2 arguments, but 3 were provided}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not
viable: requires 2 arguments, but 3 were provided}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not
viable: requires 2 arguments, but 3 were provided}}
+}
+
+float test_double_inputs(double p0, double p1) {
+ return reflect(p0, p1);
+ // expected-error@-1 {{call to 'reflect' is ambiguous}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
+}
+
+float test_int_inputs(int p0, int p1) {
+ return reflect(p0, p1);
+ // expected-error@-1 {{call to 'reflect' is ambiguous}}
inbelic wrote:
I am not sure I understand why this is the expected error message. Is it
because it could cast to a float or half? That doesn't seem right
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,33 @@ +; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s inbelic wrote: Out of curiousity, what happens when we use the triple `-mtriple=spirv32-unknown-unknown`? This should change the environment to be `OpenCL`, will it fail because there isn't a CL equivalent? https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -51,6 +51,38 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(unsigned
BuiltinID,
TheCall->setType(RetTy);
break;
}
+ case SPIRV::BI__builtin_spirv_reflect: {
+if (SemaRef.checkArgCount(TheCall, 2))
+ return true;
+
+ExprResult A = TheCall->getArg(0);
+QualType ArgTyA = A.get()->getType();
+auto *VTyA = ArgTyA->getAs();
+if (VTyA == nullptr) {
+ SemaRef.Diag(A.get()->getBeginLoc(),
+ diag::err_typecheck_convert_incompatible)
+ << ArgTyA
+ << SemaRef.Context.getVectorType(ArgTyA, 2, VectorKind::Generic) << 1
+ << 0 << 0;
+ return true;
+}
+
+ExprResult B = TheCall->getArg(1);
+QualType ArgTyB = B.get()->getType();
+auto *VTyB = ArgTyB->getAs();
+if (VTyB == nullptr) {
+ SemaRef.Diag(A.get()->getBeginLoc(),
+ diag::err_typecheck_convert_incompatible)
+ << ArgTyB
+ << SemaRef.Context.getVectorType(ArgTyB, 2, VectorKind::Generic) << 1
+ << 0 << 0;
+ return true;
+}
+
+QualType RetTy = ArgTyA;
+TheCall->setType(RetTy);
inbelic wrote:
FYI: this is the reason that it will fail to compile without having the
diagnostics. Since the intrinsic types are being overloaded, you have to set it
specifically here.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,195 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s --check-prefix=SPVCHECK
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// CHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// CHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// CHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// CHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// CHECK-NEXT:ret half [[SUB_I]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// SPVCHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// SPVCHECK-NEXT: [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// SPVCHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// SPVCHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// SPVCHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// SPVCHECK-NEXT:ret half [[SUB_I]]
+//
+half test_reflect_half(half I, half N) {
+return reflect(I, N);
+}
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <2 x half>
@_Z18test_reflect_half2Dv2_DhS_(
+// CHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[I:%.*]], <2 x half>
noundef nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp
afn half @llvm.dx.fdot.v2f16(<2 x half> [[I]], <2 x half> [[N]])
+// CHECK-NEXT:[[TMP0:%.*]] = extractelement <2 x half> [[I]], i64 0
+// CHECK-NEXT:[[TMP1:%.*]] = extractelement <2 x half> [[N]], i64 0
+// CHECK-NEXT:[[TMP2:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP1]], 0xH4000
Icohedron wrote:
It seems like all the math operations except for the dot product are being
performed on only the first elements of each input vector.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,195 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s --check-prefix=SPVCHECK
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// CHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// CHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// CHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// CHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// CHECK-NEXT:ret half [[SUB_I]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// SPVCHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// SPVCHECK-NEXT: [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// SPVCHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// SPVCHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// SPVCHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// SPVCHECK-NEXT:ret half [[SUB_I]]
+//
+half test_reflect_half(half I, half N) {
+return reflect(I, N);
+}
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <2 x half>
@_Z18test_reflect_half2Dv2_DhS_(
+// CHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[I:%.*]], <2 x half>
noundef nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp
afn half @llvm.dx.fdot.v2f16(<2 x half> [[I]], <2 x half> [[N]])
+// CHECK-NEXT:[[TMP0:%.*]] = extractelement <2 x half> [[I]], i64 0
+// CHECK-NEXT:[[TMP1:%.*]] = extractelement <2 x half> [[N]], i64 0
+// CHECK-NEXT:[[TMP2:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP1]], 0xH4000
Icohedron wrote:
Yea that's another issue I spotted and am troubleshooting right now
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,195 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s --check-prefix=SPVCHECK
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// CHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// CHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// CHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// CHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// CHECK-NEXT:ret half [[SUB_I]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// SPVCHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// SPVCHECK-NEXT: [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// SPVCHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// SPVCHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// SPVCHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// SPVCHECK-NEXT:ret half [[SUB_I]]
+//
+half test_reflect_half(half I, half N) {
+return reflect(I, N);
+}
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <2 x half>
@_Z18test_reflect_half2Dv2_DhS_(
+// CHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[I:%.*]], <2 x half>
noundef nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp
afn half @llvm.dx.fdot.v2f16(<2 x half> [[I]], <2 x half> [[N]])
+// CHECK-NEXT:[[TMP0:%.*]] = extractelement <2 x half> [[I]], i64 0
+// CHECK-NEXT:[[TMP1:%.*]] = extractelement <2 x half> [[N]], i64 0
+// CHECK-NEXT:[[TMP2:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP1]], 0xH4000
farzonl wrote:
I'm a little confused here. It looks like we are only multiplying 2 by the
first element of `N`. I would have expected `2 *N` to be multiplied against
both elements.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,195 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s --check-prefix=SPVCHECK
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// CHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// CHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// CHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// CHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// CHECK-NEXT:ret half [[SUB_I]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// SPVCHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// SPVCHECK-NEXT: [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// SPVCHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// SPVCHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// SPVCHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// SPVCHECK-NEXT:ret half [[SUB_I]]
+//
+half test_reflect_half(half I, half N) {
+return reflect(I, N);
+}
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <2 x half>
@_Z18test_reflect_half2Dv2_DhS_(
+// CHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[I:%.*]], <2 x half>
noundef nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp
afn half @llvm.dx.fdot.v2f16(<2 x half> [[I]], <2 x half> [[N]])
+// CHECK-NEXT:[[TMP0:%.*]] = extractelement <2 x half> [[I]], i64 0
+// CHECK-NEXT:[[TMP1:%.*]] = extractelement <2 x half> [[N]], i64 0
+// CHECK-NEXT:[[TMP2:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP1]], 0xH4000
+// CHECK-NEXT:[[TMP3:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP2]], [[HLSL_DOT_I]]
+// CHECK-NEXT:[[CAST_VTRUNC_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn
half [[TMP0]], [[TMP3]]
+// CHECK-NEXT:[[SPLAT_SPLATINSERT:%.*]] = insertelement <2 x half> poison,
half [[CAST_VTRUNC_I]], i64 0
+// CHECK-NEXT:[[SPLAT_SPLAT:%.*]] = shufflevector <2 x half>
[[SPLAT_SPLATINSERT]], <2 x half> poison, <2 x i32> zeroinitializer
+// CHECK-NEXT:ret <2 x half> [[SPLAT_SPLAT]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) <2 x half>
@_Z18test_reflect_half2Dv2_DhS_(
+// SPVCHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[I:%.*]], <2 x half>
noundef nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// SPVCHECK-NEXT: [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[SPV_REFLECT_I:%.*]] = tail call reassoc nnan ninf nsz
arcp afn <2 x half> @llvm.spv.reflect.v2f16(<2 x half> [[I]], <2 x half> [[N]])
+// SPVCHECK-NEXT:[[SPLAT_SPLAT:%.*]] = shufflevector <2 x half>
[[SPV_REFLECT_I]], <2 x half> poison, <2 x i32> zeroinitializer
farzonl wrote:
Oh and the SPLAT makes sense for the CHECK case because dot product is a
scalar. It just doesn't make sense when calling the reflect SPIRV, clang
builtin.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,195 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s --check-prefix=SPVCHECK
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// CHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// CHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// CHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// CHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// CHECK-NEXT:ret half [[SUB_I]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// SPVCHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// SPVCHECK-NEXT: [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// SPVCHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// SPVCHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// SPVCHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// SPVCHECK-NEXT:ret half [[SUB_I]]
+//
+half test_reflect_half(half I, half N) {
+return reflect(I, N);
+}
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <2 x half>
@_Z18test_reflect_half2Dv2_DhS_(
+// CHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[I:%.*]], <2 x half>
noundef nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp
afn half @llvm.dx.fdot.v2f16(<2 x half> [[I]], <2 x half> [[N]])
+// CHECK-NEXT:[[TMP0:%.*]] = extractelement <2 x half> [[I]], i64 0
+// CHECK-NEXT:[[TMP1:%.*]] = extractelement <2 x half> [[N]], i64 0
+// CHECK-NEXT:[[TMP2:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP1]], 0xH4000
+// CHECK-NEXT:[[TMP3:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP2]], [[HLSL_DOT_I]]
+// CHECK-NEXT:[[CAST_VTRUNC_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn
half [[TMP0]], [[TMP3]]
+// CHECK-NEXT:[[SPLAT_SPLATINSERT:%.*]] = insertelement <2 x half> poison,
half [[CAST_VTRUNC_I]], i64 0
+// CHECK-NEXT:[[SPLAT_SPLAT:%.*]] = shufflevector <2 x half>
[[SPLAT_SPLATINSERT]], <2 x half> poison, <2 x i32> zeroinitializer
+// CHECK-NEXT:ret <2 x half> [[SPLAT_SPLAT]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) <2 x half>
@_Z18test_reflect_half2Dv2_DhS_(
+// SPVCHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[I:%.*]], <2 x half>
noundef nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// SPVCHECK-NEXT: [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[SPV_REFLECT_I:%.*]] = tail call reassoc nnan ninf nsz
arcp afn <2 x half> @llvm.spv.reflect.v2f16(<2 x half> [[I]], <2 x half> [[N]])
+// SPVCHECK-NEXT:[[SPLAT_SPLAT:%.*]] = shufflevector <2 x half>
[[SPV_REFLECT_I]], <2 x half> poison, <2 x i32> zeroinitializer
farzonl wrote:
I don't see any vector splats in `clang/test/CodeGenSPIRV/Builtins/reflect.c`
but I do in the CHECK and SPVCHECKs of this file so your issue seems specific
to `hlsl_detail.h`
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,195 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s --check-prefix=SPVCHECK
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// CHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// CHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// CHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// CHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// CHECK-NEXT:ret half [[SUB_I]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// SPVCHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// SPVCHECK-NEXT: [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// SPVCHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// SPVCHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// SPVCHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// SPVCHECK-NEXT:ret half [[SUB_I]]
+//
+half test_reflect_half(half I, half N) {
+return reflect(I, N);
+}
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <2 x half>
@_Z18test_reflect_half2Dv2_DhS_(
+// CHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[I:%.*]], <2 x half>
noundef nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp
afn half @llvm.dx.fdot.v2f16(<2 x half> [[I]], <2 x half> [[N]])
+// CHECK-NEXT:[[TMP0:%.*]] = extractelement <2 x half> [[I]], i64 0
+// CHECK-NEXT:[[TMP1:%.*]] = extractelement <2 x half> [[N]], i64 0
+// CHECK-NEXT:[[TMP2:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP1]], 0xH4000
+// CHECK-NEXT:[[TMP3:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP2]], [[HLSL_DOT_I]]
+// CHECK-NEXT:[[CAST_VTRUNC_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn
half [[TMP0]], [[TMP3]]
+// CHECK-NEXT:[[SPLAT_SPLATINSERT:%.*]] = insertelement <2 x half> poison,
half [[CAST_VTRUNC_I]], i64 0
+// CHECK-NEXT:[[SPLAT_SPLAT:%.*]] = shufflevector <2 x half>
[[SPLAT_SPLATINSERT]], <2 x half> poison, <2 x i32> zeroinitializer
+// CHECK-NEXT:ret <2 x half> [[SPLAT_SPLAT]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) <2 x half>
@_Z18test_reflect_half2Dv2_DhS_(
+// SPVCHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[I:%.*]], <2 x half>
noundef nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// SPVCHECK-NEXT: [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[SPV_REFLECT_I:%.*]] = tail call reassoc nnan ninf nsz
arcp afn <2 x half> @llvm.spv.reflect.v2f16(<2 x half> [[I]], <2 x half> [[N]])
+// SPVCHECK-NEXT:[[SPLAT_SPLAT:%.*]] = shufflevector <2 x half>
[[SPV_REFLECT_I]], <2 x half> poison, <2 x i32> zeroinitializer
Icohedron wrote:
I am unsure where the vector splat is coming from.
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/Icohedron converted_to_draft https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
@@ -0,0 +1,195 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \
+// RUN: -emit-llvm -O1 -o - | FileCheck %s --check-prefix=SPVCHECK
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// CHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// CHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// CHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// CHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// CHECK-NEXT:ret half [[SUB_I]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half
@_Z17test_reflect_halfDhDh(
+// SPVCHECK-SAME: half noundef nofpclass(nan inf) [[I:%.*]], half noundef
nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// SPVCHECK-NEXT: [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[I]], 0xH4000
+// SPVCHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[N]], [[N]]
+// SPVCHECK-NEXT:[[MUL2_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP0]], [[MUL_I]]
+// SPVCHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half
[[I]], [[MUL2_I]]
+// SPVCHECK-NEXT:ret half [[SUB_I]]
+//
+half test_reflect_half(half I, half N) {
+return reflect(I, N);
+}
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <2 x half>
@_Z18test_reflect_half2Dv2_DhS_(
+// CHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[I:%.*]], <2 x half>
noundef nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT:[[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp
afn half @llvm.dx.fdot.v2f16(<2 x half> [[I]], <2 x half> [[N]])
+// CHECK-NEXT:[[TMP0:%.*]] = extractelement <2 x half> [[I]], i64 0
+// CHECK-NEXT:[[TMP1:%.*]] = extractelement <2 x half> [[N]], i64 0
+// CHECK-NEXT:[[TMP2:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP1]], 0xH4000
+// CHECK-NEXT:[[TMP3:%.*]] = fmul reassoc nnan ninf nsz arcp afn half
[[TMP2]], [[HLSL_DOT_I]]
+// CHECK-NEXT:[[CAST_VTRUNC_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn
half [[TMP0]], [[TMP3]]
+// CHECK-NEXT:[[SPLAT_SPLATINSERT:%.*]] = insertelement <2 x half> poison,
half [[CAST_VTRUNC_I]], i64 0
+// CHECK-NEXT:[[SPLAT_SPLAT:%.*]] = shufflevector <2 x half>
[[SPLAT_SPLATINSERT]], <2 x half> poison, <2 x i32> zeroinitializer
+// CHECK-NEXT:ret <2 x half> [[SPLAT_SPLAT]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) <2 x half>
@_Z18test_reflect_half2Dv2_DhS_(
+// SPVCHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[I:%.*]], <2 x half>
noundef nofpclass(nan inf) [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// SPVCHECK-NEXT: [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[SPV_REFLECT_I:%.*]] = tail call reassoc nnan ninf nsz
arcp afn <2 x half> @llvm.spv.reflect.v2f16(<2 x half> [[I]], <2 x half> [[N]])
+// SPVCHECK-NEXT:[[SPLAT_SPLAT:%.*]] = shufflevector <2 x half>
[[SPV_REFLECT_I]], <2 x half> poison, <2 x i32> zeroinitializer
farzonl wrote:
Why are we returning a vector splat?
https://github.com/llvm/llvm-project/pull/122992
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)
https://github.com/Icohedron edited https://github.com/llvm/llvm-project/pull/122992 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
