[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

Romaric Jodin via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 14 07:09:01 PDT 2024


================
@@ -307,8 +320,8 @@ def generate_saturated_conversion(src, dst, size):
         # Conversion from float to int
         print(
             """  {DST}{N} y = convert_{DST}{N}(x);
-  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
-  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
+  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS});
+  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= ({SRC}{N}){DST_MAX}){BS});
----------------
rjodinchr wrote:

Yes this change was intended.
It is not a standalone bugfix as for all C platforms, this should be the same. But with Vulkan SPIR-V it leads to issues with zeros, infs & nans, where comparisons are unspecified (if I remember correctly).
I understand that changing the default path might get a bit more dangerous there, so I have added a if statement for it as well.

https://github.com/llvm/llvm-project/pull/66902


More information about the cfe-commits mailing list