Issue with [InstCombine] Canonicalize range test idiom [D113366]

[AMD Official Use Only]

Hi,

https://reviews.llvm.org/D113366 and https://github.com/llvm/llvm-project/commit/1376301c87274bccf5565eb892173442782b1de3

The above change causes a soft hang for the below IR in InstCombine Transform.

define i32 @p0(i32 %CF_init) {
%t0 = add i32 %CF_init, -3
%t1 = icmp ugt i32 %t0, 1
%t2 = select i1 %t1, i32 -3, i32 1
ret i32 %t2
}

tryToReuseConstantFromSelectInComparison() from InstCombineSelect.cpp will replace select with inverse icmp and select. 1376301c8727 change when it sees a icmp ugt will replace with icmp ult. InstCombinerImpl::run() in InstructionCombining.cpp, will run these transforms in a loop and it never ends. This is causing soft hang.

icmp ugt is always transformed to icmp ult. Issue is with this transform. Commenting out the change fixes the soft hang issue.
Any suggestion on other ways of fixing this in InstructionCombining transform pass?

Regards,
Chaitanya

This problem was also reported as:
https://github.com/llvm/llvm-project/issues/52684
…and should be fixed with:
https://github.com/llvm/llvm-project/commit/bb2fc19c6355d990a4cfb94be20528fbe37950a8