This is a generalization of the icmp fold in D118061 (and that can probably be abandoned if this is sufficient).
We're looking for a disguised form of "odd * odd must be odd".
Some Alive2 proofs to show correctness:
https://alive2.llvm.org/ce/z/60Y8hz
https://alive2.llvm.org/ce/z/HfAP6R
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I don't suppose this can handle D117995? If we can do this in SimplifyDemandedBits then we can add the knownbits fold with the additional NeverUndefOrPoison check.
Otherwise I think I'll just add a (DemandedMask ==2 && X == Y) -> 0 special case.
Hmm, not sure if I understood the question. I'm not seeing how we'd do it other than a special-case here. The knownbits fold isn't going to work in general because of the potential undef input?
Also, if we're adding the Mask==2 special-case for self-multiply, we could add the Mask==1 case as well:
https://alive2.llvm.org/ce/z/3HcD76
Ping.
Note that 2d1390efbe610 added one special-case for the backend. Presumably, we should keep these in sync as much as possible, so I can add that in follow-ups after adding tests.
https://alive2.llvm.org/ce/z/f39Z6n