<html><body><p>Hi David,<br><br>Thank you.<br>I just submitted a bug report 27024 (PGO instrumentation profile data is not reflected in correct basic blocks).<br><br>Thank you,<br>--Toshio<br><br><img width="16" height="16" src="cid:1__=C6BBF5EDDF8ECA588f9e8a93df938690918cC6B@" border="0" alt="Inactive hide details for Xinliang David Li ---2016/03/22 12:04:10---On Mon, Mar 21, 2016 at 7:19 PM, Toshio Suganuma via llvm-"><font color="#424282">Xinliang David Li ---2016/03/22 12:04:10---On Mon, Mar 21, 2016 at 7:19 PM, Toshio Suganuma via llvm-dev < llvm-dev@lists.llvm.org> wrote:</font><br><br><font size="2" color="#5F5F5F">From:        </font><font size="2">Xinliang David Li <xinliangli@gmail.com></font><br><font size="2" color="#5F5F5F">To:        </font><font size="2">Toshio Suganuma/Japan/IBM@IBMJP</font><br><font size="2" color="#5F5F5F">Cc:        </font><font size="2">llvm-dev <llvm-dev@lists.llvm.org>, Rong Xu <xur@google.com></font><br><font size="2" color="#5F5F5F">Date:        </font><font size="2">2016/03/22 12:04</font><br><font size="2" color="#5F5F5F">Subject:        </font><font size="2">Re: [llvm-dev] Instrumented BB in PGO</font><br><hr width="100%" size="2" align="left" noshade style="color:#8091A5; "><br><br><br><br><br><font size="4">On Mon, Mar 21, 2016 at 7:19 PM, Toshio Suganuma via llvm-dev <</font><a href="mailto:llvm-dev@lists.llvm.org" target="_blank"><u><font size="4" color="#0000FF">llvm-dev@lists.llvm.org</font></u></a><font size="4">> wrote:</font><ul><font size="4">Hello,<br><br>I have a question regarding PGO instrumented BBs (I use IR-level instrumentation).<br><br>It seems that instrumented BBs do not match between the two compilations for profile-gen and profile-use for some cases. Here is an example from SPECcpu 2006 lbm (a simple case consisting of just two modules).<br>In the first compilation, we have 5 instrumentation points for the main function as follows:<br></font><font size="4" face="Consolas"><br>$ opt -pgo-instr-gen -instrprof _all_combined.bc -o _all_combined_inst.bc -debug-only=pgo-instrumentation<br>Dump Function main Hash: 61483163021 after CFGMST<br>Number of Basic Blocks: 10<br>BB: FakeNode Index=0<br>BB: if.then Index=5<br>BB: for.body Index=4<br>BB: </font><a href="http://for.body.lr.ph/" target="_blank"><u><font size="4" color="#0000FF" face="Consolas">for.body.lr.ph</font></u></a><font size="4" face="Consolas"> Index=3<br>BB: entry Index=1<br>BB: for.inc Index=8<br>BB: if.then5 Index=7<br>BB: if.end Index=6<br>BB: for.end Index=2<br>BB: for.end.loopexit Index=9<br>Number of Edges: 14 (*: Instrument, C: CriticalEdge, -: Removed)<br>Edge 0: 8-->4 c W=247031<br>Edge 1: 6-->8 c W=159375<br>Edge 2: 4-->6 *c W=127500<br>Edge 3: 1-->2 c W=4500<br>Edge 4: 4-->5 W=127<br>Edge 5: 5-->6 * W=127<br>Edge 6: 6-->7 W=95<br>Edge 7: 7-->8 * W=95<br>Edge 8: 0-->1 W=12<br>Edge 9: 2-->0 * W=12<br>Edge 10: 3-->4 W=8<br>Edge 11: 9-->2 W=8<br>Edge 12: 1-->3 W=7<br>Edge 13: 8-->9 * W=7<br>Split critical edge: 4 --> 6<br>Adding Instrumentation in BB Name=for.body.if.end_crit_edge<br>Adding Instrumentation in BB Name=if.then<br>Adding Instrumentation in BB Name=if.then5<br>Adding Instrumentation in BB Name=for.end<br>Adding Instrumentation in BB Name=for.end.loopexit</font><font size="4"><br><br>After a training run, we get profile data for the main function as follows, but these count values are put into incorrect BBs in the second compilation.<br>Block counts: [0, 300, 4, 1, 1]<br></font><font size="4" face="Consolas"><br>$ opt -analyze -pgo-instr-use _all_combined.bc -debug-only=pgo-instrumentation<br>Dump Function main Hash: 61483163021 after CFGMST<br>Number of Basic Blocks: 10<br>BB: FakeNode Index=0<br>BB: </font><a href="http://for.body.lr.ph/" target="_blank"><u><font size="4" color="#0000FF" face="Consolas">for.body.lr.ph</font></u></a><font size="4" face="Consolas"> Index=3<br>BB: if.end Index=6<br>BB: entry Index=1<br>BB: if.then Index=5<br>BB: for.body Index=4<br>BB: for.end.loopexit Index=9<br>BB: for.inc Index=8<br>BB: if.then5 Index=7<br>BB: for.end Index=2<br>Number of Edges: 14 (*: Instrument, C: CriticalEdge, -: Removed)<br>Edge 0: 8-->4 c W=247031<br>Edge 1: 6-->8 c W=159375<br>Edge 2: 4-->6 *c W=127500<br>Edge 3: 1-->2 c W=127058<br>Edge 4: 0-->1 W=135<br>Edge 5: 2-->0 * W=135<br>Edge 6: 4-->5 W=127<br>Edge 7: 5-->6 * W=127<br>Edge 8: 6-->7 W=95<br>Edge 9: 7-->8 * W=95<br>Edge 10: 3-->4 W=8<br>Edge 11: 9-->2 W=8<br>Edge 12: 1-->3 W=7<br>Edge 13: 8-->9 * W=7<br>5 counts<br>0: 0<br>1: 300<br>2: 4<br>3: 1<br>4: 1<br>SUM = 306<br>Split critical edge: 4 --> 6<br>Setting BB Name=for.body.if.end_crit_edge with CountValue=0<br>Setting BB Name=for.end with CountValue=300<br>Setting BB Name=if.then with CountValue=4<br>Setting BB Name=if.then5 with CountValue=1<br>Setting BB Name=for.end.loopexit with CountValue=1</font><font size="4"><br><br>The CountValue 300 should go to the BB=if.then (Index 5), not for.end (Index 2). Actually because of this incorrect setting, the entry count of the main function is set 300, instead of 1 (after populating the count values).<br>The reason for this problem is that CFGMST edges are ordered in a different way due to different weight values (edges 0 --> 1 and 2 --> 0 get W=12 in the first compilation, while they get W=135 in the second compilation). The weight values are computed based on block frequency info and branch probability info, but somehow they produce different values between the two compilations.</font></ul><br><br><font size="4">Different  BFI produced for otherwise identical compilation is a bug we should fix (can cause other problems too). Can you file a bug about it? </font><br><br><font size="4">thanks,</font><br><br><font size="4">David</font><br><font size="4"> </font><ul><font size="4"><br>How can we assume that CFGMST is constructed in the same way between the two compilations so that we can always set profile results into correct basic blocks?<br><br>Thank you,<br>--Toshjio</font><br><font size="4"><br>_______________________________________________<br>LLVM Developers mailing list</font><u><font size="4" color="#0000FF"><br></font></u><a href="mailto:llvm-dev@lists.llvm.org"><u><font size="4" color="#0000FF">llvm-dev@lists.llvm.org</font></u></a><u><font size="4" color="#0000FF"><br></font></u><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank"><u><font size="4" color="#0000FF">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</font></u></a><font size="4"><br></font></ul><br><BR>
</body></html>