[InstCombine] canonicalize cmp+select as umin/umax
authorSanjay Patel <spatel@rotateright.com>
Wed, 8 Feb 2023 21:47:55 +0000 (16:47 -0500)
committerSanjay Patel <spatel@rotateright.com>
Wed, 8 Feb 2023 22:25:58 +0000 (17:25 -0500)
commit86b4d8645fc1b86693fef564cef68f24599c930f
tree717582c7f984d643580a40646c361efbcb2a7157
parentb98813fbb69751d95c7211784f0ca7735a935a36
[InstCombine] canonicalize cmp+select as umin/umax

(V == 0) ? 1 : V --> umax(V, 1)
(V == UMAX) ? UMAX-1 : V --> umin(V, UMAX-1)

https://alive2.llvm.org/ce/z/pfDBAf

This is one pair of the variants discussed in issue #60374.

Enhancements for the other end of the constant range and
signed variants are potential follow-ups, but that may
require more work because we canonicalize at least one
min/max like that to icmp+zext.
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/div-shift.ll
llvm/test/Transforms/InstCombine/select.ll