<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/144300>144300</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed DSE of non-inlineable call
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
qchateau
</td>
</tr>
</table>
<pre>
Minimal working example:
```
@x = global i32 0, align 4
define void @bar(ptr %0) noinline {
%2 = load i32, ptr @x, align 4
store i32 %2, ptr %0, align 4
ret void
}
define void @foo() {
%1 = alloca i32, align 4
call void @bar(ptr %1)
ret void
}
```
`@bar` stores the value of global `@x` in its argument. It is marked `noinline`.
`@foo` calls `@bar` with an `alloca` variable, and does nothing else. At `-O3`, opt (trunk) is not able to kill the call to `@bar`.
In practice, I noticed this with an indirect call instead of a call to "@bar", and could not make DSE work as soon as the called function read memory (understand: the call gets DSE'ed with `memory(argmem: readwrite)`, but not with `memory(read, argmem: readwrite)`.
If I remvoe `noinline` , the call gets inline, then DSE'd correctly.
https://godbolt.org/z/9MEGrYdsa
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0lEGP4rgTxT-Ncyk1Mk4IcMiBGYa_-tD6H_a0x0pcSbw4Nms7dPd--lU50N3MzkhIEXG9V796LsAYzeCIGrH5JjbHAuc0-tD83Y2YCOei9fq9eTHOTGjh1YezcQPQG04XS6I8CHkQtbx95EFU8g1EeYTB-hYtmFKBFOo7oDWDg4pL5EFTbxzB1RsNopItBqF2lxRAqI0Uag_OG2e5RGy_CXkAPlDZ13rU7MqeWVHJt0d_gJh8oNyaZR-V2fuxMlDKFIy1Pf4SrvdeqB1DfWFZZxa01nd4p_nq26G1vx5vLdT-N62_xrh8XbS1XCaKkEaCK9qZwPf3hJe6N64yDkyKgGGYJ3JpBc8JTIQJw5k0F95jFbVcfbTgAWuZkSM8dH01aQR0_HIZlV9eMRhsLeWRnQbtKYLzacx7YSOt4JBY8vT_kt3Ud_CXBELtUpjdmYM0WQDsAsnD2VibR8upJf8AsVrSeHZwCdgl0-XGz2xgOtKQRhM_QI3TJlCXFifjYiLUnBV-eit1vxJ1H6Hzs9UZacIzwfGPH3nRASNE7x0_73ikoZ9dl4x3ENh8osmHdx5vdppCTOi0KA-f8wyUIlsKtSW9kIpaLjKhdhiGiSZWsN1rMIl4Q5bg2jllrP-ouDbT_059j62HZwg0XT39dP_A8kfI29ny3t2YOZ3Amdr3m6eQhzGlS-QfvzoJdRq8br1NKx8GoU7_CHXav_z4X_hTRyx0U-p9uceCmvV2I-WmqvdVMTaq3NW4p7LUnS573NX7stK7tapIdYhrLEyjpNrIel3Ler1bVyutZL1DpeueetqWragkTWjsytrrxL0LE-NMzbqqSikLiy3ZmP_UlHL0CvmUL31zLELDoqd2HqKopDUxxU-bZJKl5sXESDrvgu_Befe0xJOXljMr5mCbn4IwaZzbVecnoU7sd3s8XYL_i7ok1ClTRKFON8xro_4NAAD__xEHrzU">