<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/88107>88107</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[IPSCCP] Missed optimization: refine range of `select`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
XChy
</td>
</tr>
</table>
<pre>
Godbolt: https://github.com/Kitware/CMake/blob/3f08812a6bb1673378009393f01eac1a79927165/Utilities/cmzstd/lib/dictBuilder/zdict.c#L653
### Motivating example
```llvm
define i32 @caller(i32 %1) {
%cmp = icmp eq i32 %1, 0
%spec.select = select i1 %cmp, i32 3, i32 %1 ; %spec.select u> 0
call void @callee(i32 %spec.select)
unreachable ; resist inliner here
}
define void @callee(i32 %0) {
%cmp = icmp eq i32 %0, 0
%select = select i1 %cmp, i32 3, i32 0
call void @ZSTD_getParams(i32 %select)
ret void
}
declare void @ZSTD_getParams(i32)
```
can be folded to
```llvm
define void @caller(i32 %1) #0 {
%cmp = icmp eq i32 %1, 0
%spec.select = select i1 %cmp, i32 3, i32 %1
call void @callee(i32 %spec.select)
ret void
}
define internal void @callee(i32 %0) {
call void @ZSTD_getParams(0)
ret void
}
```
And then the dead argument can be eliminated.
Because the original real-world program is inter-procedural, put an inter-procedural example here.
### Real-world motivation
This snippet of IR is derived from [cmake/Utilities/cmzstd/lib/dictBuilder/zdict.c@ZDICT_analyzeEntropy](https://github.com/Kitware/CMake/blob/3f08812a6bb1673378009393f01eac1a79927165/Utilities/cmzstd/lib/dictBuilder/zdict.c#L653) (after O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, email me please.
**Let me know if you can confirm that it's an optimization opportunity, thanks.**
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVsFu4zYQ_Rr6MliBIi1LOvgQ2-si6C4a7KZAsZcFJY4sNhSpkpRT5-sLSo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