The test (currently crashing) is reduced from the example provided in the post-commit discussion in D87149.
Here we replace with undef because we can't remove the operand completely (because InstCombine preserves the CFG).
We used to do something similar for branches, but we changed that to use a fixed constant value rather than undef because branching on undef became poison/UB.
I'm not sure what the cost/implications of this approach are. If we want to fix the crash more directly, we could just add a clause for uses and restrict the transform from D87149.
The patch LGTM. Just a side comment: we should avoid tests with br undef as we define that as UB, and therefore it makes any transformation correct. Which in turn essentially disables verification by Alive2.
(I know we still have many such tests. I think we talked in the past of writing a script to do a mass change of these to use input variables)