<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60103>60103</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Constant propagation makes a register value forgotten
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:optimizations,
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chfast
</td>
</tr>
</table>
<pre>
```cpp
template <unsigned X>
int go(int) noexcept;
int sw(int arg)
{
switch (arg)
{
case 0: return go<0>(arg);
case 1: return go<1>(arg);
case 2: return go<2>(arg);
case 3: return go<3>(arg);
case 4: return go<4>(arg);
}
return 0;
}
```
In this example `arg` argument is forwarded to `go` calls. Although the value is already in the right register the register is re-assigned because on the IR level the usage is converted to constant.
```asm
.LBB0_3:
mov edi, 1
jmp int go<1u>(int) # TAILCALL
```
https://godbolt.org/z/cczTP5v1q
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyElEmPgzYUxz-NuTwl8hK2A4csjTRSDlU1h94qAy_gqcHUfmSWT18BmUkmXcZCsuz3__mtQodgmh6xYPGOxYdIj9Q6X1TtWQeKSle_Fyzhy1cNA-MHxreE3WA1ITC1H_v5gRp-Z-qXxWx6gsYxmZmemMyhd_hW4UBM7RbBTRZeFxlo3zCZX83pVQfh1VDVApPZvR0A4Ka5rkoHBM7UFjzS6PspArXnU1BftPo3Rjwy4mdGPjLyZ0Y9MupnZvPIbP6TYenhvrifFL8V_Uvw2c97_VMP1JoA-Ka7wSKwhE9OEj51ZuywJzABzs6_al9jDeQmSeMmRaWtDWvYWmrd2LRALcJF2xEnRFuPun4H08_33jQtgcfGBEK_XH0eTACPq-tE1lBipceA4Bby6TeweEE7H8agm_n5yvUX9LREVLk-kO5pfZ_ZV7o6dMvN-rTb8T-mfnwveecu8461YXIP4rv1pRvgOtlqL8alEdcJ_-diUsHz9um0355O_1P2lmgIUyDyyOSxcXXpLK3d1N7jB5PHqvp4_jW-iL-iulB1rnIdYSGSVOVJJlQatUVelpsk4wJLXaUqE-Um03VdJ0KlucgrjEwhuVRciFTEPIvTtVIy3SgZn-tYlGeRsQ3HThu7tvbSTb4jE8KIRcIFV5HVJdow_x6knBRMbd1ApjMfmozrA5OSyT2TsjMhYL26N062-BD5YgJX5dgEtuHWBAo3Z2TIYrG_tg4G7wbdzDR0-k8MoG8TskzV2fnGEWEfjd4WDyU01I7lunIdk8c53GVbDd69YEVMHufsApPHOcG_AwAA__8n0XQW">