aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/KnownBits.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Support/KnownBits.cpp')
-rw-r--r--llvm/lib/Support/KnownBits.cpp14
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.