Trying to fix https://github.com/llvm/llvm-project/issues/53978 I ran into something like this: https://alive2.llvm.org/ce/z/bduF3e (generalized here https://alive2.llvm.org/ce/z/HdrUXt ) which is not currently optimized.
@nikic mentioned on discord that it might make more sense to canonicalize the intrinsic into a simple add/sub instead of trying to match that specific pattern
Yes, InstCombine would be the place. Though frankly, we should probably just canonicalize uadd/usub away from intrinsics. That should result in better mid-end optimization, and CGP can reform them
This patch does that, but only when the addition is by a constant. I added @uadd_res_ugt_smaller_const_or_ov and @uadd_res_ult_const_five_and_ov as a baseline (The baseline is in the second diff. The third one is the patch against main HEAD).
With this patch, the original case in https://github.com/llvm/llvm-project/issues/53978 gets optimized to a constant false.