Author: Matt Arsenault
Date: 2026-03-12T11:52:51+01:00
New Revision: 85e542fff3c521ede90d6e30c8f4c725f5d36fb6

URL: 
https://github.com/llvm/llvm-project/commit/85e542fff3c521ede90d6e30c8f4c725f5d36fb6
DIFF: 
https://github.com/llvm/llvm-project/commit/85e542fff3c521ede90d6e30c8f4c725f5d36fb6.diff

LOG: libclc: Improve fdim handling (#186085)

The maxnum is somewhat overconstraining. This gives slightly
better codegen and avoids the noise from the select and convert,
and saves the cost of materializing the nan literal.

Added: 
    

Modified: 
    libclc/clc/lib/generic/math/clc_fdim.cl
    libclc/clc/lib/generic/math/clc_fdim.inc

Removed: 
    


################################################################################
diff  --git a/libclc/clc/lib/generic/math/clc_fdim.cl 
b/libclc/clc/lib/generic/math/clc_fdim.cl
index 4e76448cde88f..a2b3adac29c10 100644
--- a/libclc/clc/lib/generic/math/clc_fdim.cl
+++ b/libclc/clc/lib/generic/math/clc_fdim.cl
@@ -6,13 +6,7 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#include <clc/clc_convert.h>
-#include <clc/float/definitions.h>
-#include <clc/internal/clc.h>
-#include <clc/math/clc_fmax.h>
-#include <clc/math/math.h>
-#include <clc/relational/clc_isnan.h>
-#include <clc/relational/clc_select.h>
+#include "clc/relational/clc_isunordered.h"
 
 #define __CLC_BODY <clc_fdim.inc>
-#include <clc/math/gentype.inc>
+#include "clc/math/gentype.inc"

diff  --git a/libclc/clc/lib/generic/math/clc_fdim.inc 
b/libclc/clc/lib/generic/math/clc_fdim.inc
index 0a8463a71f7ef..8ab5a776490bb 100644
--- a/libclc/clc/lib/generic/math/clc_fdim.inc
+++ b/libclc/clc/lib/generic/math/clc_fdim.inc
@@ -8,7 +8,5 @@
 
 _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_fdim(__CLC_GENTYPE x,
                                                 __CLC_GENTYPE y) {
-  return __clc_select(__builtin_elementwise_maxnum(x - y, __CLC_FP_LIT(0.0)),
-                      __CLC_GENTYPE_NAN,
-                      __CLC_CONVERT_BIT_INTN(__clc_isnan(x) || 
__clc_isnan(y)));
+  return (x <= y && !__clc_isunordered(x, y)) ? __CLC_FP_LIT(0.0) : (x - y);
 }


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to