[llvm] [InstCombine] Add additional known bits info for self multiply (PR #151202)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 4 10:47:46 PDT 2025
================
@@ -888,11 +888,27 @@ KnownBits KnownBits::mul(const KnownBits &LHS, const KnownBits &RHS,
Res.Zero |= (~BottomKnown).getLoBits(ResultBitsKnown);
Res.One = BottomKnown.getLoBits(ResultBitsKnown);
- // If we're self-multiplying then bit[1] is guaranteed to be zero.
- if (NoUndefSelfMultiply && BitWidth > 1) {
- assert(Res.One[1] == 0 &&
- "Self-multiplication failed Quadratic Reciprocity!");
- Res.Zero.setBit(1);
+ // Self multiplying
+ if (NoUndefSelfMultiply) {
+ // bit[1] is guaranteed to be zero.
+ if (BitWidth > 1) {
+ assert(Res.One[1] == 0 &&
+ "Self-multiplication failed Quadratic Reciprocity!");
+ Res.Zero.setBit(1);
+ }
+
+ // If X has TZ trailing zeroes, then bit (2 * TZ + 1) must be zero.
+ unsigned TwoTZP1 = 2 * TrailZero0 + 1;
+ if (TwoTZP1 < BitWidth)
+ Res.Zero.setBit(TwoTZP1);
+
+ // If X has exactly TZ trailing zeros, then bit (2 * TZ + 2) must also be
----------------
dtcxzyw wrote:
```suggestion
// If X has exact TZ trailing zeros, then bit (2 * TZ + 2) must also be
```
https://github.com/llvm/llvm-project/pull/151202
More information about the llvm-commits
mailing list