<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/82877>82877</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] InstCombine stucks when simplifying icmps
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:instcombine,
llvm:hang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
dtcxzyw
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dtcxzyw
</td>
</tr>
</table>
<pre>
Reduced test case: https://godbolt.org/z/dc6jnha5q
```
define i64 @func(i32 %p) {
entry:
%not = xor i32 %p, -1
br label %for.body
for.body:
%p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]
%p1 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%inc = add i32 %p1, 1
%cmp1 = icmp ne i32 %inc, 0
%cond = select i1 %cmp1, i32 0, i32 -1231558963
%xor = xor i32 %cond, %p0
%cmp2 = icmp ne i32 %xor, -2
%conv = zext i1 %cmp2 to i32
br i1 %cmp2, label %for.body, label %for.exit
for.exit:
ret i64 0
}
```
```
IC: Visiting: %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]
IC: Visiting: %cmp2 = icmp ne i32 %1, -2
ADD DEFERRED: %2 = select i1 %cmp1.not, i32 1231558962, i32 -1
ADD DEFERRED: %3 = xor i32 %2, %p0
IC: Old = %cmp2 = icmp ne i32 %1, -2
New = <badref> = icmp ne i32 %3, 1
ADD: %cmp2 = icmp ne i32 %3, 1
IC: ERASE %4 = icmp ne i32 %1, -2
ADD DEFERRED: %1 = xor i32 %0, %p0
IC: ERASE %1 = xor i32 %0, %p0
ADD DEFERRED: %0 = select i1 %cmp1.not, i32 -1231558963, i32 0
ADD DEFERRED: %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]
ADD: %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]
IC: ERASE %0 = select i1 %cmp1.not, i32 -1231558963, i32 0
ADD DEFERRED: %cmp1.not = icmp eq i32 %inc, 0
ADD: %cmp1.not = icmp eq i32 %inc, 0
ADD: %1 = xor i32 %0, %p0
ADD: %0 = select i1 %cmp1.not, i32 1231558962, i32 -1
IC: Visiting: %0 = select i1 %cmp1.not, i32 1231558962, i32 -1
IC: Visiting: %1 = xor i32 %0, %p0
IC: Visiting: %cmp1.not = icmp eq i32 %inc, 0
IC: Visiting: %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]
IC: Visiting: %cmp2 = icmp ne i32 %1, 1
ADD DEFERRED: %2 = select i1 %cmp1.not, i32 -1231558963, i32 0
ADD DEFERRED: %3 = xor i32 %2, %p0
IC: Old = %cmp2 = icmp ne i32 %1, 1
New = <badref> = icmp ne i32 %3, -2
ADD: %cmp2 = icmp ne i32 %3, -2
IC: ERASE %4 = icmp ne i32 %1, 1
ADD DEFERRED: %1 = xor i32 %0, %p0
IC: ERASE %1 = xor i32 %0, %p0
ADD DEFERRED: %0 = select i1 %cmp1.not, i32 1231558962, i32 -1
ADD DEFERRED: %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]
ADD: %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]
IC: ERASE %0 = select i1 %cmp1.not, i32 1231558962, i32 -1
ADD DEFERRED: %cmp1.not = icmp eq i32 %inc, 0
ADD: %cmp1.not = icmp eq i32 %inc, 0
ADD: %1 = xor i32 %0, %p0
ADD: %0 = select i1 %cmp1.not, i32 -1231558963, i32 0
IC: Visiting: %0 = select i1 %cmp1.not, i32 -1231558963, i32 0
IC: Visiting: %1 = xor i32 %0, %p0
IC: Visiting: %cmp1.not = icmp eq i32 %inc, 0
Repeats multiple times...
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUV0FvqzgQ_jXmYhUZg0M4cEhDIr3LrpSV9g7YJH4LhodNm_bXr2xI4vJIS6JWepUigu2Zz-OZb77EqZR8LxiLAXkEGFOVH19fngHGgCRO2qlD3cbDpJPV9CXeMdrljELFpIJ5KhnwV_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