[EarlyCSE] Improve EarlyCSE of some absolute value cases.


[EarlyCSE] Improve EarlyCSE of some absolute value cases.

Change matchSelectPattern to return X and -X for ABS/NABS in a well defined order. Adjust EarlyCSE to account for this. Ensure the SPF result is some kind of min/max and not abs/nabs in one place in InstCombine that made me nervous.

Prevously we returned the two operands of the compare part of the abs pattern. The RHS is always going to be a 0i, 1 or -1 constant. This isn't a very meaningful thing to return for any one. There's also some freedom in the abs pattern as to what happens when the value is equal to 0. This freedom led to early cse failing to match when different constants were used in otherwise equivalent operations. By returning the input and its negation in a defined order we can ensure an exact match. This also makes sure both patterns use the exact same subtract instruction for the negation. I believe CSE should evebntually make this happen and properly merge the nsw/nuw flags. But I'm not familiar with CSE and what order it does things in so it seemed like it might be good to really enforce that they were the same.

Differential Revision: https://reviews.llvm.org/D47037


Event Timeline

So, procedure wise, you should address all the review comments made, and if you have, and it was accepted afterwards, that is fine.
(IE you don't need everyone who has ever made a comment to accept it).

If you haven't addressed someone's review comments, and it was accepted, you should either address them, or ping that person to make sure they are okay with you committing it anyway.