[llvm] [NFC] Various Cleanup in StackColoring, StackSlotColoring, LiveStacks (PR #143931)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 23 10:45:44 PDT 2025


================
@@ -795,6 +795,49 @@ using stack_float_t = volatile float;
 using stack_float_t = float;
 #endif
 
+/// Returns the number of digits in the given integer.
+inline int NumDigits(uint64_t N) {
----------------
Ralender wrote:

I used the logic from the link you sent, but I did a few changes:
 - tables are not built at compile-time, instead of handwritten
 - moved to 64bit
 - inverted the order of the AtLeast/guess table, to avoid doing 64 - clz. this also removes the cmove if the hw clz is well defined on 0
 - changed storage to unsigned for the AtLeast/guess table, because clang couldn't figure out the sign-extension was not needed.
   I suspect its a case of missing https://github.com/llvm/llvm-project/pull/127695

after that the codegen for x86-64-v3 is:
```asm
f3 48 0f bd c7        	lzcnt  %rdi,%rax
48 8d 0d d4 e8 ff ff  	lea    -0x172c(%rip),%rcx
48 63 04 81           	movslq (%rcx,%rax,4),%rax
48 3b bc c1 08 01 00 00	cmp    0x108(%rcx,%rax,8),%rdi
83 d8 ff              	sbb    $0xffffffff,%eax
```

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


More information about the llvm-commits mailing list