[InstCombine] avoid infinite loops from min/max canonicalization
authorSanjay Patel <spatel@rotateright.com>
Tue, 10 Aug 2021 18:30:43 +0000 (14:30 -0400)
committerSanjay Patel <spatel@rotateright.com>
Tue, 10 Aug 2021 18:42:37 +0000 (14:42 -0400)
commitb267d3ce8defa092600bda717ff18440d002f316
tree1b714a4489e239c5d0c13495d8729025e04d5829
parent640091884f81b377737bb73a3f076c7069666607
[InstCombine] avoid infinite loops from min/max canonicalization

The intrinsics have an extra chunk of known bits logic
compared to the normal cmp+select idiom. That allows
folding the icmp in each case to something better, but
that then opposes the canonical form of min/max that
we try to form for a select.

I'm carving out a narrow exception to preserve all
existing regression tests while avoiding the inf-loop.
It seems unlikely that this is the only bug like this
left, but this should fix:
https://llvm.org/PR51419
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/select-min-max.ll