<body><div style="font-family: 'PingFang SC'; font-size: 10.5pt;">If so, I think we could have two choices:<div><br></div><div>1. Remove <span style="font-family: Arial;">FuncInfo.MBB->getBasicBlock()->size() > 1</span></div><div><font face="Arial"><br></font></div><div><font face="Arial">We could not stop at any continue statement, but we can have the same behavior  whether the continue statement is the only one statement in the for loop body or not.</font></div><div><font face="Arial"><br></font></div><div><font face="Arial">2. Remove whole if condition : </font><span style="font-family: Arial;">if (FuncInfo.MBB->getBasicBlock()->size() > 1 &&</span><br style="font-family: Arial;"><span style="font-family: Arial;">     FuncInfo.MBB->isLayoutSuccessor(MSucc)) </span></div><div><font face="Arial"><br></font></div><div><font face="Arial">We keep the unconditional branch even its successor is the basic block of nature layout. Then we can stop at any continue statement whether it is only one in the for loop body or not.</font></div><div><font face="Arial"><br></font></div><div><font face="Arial">These two choices can make our user understandab, otherwise compiler users will be strange why compiler can sometimes stop at continue statement , sometimes can not. We need to fix and unify it.</font></div><div><font face="Arial"><br></font></div><div><font face="Arial">Wish to hear more advice and better solution.</font></div><div>
<br>
<div class="-eMc-quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; display: block;">
        <span dir="ltr"><
                <a href="mailto:dblaikie@gmail.com" target="_blank">David Blaikie</a>> 在 2017-07-25 22:32:42 写道:
        </span>
        <br>
        <blockquote class="" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; display: block;">
                <div dir="ltr">
                        
<div dir="ltr">
<br>
<br>
<div onclick="emc_toggle_blockquote_visibility(this);"> </div>
<div class="" style="display: block;">
<div dir="ltr">On Mon, Jul 24, 2017 at 8:17 PM Frozen via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
</div>
<blockquote class="" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; display: block;">
<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial">
<div>
<span style="font-family:Arial">    This email is related with the code of commit:</span> <a href="http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20120409/140650.html" style="font-family:Arial;text-decoration:underline" target="_blank"><span style="font-family:Arial">http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20120409/140650.html</span></a><span style="font-family:Arial">. This commit will let our unconditional branch instruction not be deleted when its successor is the nature layout and its basic block's instruction only one instruction.</span>
</div>
<div><br></div>
<span style="font-family:Arial">  However, I have some concerns about it, especially in the debug mode. Let me show you some example:<br>
<br>
[</span><span style="font-family:Arial"><span style="font-family:Arial">1.cpp</span>]<br>
<a href="http://1.int" target="_blank">1.int</a> main()<br>
2.{<br>
3.  int i;<br>
4.<br>
5.  for (i = 0; i < 256; i++)<br>
6.  {<br>
7.    continue;<br>
8.  }<br>
9.}<br>
[/<code>1.cpp</code>]<br>
<br>
When we use clang++ to compile it and use gdb to debug it.<br>
<br>
[Debug Part]<br></span>
<pre><code class="m_4318320555433844435language-text"><span style="font-family:Arial">(gdb) b main
Breakpoint 1 at 0x100000f8b: file 1.cpp, line 5.
(gdb) r
Thread 2 hit Breakpoint 1, main () at 1.cpp:5
5         for (i = 0; i < 256; i++)
(gdb) n
7           continue;
(gdb) n
5         for (i = 0; i < 256; i++)
(gdb) n
7           continue;
(gdb) n
5         for (i = 0; i < 256; i++)
(gdb) n
7           continue;<br></span></code><code class="m_4318320555433844435language-llvm"><span style="font-family:Arial">[/Debug Part]</span></code><br><code class="m_4318320555433844435language-llvm"><span style="font-family:Arial">This behavior is as expected. <br>[LLVM Part]<br>for.cond:                                         ; preds = %for.inc, %entry<br>  %0 = load i32, i32* %i, align 4, !dbg !17<br>  %cmp = icmp slt i32 %0, 256, !dbg !19<br>  br i1 %cmp, label %for.body, label %for.end, !dbg !20<br><br>for.body:                                         ; preds = %for.cond<br><b>  br label %for.inc, !dbg !21  ;  it will keep the debug information !21</b><br><br>for.inc:                                          ; preds = %for.body<br>  %1 = load i32, i32* %i, align 4, !dbg !23<br>  %inc = add nsw i32 %1, 1, !dbg !23<br>  store i32 %inc, i32* %i, align 4, !dbg !23<br>  br label %for.cond, !dbg !24, !llvm.loop !25<br><br>for.end:                                          ; preds = %for.cond<br>  %2 = load i32, i32* %retval, align 4, !dbg !27<br>  ret i32 %2, !dbg !27<br><br>!21 = !DILocation(line: 7, column: 5, scope: !22); <br></span></code><code class="m_4318320555433844435language-llvm"><br></code><code><span style="font-family:Arial">However, let us see another source code example.<br><br>[2.cpp]</span></code><br><code><code class="m_4318320555433844435language-c"><span style="font-family:Arial"><a href="http://1.int" target="_blank">1.int</a> main()
2.{
3.  int i;
4.
5.  for (i = 0; i < 256; i++)
6.  {
7.    i++;
8.    continue;
9.  }
10.}</span></code></code><code><span style="font-family:Arial"><br>[/2.cpp]<br><br>If we debug it, we can see that:<br>[Debug Part]<br></span></code><br><code><code class="m_4318320555433844435language-text"><span style="font-family:Arial">(gdb) b main
Breakpoint 1 at 0x100000f7b: file 2.cpp, line 5.
(gdb) r
Thread 2 hit Breakpoint 1, main () at 2.cpp:5
5         for (i = 0; i < 256; i++)
(gdb) n
7           i++;
(gdb) n
5         for (i = 0; i < 256; i++)
(gdb) n
7           i++;
(gdb) n
5         for (i = 0; i < 256; i++)
(gdb) n
7           i++;
(gdb) n
5         for (i = 0; i < 256; i++)<br>[/Debug Part]<br><br><b>We can not stop at continue statement of line 8! </b><br>Let us see the llvm ir:<br>[LLVM]<br></span></code></code><code><code class="m_4318320555433844435language-text"><code class="m_4318320555433844435language-llvm"><span style="font-family:Arial">for.cond:                                         ; preds = %for.inc, %entry
  %0 = load i32, i32* %i, align 4, !dbg !17
  %cmp = icmp slt i32 %0, 256, !dbg !19
  br i1 %cmp, label %for.body, label %for.end, !dbg !20

for.body:                                         ; preds = %for.cond
  %1 = load i32, i32* %i, align 4, !dbg !21
  %inc = add nsw i32 %1, 1, !dbg !21
  store i32 %inc, i32* %i, align 4, !dbg !21
<b>  br label %for.inc, !dbg !23;  ; // Here is continue statement, but its basic block instructions size > 1 and its successor is nature layout, which will be deleted</b>

for.inc:                                          ; preds = %for.body
  %2 = load i32, i32* %i, align 4, !dbg !24
  %inc1 = add nsw i32 %2, 1, !dbg !24
  store i32 %inc1, i32* %i, align 4, !dbg !24
  br label %for.cond, !dbg !25, !llvm.loop !26

for.end:                                          ; preds = %for.cond
  %3 = load i32, i32* %retval, align 4, !dbg !28
  ret i32 %3, !dbg !28

!23 = !DILocation(line: 8, column: 5, scope: !22)</span></code></code></code>
</pre>
As comment, <code><code class="m_4318320555433844435language-text"><code class="m_4318320555433844435language-llvm"><span style="font-family:Arial"><b>br label %for.inc, !dbg !23;</b></span></code></code></code> will be deleted and we can not get right debug behavior.<br>
<br>
So I propose one changeset, if we have debug information, we don't eliminate the unconditional branch instruction, otherwise we eliminate it.<br>
</div>
</blockquote>
<div>
<br>
It is a fairly strong goal of LLVM that the presence or absence of debug information should not affect the optimization decisions/code of the final binary, unfortunately.<br>
 </div>
<blockquote class="" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; display: block;">
<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial">
<br>
 /// (fall-through) successor, and update the CFG.<br>
 void FastISel::fastEmitBranch(MachineBasicBlock *MSucc,<br>
                               const DebugLoc &DbgLoc) {<br>
-  if (FuncInfo.MBB->getBasicBlock()->size() > 1 &&<br>
-      FuncInfo.MBB->isLayoutSuccessor(MSucc)) {<br>
-    // For more accurate line information if this is the only instruction<br>
-    // in the block then emit it, otherwise we have the unconditional<br>
+  if (FuncInfo.MBB->isLayoutSuccessor(MSucc) && !DbgLoc) {<br>
+    // For more accurate line information if this is in debug mode<br>
+    // then emit it, otherwise we have the unconditional<br>
     // fall-through case, which needs no instructions.<br>
   } else {<br>
     // The unconditional branch case.<br>
<br>
Wish to hear more comments and feedbacks.<br>
</div>
<br>
<br>
<p><span title="neteasefooter"> </span></p>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote>
</div>
</div>

                </div>
        </blockquote>
</div>
                        </div></div></body>