<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJylVU1v4zYQ_TXyhbBgS7EtH3zYxA2QomiB7Pa8oKSRxDVFCiTlj_76vqGcxEmDAosFDJkiZ4Zv3rwZlba-7J5HY5RphTI-VLYvlSFhjQgdCTrLftCEo0YZFUhoawcvkqyQpobF6EXlpO_Iw0RI78kFUY5K1z7JtqkQ3xDEkfSIpzwcZBAnEqVWptYXUUljjaqkVv9QvE-Z4ABDVTjSWgQrnp7FSYXOjkFUHVUHBoptTzBuPvh00gtpLmL05HH3kxG99fCTeE-yB1gDw8mOuhYlwRKuxlZkguiVD_JAbFTiJq9MNQEazcHYkxF2IMcplyOAkzgQDT4aRJxaHcHVkcwrVobANKmU0mj3IUAVbz9aDUfpShWcdBfRkRzEyYFopu8VsiM_6jBRbN5qUV0qRLKNaMkgeKA3PkEbe9ekCduGTtgAI8linyy-TM-_pgr70TWyote78JNicBTCBTTE4jfqzKlQ2qZC1vXEi6epHleczNoTgvmBqljiTh4nBr3sCQFtqakXjXWi5xJZHLmb0iF_43Hax8LdBpKORK28o1a6mqv_gUlPCBhUNdHDu1XHpAwaacWyszFHYTFAdEmWtUiPQ8mTvMSSCRWwPWlmkA7hRi0dO3-WFDiKWb3rCjDnR5oyZNVxllB-jYq80_XUYPV0rYzV_m9WH2qVrBfX3_Sa34vnv_9M8i9wC2J-27jzryLJH5Dkyk_GQTqkK2oZpJYX1maS75kEmveIQPMh2yywyLP44Nfl-1dere_iY65eFk3BTsusmJuCF-sXH5x9jduKt6PRMlryI8e972CBFpbYFdK5WH-H_7Xp5pgS43nemvHVa3rWVGkuqMozkdwttD72KVxTeTxn6dDbY-8PJRQLImBxFgqr3yBU8T5Iw3wdrao5CFoufHRhFmX029xPToK3jhFubPyfQvAWbnXP2V7T5ORgGff3L9egASO0K-LN_lMhPFqoRZw6FUf0ESmoVkY5dSEMHown2SN-LbQ2lik0gpffR63kH9K0WP_gNf6jdtEsj3mRZes4t6dZwB08ONXzdKokd71tpjEe5_40NuzYdtwePbrJ2IB5A31jSPPgiN2C9WhKbavD5Iue6VniWfHtfo_MZ_Uur7f5Vs7kiHBuhwGEBvOz0end_6TCvF__5hgxP9Cmt8mscoh31u3WyGpbFJuGKloUdLehLTW0Lar1otwuCznTsiTtd6gLisHTMobgwqz2s19HoHbZIssWy2Wx3NwtV9u0aNarhazv8lVeFk0mISFMMaXTKCTr2pnbxZDl2HrWFz5P_u0Q31nVguQIGAiDCpp2D1wQiAFfoZvv6vRhf5k-ceh8PnL8LKLeRcj_AvVnoOY>53272</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Crash when canonicalizing intrinsic with writing operand bundles
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
preames
</td>
</tr>
</table>
<pre>
Running instcombine on the example infinite loops (and thus crashes in assert builds). The reason is that we blindly canonicalize the intrinsic call to IR without checking to see if the intrinsic has any uses. In most cases, this would be an innocent mistake, but since the unknown operand bundle keeps the call live even without uses (i.e. the operand bundle can involve arbitrary heap writes), this results in an infinite cycle of generate canonical IR, delete new IR.
On the surface, this is a pretty simple fix (e.g. add the use check), but I suspect we have the same problem for many other intrinsic transforms. I suspect we are disregarding operand bundle semantics in a bunch of places, and are mostly "getting away with it". In particular, I suspect we have this same infinite loop issue for most any readnone intrinsic combined with a writing operand bundle.
```
; RUN: opt -instcombine -S < %s
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128-ni:10:11:12:13"
target triple = "x86_64-unknown-linux-gnu"
declare i32 @llvm.x86.avx2.pmovmskb(<32 x i8>)
define void @test(<32 x i8> %a) {
%v = call i32 @llvm.x86.avx2.pmovmskb(<32 x i8> %a) [ "unknown"() ]
ret void
}
```
Found while investigating https://github.com/JuliaLang/julia/issues/38226. This is the primary cause of that crash, though we may not need to fix this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