[compiler-rt] compiler-rt/arm: Check for overflow when adding float denorms (PR #185245)

via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 7 23:19:43 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-arm

Author: Keith Packard (keith-packard)

<details>
<summary>Changes</summary>

When the sum of two sub-normal values is not also subnormal, we need to set the exponent to one.

Test case:

static volatile float x = 0x1.362b4p-127;
static volatile float x2 = 0x1.362b4p-127 * 2;

int
main (void)
{
	printf("x %a x2 %a x + x %a\n", x, x2, x + x);
	return x2 == x + x ? 0 : 1;
}

---
Full diff: https://github.com/llvm/llvm-project/pull/185245.diff


1 Files Affected:

- (modified) compiler-rt/lib/builtins/arm/addsf3.S (+9) 


``````````diff
diff --git a/compiler-rt/lib/builtins/arm/addsf3.S b/compiler-rt/lib/builtins/arm/addsf3.S
index 7b7cf85922753..3e67bafb55d61 100644
--- a/compiler-rt/lib/builtins/arm/addsf3.S
+++ b/compiler-rt/lib/builtins/arm/addsf3.S
@@ -113,6 +113,15 @@ LOCAL_LABEL(done_align):
   // aSignificand += bSignificand;
   adds r4, r4, r5
 
+  // Check for denorm result
+  cmp  r2, #0
+  bne  1f
+
+  // Add carry bit to exponent
+  lsrs r6, r4, #(significandBits + 3)
+  adds r2, r2, r6  // result Exponent
+
+1:
   // Check carry bit.
   movs r6, #1
   lsls r6, r6, #(significandBits + 3 + 1)

``````````

</details>


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


More information about the llvm-commits mailing list