[llvm] [KnownBits][SelectionDAG] Add KnownBits::clmul. Support trailing bits. NFC (PR #177517)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 23 01:05:27 PST 2026


================
@@ -602,6 +602,41 @@ KnownBits KnownBits::ashr(const KnownBits &LHS, const KnownBits &RHS,
   return Known;
 }
 
+KnownBits KnownBits::clmul(const KnownBits &LHS, const KnownBits &RHS) {
+  unsigned BitWidth = LHS.getBitWidth();
+
+  // An m*n result will always fit in m+n-1 bits since there are no carries.
+  unsigned ActiveBits = std::min(
+      BitWidth, LHS.countMaxActiveBits() + RHS.countMaxActiveBits() - 1);
+
+  // The result of the bottom bits of a clmul can be inferred by looking at the
+  // bottom bits of both operands and carryless multiplying them together. The
+  // number of bits we can determine follows the same logic as KnownBits::mul.
+  const APInt &Bottom0 = LHS.One;
+  const APInt &Bottom1 = RHS.One;
----------------
jayfoad wrote:

Ugh, switching the naming convention from LHR/RHS to 0/1 here seems actively confusing, since we also have fields .Zero and .One. But I see it is just copied from KnownBits::mul so I guess it's OK.

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


More information about the llvm-commits mailing list