[PATCH] D107849: [Libclc] Resolve FIXME: GCN insel crashes when a == 0 or b == 0

Alf via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 10 11:01:06 PDT 2021


gAlfonso-bit created this revision.
gAlfonso-bit added a reviewer: LLVM.
Herald added a subscriber: jvesely.
gAlfonso-bit requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107849

Files:
  libclc/generic/lib/math/clc_fma.cl
  libclc/generic/lib/math/math.h


Index: libclc/generic/lib/math/math.h
===================================================================
--- libclc/generic/lib/math/math.h
+++ libclc/generic/lib/math/math.h
@@ -76,15 +76,14 @@
 #define MANTLENGTH_SP32   24
 #define BASEDIGITS_SP32   7
 
-_CLC_OVERLOAD _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x)
-{
-	int ix = as_int(x);
-	if (!__clc_fp32_subnormals_supported() &&
-		((ix & EXPBITS_SP32) == 0) && ((ix & MANTBITS_SP32) != 0)) {
-		ix &= SIGNBIT_SP32;
-		x = as_float(ix);
-	}
-	return x;
+_CLC_OVERLOAD _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x) {
+  int ix = as_int(x);
+  if (!__clc_fp32_subnormals_supported() && ((ix & MANTBITS_SP32) != 0) &&
+      ((ix & EXPBITS_SP32) == 0)) {
+    ix &= SIGNBIT_SP32;
+    x = as_float(ix);
+  }
+  return x;
 }
 
 #ifdef cl_khr_fp64
Index: libclc/generic/lib/math/clc_fma.cl
===================================================================
--- libclc/generic/lib/math/clc_fma.cl
+++ libclc/generic/lib/math/clc_fma.cl
@@ -46,18 +46,21 @@
 	b = __clc_flush_denormal_if_not_supported(b);
 	c = __clc_flush_denormal_if_not_supported(c);
 
-	if (c == 0)
+	if (a == .0f || b == .0f)
+		return c;
+
+	if (c == .0f)
 		return a * b;
 
 	struct fp st_a, st_b, st_c;
 
-	st_a.exponent = a == .0f ? 0 : ((as_uint(a) & 0x7f800000) >> 23) - 127;
-	st_b.exponent = b == .0f ? 0 : ((as_uint(b) & 0x7f800000) >> 23) - 127;
-	st_c.exponent = c == .0f ? 0 : ((as_uint(c) & 0x7f800000) >> 23) - 127;
+	st_a.exponent = ((as_uint(a) & 0x7f800000) >> 23) - 127;
+	st_b.exponent = ((as_uint(b) & 0x7f800000) >> 23) - 127;
+	st_c.exponent = ((as_uint(c) & 0x7f800000) >> 23) - 127;
 
-	st_a.mantissa = a == .0f ? 0 : (as_uint(a) & 0x7fffff) | 0x800000;
-	st_b.mantissa = b == .0f ? 0 : (as_uint(b) & 0x7fffff) | 0x800000;
-	st_c.mantissa = c == .0f ? 0 : (as_uint(c) & 0x7fffff) | 0x800000;
+	st_a.mantissa = (as_uint(a) & 0x7fffff) | 0x800000;
+	st_b.mantissa = (as_uint(b) & 0x7fffff) | 0x800000;
+	st_c.mantissa = (as_uint(c) & 0x7fffff) | 0x800000;
 
 	st_a.sign = as_uint(a) & 0x80000000;
 	st_b.sign = as_uint(b) & 0x80000000;
@@ -73,7 +76,6 @@
 	st_mul.mantissa = (st_a.mantissa * st_b.mantissa) << 14ul;
 	st_mul.exponent = st_mul.mantissa ? st_a.exponent + st_b.exponent : 0;
 
-	// FIXME: Detecting a == 0 || b == 0 above crashed GCN isel
 	if (st_mul.exponent == 0 && st_mul.mantissa == 0)
 		return c;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107849.365545.patch
Type: text/x-patch
Size: 2402 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210810/da33bf5a/attachment.bin>


More information about the llvm-commits mailing list