Skip to content

Commit 0945ce5

Browse files
author
Macsen Casaus
committed
Generalize X * X info to all bit widths
1 parent 37dfb4b commit 0945ce5

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

llvm/lib/Support/KnownBits.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -897,20 +897,18 @@ KnownBits KnownBits::mul(const KnownBits &LHS, const KnownBits &RHS,
897897
Res.Zero.setBit(1);
898898
}
899899

900-
// If input bit[0] is set, then output bit[2] is guaranteed to be zero.
901-
if (BitWidth > 2 && LHS.One[0])
902-
Res.Zero.setBit(2);
900+
// If X has TZ trailing zeroes, then bit (2 * TZ + 1) must be zero.
901+
unsigned TZ = (~LHS.Zero).countr_zero();
902+
unsigned TwoTZP1 = 2 * TZ + 1;
903+
if (TwoTZP1 < BitWidth)
904+
Res.Zero.setBit(TwoTZP1);
903905

904-
// If input bit[0] is clear, then output bit[3] is guaranteed to be zero.
905-
if (BitWidth > 3 && LHS.Zero[0])
906-
Res.Zero.setBit(3);
907-
908-
// If input % 4 == 2, then output bit[3] and bit[4] are guarantted to be
906+
// If X has exactly TZ trailing zeros, then bit (2 * TZ + 2) must also be
909907
// zero.
910-
if (BitWidth > 3 && LHS.Zero[0] && LHS.One[1]) {
911-
Res.Zero.setBit(3);
912-
if (BitWidth > 4)
913-
Res.Zero.setBit(4);
908+
if (LHS.One[TZ]) {
909+
unsigned TwoTZP2 = TwoTZP1 + 1;
910+
if (TwoTZP2 < BitWidth)
911+
Res.Zero.setBit(TwoTZP2);
914912
}
915913
}
916914

0 commit comments

Comments
 (0)