<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
.MsoPapDefault
        {mso-style-type:export-only;
        line-height:115%;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Hello Dave,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The problem is that this is not well-formed IR.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">A branch instruction is a terminator, and may only appear in the end of a basic block, never in the middle. You’ll need to split that basic block into two.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Michael<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]
<b>On Behalf Of </b>Dave Pitsbawn<br>
<b>Sent:</b> Monday, April 06, 2015 06:54<br>
<b>To:</b> LLVM Developers Mailing List<br>
<b>Subject:</b> [LLVMdev] Unreachable br in IR but still seems to be executed<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal" style="line-height:115%">I'm trying to implement a continue statement like in C<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%">                if (i % 2 == 0)<br>
                {<br>
                    i = i + 1;<br>
                    continue;<br>
                }<br>
                else<br>
                {<br>
                    i = i + 1;<br>
                }<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%">My code generates IR like this, because of how I visit my AST, so when I encounter a continue or break statement I go and find the corresponding while.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%">I was hoping LLVM would do the right thing which is ignore the unreachable IR (br label %if.end). But it seems to somehow get to execute statements after my br<o:p></o:p></p>
</div>
<p>I've marked it with "SHOULD NOT HAPPEN"<o:p></o:p></p>
<div>
<p class="MsoNormal" style="line-height:115%">define i32 @Main() {<br>
entry:<br>
  %i = alloca i32<br>
  %loopCounter = alloca i32<br>
  store i32 0, i32* %i<br>
  store i32 0, i32* %loopCounter<br>
  br label %while.cond<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%">while.cond:                                       ; preds = %if.end, %if.then, %<br>
entry<br>
  %0 = load i32* %i<br>
  %cmptmp = icmp slt i32 %0, 100<br>
  br i1 %cmptmp, label %while.body, label %while.end<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%">while.body:                                       ; preds = %while.cond<br>
  %1 = load i32* %i<br>
  %modtmp = srem i32 %1, 2<br>
  %cmptmp1 = icmp eq i32 %modtmp, 0<br>
  br i1 %cmptmp1, label %if.then, label %if.else<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%">while.end:                                        ; preds = %while.cond<br>
  %2 = load i32* %loopCounter<br>
  ret i32 %2<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%">if.then:                                          ; preds = %while.body<br>
  %3 = load i32* %i<br>
  %add = add i32 %3, 1<br>
  store i32 %add, i32* %i<br>
  br label %while.cond<br>
  %4 = load i32* %I                      <----------- SHOULD NOT HAPPEN<br>
  %sub = sub i32 %4, 1<br>
  store i32 %sub, i32* %i<br>
  br label %if.end<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%">if.else:                                          ; preds = %while.body<br>
  %5 = load i32* %i<br>
  %add2 = add i32 %5, 1<br>
  store i32 %add2, i32* %i<br>
  br label %if.end<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%">if.end:                                           ; preds = %if.else, %if.then<br>
  %6 = load i32* %loopCounter<br>
  %add3 = add i32 %6, 1<br>
  store i32 %add3, i32* %loopCounter<br>
  br label %while.cond<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:115%">after_ret:                                        ; No predecessors!<br>
  ret i32 0<br>
}<o:p></o:p></p>
</div>
</div>
</div>
<p>---------------------------------------------------------------------<br>
Intel Israel (74) Limited</p>

<p>This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.</p></body>
</html>