Several cases where missing.
- (icmp eq/ne X*Z, Y*Z) [if Z % 2 != 0] -> (icmp eq/ne X, Y) EQ: https://alive2.llvm.org/ce/z/6_HPZ5 NE: https://alive2.llvm.org/ce/z/c34qSU
There was previously an implementation of this that work of Y was non-constant, but it was missing if Y*Z evaluated to a constant and/or nsw/nuw where both false. As well it only worked if Z was a constant but we can check 1s bit of KnownBits to cover more cases.
- (icmp eq/ne X*Z, Y*Z) [if Z != 0 and nsw(X*Y) and nsw(Y*Z)] -> (icmp eq/ne X, Y) EQ: https://alive2.llvm.org/ce/z/6SdAG6 NE: https://alive2.llvm.org/ce/z/fjsq_b
This was previously implemented only to work if Z was constant, but we can use isKnownNonZero to cover more cases.
- (icmp uPred X*Y, Y*Z) [if Z != 0 and nuw(X*Y) and nuw(X*Y)] -> (icmp uPred X, Y) EQ: https://alive2.llvm.org/ce/z/FqWQLX NE: https://alive2.llvm.org/ce/z/2gHrd2 ULT: https://alive2.llvm.org/ce/z/MUAWgZ ULE: https://alive2.llvm.org/ce/z/szQQ2L UGT: https://alive2.llvm.org/ce/z/McVUdu UGE: https://alive2.llvm.org/ce/z/95uyC8
This was previously implemented only for eq/ne cases. As well only if Z was constant, but again we can use isKnownNonZero to cover more cases.
Is there a better way to do this?