<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/151683>151683</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DAG] ForwardStoreValueToDirectLoad - failure to peek through non-matching load types
</td>
</tr>
<tr>
<th>Labels</th>
<td>
missed-optimization,
llvm:SelectionDAG
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RKSimon
</td>
</tr>
</table>
<pre>
ForwardStoreValueToDirectLoad can peek through a load of a store of a constant to use the constant directly:
```ll
define float @test_stlf(ptr %p, float %v) {
store float zeroinitializer, ptr %p, align 4
%f = load float, ptr %p, align 4
%r = fmul fast float %f, %v
ret float %r
}
```
```asm
test_stlf: # @test_stlf
movl $0, (%rdi)
xorps %xmm0, %xmm0
retq
```
But if we are storing a different type (typically due to load combining etc.) then the forwarding fails:
```ll
define float @test_stlf_integer(ptr %p, float %v) {
store i32 zeroinitializer, ptr %p, align 4
%f = load float, ptr %p, align 4
%r = fmul fast float %f, %v
ret float %r
}
define float @test_stlf_vector(ptr %p, float %v) {
store <4 x float> zeroinitializer, ptr %p, align 4
%f = load float, ptr %p, align 4
%r = fmul fast float %f, %v
ret float %r
}
define float @test_stlf_bitcast(ptr %p, float %v) {
store <2 x i64> zeroinitializer, ptr %p, align 4
%f = load float, ptr %p, align 4
%r = fmul fast float %f, %v
ret float %r
}
```
```asm
test_stlf_integer: # @test_stlf_integer
movl $0, (%rdi)
mulss (%rdi), %xmm0
retq
test_stlf_vector: # @test_stlf_vector
xorps %xmm1, %xmm1
movups %xmm1, (%rdi)
mulss (%rdi), %xmm0
retq
test_stlf_bitcast: # @test_stlf_bitcast
xorps %xmm1, %xmm1
movups %xmm1, (%rdi)
mulss (%rdi), %xmm0
retq
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUVlGP4yYQ_jX4BSXC2CTZBz9kN00f2qdu1dcThsGmxcaFcW6zv74CZze7d3u9O1Wq9qRIwXwzzDfzMYCM0XYjQEPELRGHQs7Y-9D89su9HfxYtF6fm6MPH2XQ9-gD_CHdDL_7gw2g8FcvNVVypBPAXxT74Oeup5K6NO8NlTQmn2Wo_BhRjkjR0zkCxR6uczqv586k2hO2Jxu2_JwjbK_B2BGocV4iJTVDiPghojOE7yYMlHAxEX73ZMDFifAbSra3hO3phcGCPULwdrRopbOPEJLTywWks91I6-xGuDCUVIcll-z-FfOQzc0wO2pkxCsdk4wzrWQZ4AUUUrLbw8uU0_jFp4wDYftrytWeEl69LkNadvAnRwmv2RJslxbXlvCbjD74MMUU8GEYLhbL8MLo788Z3M5IraEfgcoAuYp27Kik2hoDAZKO5wlSKDxPVknnzlTPkNTNJVN-aO2YfADVOimCPYxZdbPsp4QZaV28iP7Nun-wI0KX9Ptm_W3F37P6X071BAr992RKqruaPlw4Vz_9mFm3FpWM-H1pc_pA7aZ-50m_arMvdPnzBn-j25-xr3f9MLsYX0-_3fqfbbe34l6gT4-T8rpm-cRp_hT978SedsRbzJ6w_5Xas3aFbip9U93IAppyK2pW17zeFX0joKyBi3a32-qN5IYLo-uNkKYFUSuhC9twxgXbsbJkFat365aXW7XVW82MqkpQpGYwSOvWzp2GtQ9dYWOcoSlFudlVhZMtuJhvbs4HGyPolZ_QDvZRovUj4ZzwO8J5cifV_h4cqAQc9j8nTByK0CRs1c5dJDVzNmK8BkOLLj8Mkr040H9_B6zyYT6HfAW8ehCMflwNElWfTvzcZunqiMUcXNMjTvkC4EfCj53Ffm7Xyg-EHzPr5W81Bf8nKCT8mCsQCT9einBq-D8BAAD__6d0qJ4">