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

Patrick Holland via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 11 16:15:09 PDT 2023


holland11 added a comment.

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.

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.


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