<div dir="ltr">Your IR for the "if" doesn't seem to match what you've pasted, there are some additional load/stores which I don't see in your source. Maybe you're complaining about the "br label %if.end" (the one beyond the "br label %while.cond")<div><br></div><div>A couple of ways to fix that:</div><div><br></div><div>(1) Don't generate that extra br :-)</div><div><br></div><div>(2) But maybe you want to faithfully represent the source code, which is a noble cause and in that case I suggest adding a "fake" basic block, perhaps call it "unreachable" and position the IRBuilder at that point, and if there are instructions from that point on they get stuffed in that unreachable BB. At this point you can ASSERT to your user, or maybe it's just a warning and you can simply apply the CFG Simplification Pass and call it a day.</div><div><br></div><div>HTH,</div><div>Mukul</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 5, 2015 at 8:54 PM, Dave Pitsbawn <span dir="ltr"><<a href="mailto:dpitsbawn@gmail.com" target="_blank">dpitsbawn@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I'm trying to implement a continue statement like in C</div><div><br></div><div>                if (i % 2 == 0)<br>                {<br>                    i = i + 1;<br>                    continue;<br>                }<br>                else<br>                {<br>                    i = i + 1;<br>                }</div><div><br></div><div>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.</div><div><br></div><div>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<br></div><p>I've marked it with "SHOULD NOT HAPPEN"</p><div>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</div><div>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</div><div>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</div><div>while.end:                                        ; preds = %while.cond<br>  %2 = load i32* %loopCounter<br>  ret i32 %2</div><div>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</div><div>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</div><div>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</div><div>after_ret:                                        ; No predecessors!<br>  ret i32 0<br>}</div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>