[llvm] [KnownBits][APInt] Optimize isConstant (NFC) (PR #191919)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 19 14:18:39 PDT 2026


nikic wrote:

> The previous implementation (comparison bitwidth with sum of popcounts) allowed conflicts. I decided to keep this behavior, as changing it could potentially something break.

The previous implementation both allowed and did not allow conflicts, depending on the precise situation. Like `Zero = 01, One = 11` would not be "constant" but `Zero = 01, One = 01` would. The precise behavior here was just an artifact of the implementation...

> `Zero == ~One` would be ideal in terms of simplicity, although it could potentially create an allocation issue for multi-word scenarios. I can try committing it and see how it turns out. Can you add [that (e669e4603ee5bec04be37d0d8b5ccabbf1eea3dd)](https://github.com/llvm/llvm-project/pull/191919/commits/e669e4603ee5bec04be37d0d8b5ccabbf1eea3dd) commit to llvm-compile-time-tracker?

https://llvm-compile-time-tracker.com/compare.php?from=26b7fd51095221e03ce2a2170b6d168652ba3c7d&to=35963dd3fa10331ae34bb2c9f8c07c8d01624939&stat=instructions:u So the plain check doesn't seem to provide a benefit. I'd expect having a dedicates isInverseOf() method that avoids the allocation would though. (Though I find it peculiar that `(Zero | One).isAllOnes()` was beneficial without a dedicated implementation...)

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


More information about the llvm-commits mailing list