Currently we miss folds with undef and identity values for binary ops
that do not fold to undef in general.
We can generalize the identity simplifications and do them before
checking for undef in particular.
Alive checks:
This will also allow us to remove some now redundant cases throughout
the function, but I would like to do this as follow-up. That should make
tracking down potential issues easier.
Add a code comment for future reference? An identity constant always allows returning the other operand including undef/poison.
There's some possibly related discussion about that in:
https://bugs.llvm.org/show_bug.cgi?id=43958
Also, we can handle several more identity patterns like:
// X << 0 = X
by passing the optional "AllowRHSConstant" parameter to getBinOpIdentity().
So that could be another TODO for a follow-up patch. Our test coverage seems very lacking for this function though...so that should be improved first to make sure we're not breaking any rules.