<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJy1VluPqzYQ_jXkxVoEdi7wwMNeep4qVWpX6uPKmCFxj8HUNrsn_fWdAZIQklN1e5GiMNiemW9mvhlT2upYvIIPrNGtbvQfULHa2Ya9Otn62rrGR_zLLz__9IiPd1DBuocO923Qto2NicRjlLxEyel_m4w_Y96bcamCWrfA3q2uWLROAvp6832Jtt4aaFR3jHims4g_sohv6ojnLNo9jaqMliSLxAuTxlhF4vOafWO1sTJE4oeIP-OO3rcs3c5V4j10fNDbQwADDbShC-6e-s3SgEPSlhacJSeBX9lX0ofRQakDvUwGJu3Rf7BsCGyJTPy3yMQNMvHXyMQNMoXpPVeIShePpYm7RGfjH3qaF2pyNGCYFW9EtB6ElNXSeMCK_nM39ZWDKe8nN9l33ETiiSnbUGpZOADD-Csm24rpQOudNuAZkXKWOAdhSNpw9nPFWBKQTFGQU0fsXuYNUoEy0sEnstBadCA9PpXsQo-6H04HsK05XpJze8iBrM5nBJ9SpZtGuv05V-d2nUP8VYfDJW8fQEzFYDM8ZrvAHryzklTQiPgf2z5OeVzH5OxtoPGc0hdFovKJ4EttZbvjVM-psNPJ50VPXHua1XRpEdHHuvXgRjijOHXxkiKsbzEHZ2c3qO63b_Y3Y0Zn_JqPCzMEFb4FJ9Voxh_6ujYwjvAbrLcB3iE966z2tp12yD0Ri7TF8zgizyEhogmOR3ewhHsH5Mzqssmuk3KnPN_ruHvsfkVij5goi0RjZN82YdqzvcWRwFPGqANsfxke5BJlh7s76jG8K_04SORwDV4sq9502J1kzeivYI6opz32CTuE0JGA1yj-9uihL5ELDb4MTTM-6G79DSgbX2iCaRJ4CuUa8q3ifJtJkco0hwREsivLRJbZepMAhyyp51EqRU2nDjj1DLjxpYJ3WeGMQNnZIAM4vT8Eev0RGts-2SPJEvpStl_9qipElYtcrmSP2XBF27e2M7YDv-qdKT4dj_a-B_qY2PB8l64OhdoqwNB2CmDDBd8kUkmR5xte57XI8mxlZAnGF9HmKeL8OuW4MBCG88GZeMTJRF8vw6an3c3L6t-D1AVPOE_SRHDEt07iXS7LbV2nKV9v6p1KMWHQSG3iYY5bt1-5YjBZ9ntP41374C-b0nskLsAQEyIMOhgo6OuK4Wx8mJpznI_sA2HgqoffexovwwAz1uPdFU4cXg14iwHsnzr453k>52971</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
SROA sub-vector memcpy w/subsequent load loses the store
</td>
</tr>
<tr>
<th>Labels</th>
<td>
miscompilation,
llvm:optimizations
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nunoplopes
</td>
</tr>
</table>
<pre>
Test minimized from Transforms/SROA/vector-promotion.ll:
```llvm
define void @test_subvec_memcpy(i8* %f) {
%a = alloca <4 x float>, align 16
%a.gep2 = getelementptr <4 x float>, <4 x float>* %a, i32 0, i32 2
%a.cast2 = bitcast float* %a.gep2 to i8*
%a.gep3 = getelementptr <4 x float>, <4 x float>* %a, i32 0, i32 3
%a.cast3 = bitcast float* %a.gep3 to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %a.cast3, i8* %f, i32 4, i1 false)
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %f, i8* %a.cast2, i32 8, i1 false)
; comment the load and it compiles fine
%ret = load <4 x float>, <4 x float>* %a, align 16
ret void
}
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i32, i1 immarg)
```
With the load we get (`opt -sroa`):
```llvm
define void @test_subvec_memcpy(i8* %f) {
%a.12.f.sroa_cast = bitcast i8* %f to float*
%a.12.copyload = load float, float* %a.12.f.sroa_cast, align 1
%a.12.vec.insert = insertelement <4 x float> undef, float %a.12.copyload, i32 3
%a.8.f.sroa_cast = bitcast i8* %f to <2 x float>*
%a.8.vec.extract = shufflevector <4 x float> %a.12.vec.insert, <4 x float> poison, <2 x i32> <i32 2, i32 3>
store <2 x float> %a.8.vec.extract, <2 x float>* %a.8.f.sroa_cast, align 1
ret void
}
```
The store to `%f` is gone! Without the load, there's no miscompilation.
The culprit is likely this: https://github.com/llvm/llvm-project/commit/21eb4e96c2268a31a19e0e307bb0ab8450e2e80f
cc @chandlerc @cdevadas @rotateright @LemonBoy @aeubanks
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1Vl2PqzYQ_TXkxVoEdgLkgYf96H2qVKldqY8rA0PiXoOpbXZv-us7Y0hCPu5Vt2qlKBibmTkzc85AZZpD-QrOs071qlN_QcNaazr2amXvWmM7F_Evv_36yyNe3qH2xj4MeG68Mn2sdSQeo-QlSo7_WTL9tH7vpq0GWtUDezeqYdE68RjrzY0V-nrroKuHQ8QLVUT8kUV800Z8y6L8aTJltCVZJF6Y1NrUtHxes2-s1Ub6SPwU8Wc8UbuepdnSJN7BwIPdDjxo6KD3g7f3zG-2Ag5JR0pwlhwX_MJ_LZ2fAlTK083sYLae4nvDQmLXyMR_i0zcIBM_RiZukNVY3lOHqHXx1Jp4SFQx_WGkZaPmQAHDonkTonVYpKyV2gF29N-HaS8CzHU_him-EyYST6w2HZWW-T0wzL9hsm-Y8rQ_KA2OESkXhbPgQ9HCs59rxjUByRUlOSsif1kKpIFaSwufqEJvMIB0eK3l4Ee0_bDKg-n14Vyc24csyOb0jOBzqVTXSbs71eok1yXE35Xfn-v2AcRUTLbAx8zg2YOzRpIJOhH_o-zjlMdtTMHeAo2XlD4bEpWPBL-2rs1wmPs5N3Z-8vlKE5eRFj299ojoY9U7sBOcaTmr-JoibOyxBqdgN6juy7f4hzljMH7Jxys3BBW-eSvryY3bj22rYRrhN1hvE7xDejYY5Uw_n1B4IhZZi-dpRJ5SQkQzHIfh4BruHZALr9ciuyzKnfZ8T3H32P2KxJ4wURWJxsi-LGHKsZ3BkcBTxkgBZjwPDwqJa4unOWkM35VuGiQyvAbPnutRD6hO8qbVV9AHtFMOdcL23g-0wNco_nYYYayQCx3eBNFMF3q3_g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