<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/135812>135812</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Fix Loop Transformations to Preserve Block Frequencies
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
jdenny-ornl
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jdenny-ornl
</td>
</tr>
</table>
<pre>
In LLVM IR, a loop’s latch block can have branch weight metadata that encodes an estimated trip count that is derived from application profile data. Initially, the loop body’s block frequencies agree with the estimated trip count, as expected. However, sometimes loop transformations adjust those branch weights in a way that correctly maintains the estimated trip count but that corrupts the block frequencies.
[This RFC](https://discourse.llvm.org/t/rfc-fix-loop-transformations-to-preserve-block-frequencies/85785) explains the problem in more detail and proposes a solution, which is still under discussion.
[PR #128785](https://github.com/llvm/llvm-project/pull/128785) drafts a fix for the LoopPeel case. Solutions for LoopUnroll cases are already under development.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUlM-OpDYQh5_GXEogMH8aDhx2doMy0kQaTTa5G7toPDE2sYvu6bePTHe2R5PJYaWWWqJs1_eVfyBC0EeL2LP6gXH-qtDaS-q8NYxzVn9LxEaz8_27QjI6dekfLTw9_fkbPL4w_hUEGOdW9gtnbc66LoARJGcYjZN_gRQWZnFCGL2wcoYz6uNMsCAJJUgAzYIArXQKAwgLGEgvglABeb2CdJul6yIdQKHXJ1QwebeAWFejpSDtLKzeTdogxCMzeLSatDDmEuloxp0PIvk7yCve5PHvDa3UsfvRI8JZ07xv-oxk1w2AbytKQpXBr-6MJ_TxeXALkl4wXNuRFzZMzi87YQChXrcQVVz4MIwA2oKAs7hcRaXzHiWZCyxCWxLahv8FgnGj-65tpevS_8hlLP8Sf_XD91kHeBm-svob4-1MtAZWfmF8YHxQOki3-YCZMaclc_7I-ECMD36S6aTf0miWfjBLyaWrx4D-hOneOH3XmPGhrQ9tzXgXx2Z-2KzejQaX6L44j6CQhDYgrIql1YV4IxCc2WKXOODzrOUcYxBIGwObVeghIm8haGfvis8vwHhZ8Db2_UTzqGnexky6hfEhmt7-0tW7V5RReN2MYXy4ncE7UF5MFIkm_QaT87vDk3PrM6IBKQJmAL_faMO-Ilb_sN6Zaz2A8AjCeBTq8i89ntC4dUFLWaL6UnVlJxLsi0NVHcq6aJtk7g9jN-Zc4FTxujs0xaiwqUve5m01yaYpE93znNd5VdRFU3ZVk7XjWIqmKbGqMS9VzqocF6HNj2tNdAgb9kVZtwVPjBjRhNtX4DqP_fX3_T6VcTsGVuVGBwr3E0iTwX7Qb7snfP8Qd3LwfAsFPOxpHO6hSDZv-p--k505BuqGfer5PwEAAP__GEOhBQ">