diff options
author | Noah Goldstein <goldstein.w.n@gmail.com> | 2023-05-25 12:10:31 -0500 |
---|---|---|
committer | Noah Goldstein <goldstein.w.n@gmail.com> | 2023-06-06 15:14:10 -0500 |
commit | 809b1d834dfc59575be228cfbccb95b10c2c34e2 (patch) | |
tree | ca46061d5ae3687425958411b826b066adebbae4 /llvm/lib/Support/KnownBits.cpp | |
parent | 8b2767f25708c8e9c1bc5682ee60bc3eb6754424 (diff) | |
download | llvm-809b1d834dfc59575be228cfbccb95b10c2c34e2.zip llvm-809b1d834dfc59575be228cfbccb95b10c2c34e2.tar.gz llvm-809b1d834dfc59575be228cfbccb95b10c2c34e2.tar.bz2 |
[KnownBits] Return `0` for poison {s,u}div inputs
It seems consistent to always return zero for known poison rather than
varying the value. We do the same elsewhere.
Differential Revision: https://reviews.llvm.org/D150922
Diffstat (limited to 'llvm/lib/Support/KnownBits.cpp')
-rw-r--r-- | llvm/lib/Support/KnownBits.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp index 8bc6562..ce2813e 100644 --- a/llvm/lib/Support/KnownBits.cpp +++ b/llvm/lib/Support/KnownBits.cpp @@ -758,6 +758,13 @@ KnownBits KnownBits::sdiv(const KnownBits &LHS, const KnownBits &RHS, assert(!LHS.hasConflict() && !RHS.hasConflict() && "Bad inputs"); KnownBits Known(BitWidth); + if (LHS.isZero() || RHS.isZero()) { + // Result is either known Zero or UB. Return Zero either way. + // Checking this earlier saves us a lot of special cases later on. + Known.setAllZero(); + return Known; + } + std::optional<APInt> Res; if (LHS.isNegative() && RHS.isNegative()) { // Result non-negative. @@ -819,6 +826,13 @@ KnownBits KnownBits::udiv(const KnownBits &LHS, const KnownBits &RHS, assert(!LHS.hasConflict() && !RHS.hasConflict()); KnownBits Known(BitWidth); + if (LHS.isZero() || RHS.isZero()) { + // Result is either known Zero or UB. Return Zero either way. + // Checking this earlier saves us a lot of special cases later on. + Known.setAllZero(); + return Known; + } + // We can figure out the minimum number of upper zero bits by doing // MaxNumerator / MinDenominator. If the Numerator gets smaller or Denominator // gets larger, the number of upper zero bits increases. |