Add optimizations for icmp eq/ne (mul(X, Y), 0)
authorNoah Goldstein <goldstein.w.n@gmail.com>
Fri, 27 Jan 2023 23:26:19 +0000 (17:26 -0600)
committerNoah Goldstein <goldstein.w.n@gmail.com>
Fri, 27 Jan 2023 23:45:35 +0000 (17:45 -0600)
commitaa250ceb3ff15d55bb506b4bc8196f143133d8b5
treee4f35aadbd0f107ecbc30b72b014c4b383a74258
parent44977a155f24be3cdbcd2a57acbfd6da2529abde
Add optimizations for icmp eq/ne (mul(X, Y), 0)

1. Add checks if X and/or Y are odd. The Odd values are unnecessary to
   the icmp: isZero(Odd * N) == isZero(N)

2. If neither X nor Y is known odd, then if X * Y cannot overflow AND
   if X and/or Y is non-zero, the non-zero values are unnecessary to the
   icmp.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D140850
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-binop.ll
llvm/test/Transforms/InstCombine/pr38677.ll