(iN X s>> (N-1)) & Y --> (X < 0) ? Y : 0
https://alive2.llvm.org/ce/z/qeYhdz
I was looking at a missing abs() transform and found my way to this generalization of an existing fold that was added with D67799. As discussed in that review, we want to make sure codegen handles this difference well, and for all of the targets/types that I spot-checked, it looks good.
There's a difference on an existing test that shows a potentially unnecessary use limit on an icmp fold.
That fold is in InstCombinerImpl::foldICmpSubConstant(), and IIRC there was some back-and-forth on it and similar folds because it could cause analysis/passes (SCEV, LSR?) to miss optimizations.
So I think this patch makes things more consistent. But if the more specific transform was here as a work-around, we could leave it in as a special-case before we do the more general fold (...but that would be pretty hacky).