[libclc] [libclc] Reduce bithacking for INF/NAN values (PR #129738)

Fraser Cormack via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 5 03:35:07 PST 2025


================
@@ -86,13 +84,10 @@ _CLC_DEF _CLC_OVERLOAD __CLC_GENTYPE __clc_hypot(__CLC_GENTYPE x,
   r = c ? s : r;
 
   // Check for NaN
-  c = __clc_isnan(x) || __clc_isnan(y);
-  r = c ? __CLC_AS_GENTYPE((__CLC_ULONGN)QNANBITPATT_DP64) : r;
+  r = __clc_isnan(x) || __clc_isnan(y) ? __CLC_GENTYPE_NAN : r;
----------------
frasercrmck wrote:

> Doesn't matter much, but can fold this condition into one __builtin_isunordered (or just let instcombine do it)

Yeah I think I'll just let instcombine do it (which it does).

> Above should also be rewritten with frexp and ldexp

Sorry, I'm not seeing which bit - could you explain? I note that libclc's frexp and ldexp are more involved than any of the bithacking here (possibly due to subnormal support?) so I'm not sure what the goal would be.

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


More information about the cfe-commits mailing list