<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64238>64238</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] Missed optimization for icmp(constants[x]) when the range of x is implied
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:optimizations,
llvm:instcombine,
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
XChy
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
XChy
</td>
</tr>
</table>
<pre>
```llvm
@constant = constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
define i32 @src(i64 %x) local_unnamed_addr #0 {
entry:
%cond = icmp ult i64 %x, 2
br i1 %cond, label %case1, label %case2
case2:
ret i32 789
case1:
%isOK_ptr = getelementptr inbounds i32, ptr @constant, i64 %x
%isOK = load i32, ptr %isOK_ptr, align 1
%cond_inferred = icmp ult i32 %isOK, 5
br i1 %cond_inferred, label %caseOK, label %caseErr
caseOK:
ret i32 456
caseErr:
ret i32 123
}
```
Here %cond_inferred should be always true.
[Missed example](https://godbolt.org/z/GPaoEcYT7)
[alive-tv](https://alive2.llvm.org/ce/z/ofxtZW)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVF2v4yYQ_TX4BSWyAZv4wQ-bZNNWq2r7UKkfLxE245gKQwT4brK_voLYSW7ulaLYzJxzmDngEd6rkwFoULlFhPy9G66IEFTuMzGFwbomRrLWymuDqvz20_ptRPke5V8QyztrfBAmYET3-LEotwxfsKJRKq4UJbhAZBdDmCwvdHlhqNzPkulfQq8MpBRiuXcdIhtVMYxIeUGkxtp2Qh8nY8QI8iikdBgRmmPEtzcBMMFdEZ3lMMaR2lkjU52qG8940gE_NHeYzNjWYVUs8JjQogWdAsJD8SFCngu_BZ73dRBSH3xTvwKL1wKV__7teA4uFXmCABpGMCFGlGntZKRPnpIdTqiH_cnIpZlXySSnrZDvyI_tYkhodTK4mLlz90dlenAOXl2Lx3KjR2r52PCdd3f2B8tuvHehr8692vP926dGsrJ6RUbyHbrgCkJnHF_u1nKDb8tfwcHHTv1gJy1xC1joH-LqcXATrGeBcvu78h4khosYzxritSWbIYSzjwWQAyKHk5Wt1WFt3QmRw09EDr_8IezX7p8_OSL1XUho9Qar8PaZRMqRdfzQZpkOZi3bX8K_fyFSZ7Khsqa1yKApqjrnlDPOsqGRRc-YLKqag-S04pRVooJKUF6VtN-UmWpITmjOaV7wgpds3ea8p5IJ1nZtyxlDLIdRKH0vIFPeT9BUjNBNlo7NzwMjzQL6xZ6DGtVPEZQ1Pg4QsnsklfGhs2OrDNxTY7Jx9cyb545rIm3VTiePWK6VD_5RR1BBp1n1m_FhN2uWezyfyrMc7q1LVxaRzfKVeFRuL8nwGv8YwOAwAHbCnADbPs4rj9V41gpkNjndvJyrCsPUrjs7InJIrd0eq7Oz_0EXEDkkmzwih-TU_wEAAP___9OShg">