<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55464>55464</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization - suspect escape analysis
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
OfekShilon
</td>
</tr>
</table>
<pre>
[godbolt link](https://godbolt.org/z/fM5W96YjG)
In the following toy code:
```cpp
struct Arr { double* data; };
struct Scalar {
Scalar();
double val;
};
void func( const Arr* __restrict__ input, Arr* __restrict__ result ) {
const double* b = input->data;
Scalar sc;
for(int j = 0; j < 2; ++j ) {
sc.val += b[j];
result->data[j] += sc.val;
}
}
```
An optimization remark is visible in the line ` sc1.val += b[j];`, reading:
> Load of type double not eliminated because it is clobbered by call
The only suspected clobbering call (the only call for that matter) is the `Scalar` ctor. Indeed, adding a visible implementation like `Scalar() : val(0) {}` produces much better code. The godbolt link demonstrates both.
Not sure what the compiler is guarding against - it seems no address can escape through a ctor (or any) call with no arguments. The same remark is shown for a ctor taking an argument by value, and is equally surprising.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx1VF2PmzoQ_TXkZbSIQLIbHnjIdu-tKvXjoZWqPq2MbcCJsak_Nkp_fWdMskvaeyMC_poz55wZaK04N9n2sbeitTqAVuaYbZ-ycjeEMPms2mflv3hd9nPrepz9wn_3afu9vv9xeJ-VdVY8ZcV-vn8wEAYJndXanpTpIdgzcCskYc3n7ov54tM0r_jgIg-wdw6yh0cQNrZaZuUeBAssqx5x9QkfyzSXkK-caZai5mXA37yGEohZtdiYceGF6Tewv4BfrBLQRcMRAHkbn3gRmednJzGt4uH5GZSZYsjKd_-5icOIZmL-W2Yz3Ju8FrLqaYa6y6p_LmqXbN70gOc3YjpLEpUJcEgoBflEw3dQJsvKR7wOf5Ogn-c5upDOYGiLDXCgqld_HJt1vFKbT12jZ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