<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 20, 2021 at 12:52 PM Vijay via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>I'm generating IR for a factorial function that looks like below. When I call the verifyFunction, it fails validation with the error message Terminator found in the middle of a basic block. label %then</div></div></blockquote><div><br></div><div>Because there shouldn't be a terminator instruction (in this case the return instruction) in the middle of a basic block. I see no problem with the verifier's decision here.</div><div>I think the %then block should only contain the return instruction. The `br label %ifcont` instruction is redundant because the control flow will not proceed anyway beyond the return instruction once %then block is taken.</div><div><br></div><div>-Min</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>The resulting IR still works fine but I'm not sure if the code generation should be done in a better way for the if/then block below.</div><div><br></div><div>Thanks in advance,</div><div>Vijay</div><div><br></div>define double @fact(double %n) {<br>entry:<br>  %n1 = alloca double, align 8<br>  store double %n, double* %n1, align 8<br>  %n2 = load double, double* %n1, align 8<br>  %cmptmp = fcmp ule double %n2, 1.000000e+00<br>  %booltmp = uitofp i1 %cmptmp to double<br>  %ifcond = fcmp one double %booltmp, 0.000000e+00<br>  br i1 %ifcond, label %then, label %ifcont<br><br>then:                                             ; preds = %entry<br>  ret double 1.000000e+00<br>  br label %ifcont<br><br>ifcont:                                           ; preds = %then, %entry<br>  %n3 = load double, double* %n1, align 8<br>  %n4 = load double, double* %n1, align 8<br>  %subtmp = fsub double %n4, 1.000000e+00<br>  %calltmp = call double @fact(double %subtmp)<br>  %multmp = fmul double %n3, %calltmp<br>  ret double %multmp<br>}<br>Validating function...<br>Terminator found in the middle of a basic block!<br>label %then<br>Validation failed<br><div><br></div></div>
_______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Min-Yih Hsu</div><div>Ph.D Student in ICS Department, University of California, Irvine (UCI).<br></div></div></div></div>