[PATCH] D149203: [ValueTracking] Add logic for `udiv x, y != 0` iff `y u<= x` -> `x != 0`

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 26 00:15:27 PDT 2023


nikic requested changes to this revision.
nikic added a comment.
This revision now requires changes to proceed.

I don't think you need the isKnownNonZero() check? If `X >= Y` and `X == 0` then `Y == 0`, which is UB. https://alive2.llvm.org/ce/z/hw8Gs9 Or maybe even simpler: https://alive2.llvm.org/ce/z/QhiNtE



================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2777-2781
+      std::optional<bool> YUleX = KnownBits::ule(YKnown, XKnown);
+
+      // If Y u<= X then div is only zero if X is zero.
+      if (YUleX && *YUleX)
+        return isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q);
----------------
I found the swapped operand order confusing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149203/new/

https://reviews.llvm.org/D149203



More information about the llvm-commits mailing list