I looked around instcombine for precedence for this, but I don't see any existing folds where it comes up.
I'm proposing that we pull 'not' ops through min/max even if it means adding an instruction (because all of the 'not' values have other uses) .
The justification for this is that we're still eliminating all (4) of the 'not' value uses in the min/max, so it's still a net reduction of uses.
The bigger motivating case can be seen in the last PR35875 test. We end up eliminating instructions there because we can absorb 'not' into 'sub'.
Possible alternatives are:
- Do a very narrow/large pattern match for min/max+sub. To get the motivating example, it would actually have to be a match of 3-way min/max + sub.
- Defer this fold to some other pass (aggressive-instcombine, GVN?) where we can check users to make sure we won't increase the instruction count.