[PATCH] D149418: [ValueTracking] Add additional cases for `isKnownNonZero(mul X, Y)`

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 11 20:40:36 PDT 2023


goldstein.w.n added a comment.

In D149418#4336383 <https://reviews.llvm.org/D149418#4336383>, @holland11 wrote:

> Ah I see now, thank you! So in general, the only way a multiply with two non-zero source operands can result in a 0 is from overflow, but if at least one of those operands is odd, any overflow will never result in overflowing to 0.
>
> Edit: Nvm, the below is actually incorrect. I was only considering a single overflow (so 0b10000 in a 4 bit result), but it's possible to get multiple overflow (0b110000 in a 4 bit result) which could still be 0 without being a power of two.
> I suppose another way to think about it is that the only way to overflow to 0 in binary is with a result that is a power of two (ex. 256 in 8bit). Power of two's are never divisible by an odd number (besides 1, but that would require 256 * 1 which wouldn't make sense for 8b arithmetic). So if our multiplication involves at least one odd number, the result will never be a power of two (unless the other operand is 1 which means we won't overflow anyways) which means it will never overflow to 0.

This made me think of something, we can actually strengthen this case. Odd is just a special case really the result is X * Y != 0 is the same is Lowbit(X) * Lowbit(Y) != 0. Patch incoming!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149418



More information about the llvm-commits mailing list