-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed
Labels
Description
The attached test case is causing instcombine to infinite loop. The two transformations that are going back and forth are:
InstCombineSelect.cpp:
static Instruction * tryToReuseConstantFromSelectInComparison(....)
and:
InstCombineCompares.cpp:
Instruction *InstCombinerImpl::foldICmpAddConstant(...)
....
// The range test idiom can use either ult or ugt. Arbitrarily canonicalize
// to the ult form.
// X+C2 >u C -> X+(C2-C-1) <u ~C
if (Pred == ICmpInst::ICMP_UGT)
The select transformation is doing this:
%1 = icmp ult i32 %0, 2
%spec.select = select i1 %1, i32 1, i32 -3
=>
%.inv = icmp ugt i32 %0, 1
%spec.select = select i1 %.inv, i32 -3, i32 1
It is flipping the compare so that the constant becomes the same as one of the
select operands.
The compare canonicalization then undoes this transformation, as it changes "ugt" back to ult". It looks like
one of these transformations should be prevented, but it is not immediately clear which way is "better".