Only match trunc for now, as integrating into the SimplifyDemandedBits proved to be a significant challenge.
The change to returning SDValue looks like an NFC that you can do right away?
I can do that, indeed. Let me land this part and rebase.
Rebase on top of NFC changes
Shouldn't this be: APInt::getMaxValue(LHS.getScalarValueSizeInBits()) ?
TBH I'd prefer getAllOnesValue as well as it avoids the signed/unsigned ambiguity of getMaxValue.
That wouldn't generate the proper pattern for vectors and would leave things such as only the last element is demanded.
Add test for vector - but nothing changes for them (see rL374043 ) and use isSubsetOf and getAllOnesValue.
I don't understand the logic here.
This might need some comments.
Should this use getAllOnesValue() directly?