Vijay via llvm-dev
2021-Oct-20 19:49 UTC
[llvm-dev] verifyFunction fails validation with Terminator found in the middle of a basic block
Hi, 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 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. Thanks in advance, Vijay define double @fact(double %n) { entry: %n1 = alloca double, align 8 store double %n, double* %n1, align 8 %n2 = load double, double* %n1, align 8 %cmptmp = fcmp ule double %n2, 1.000000e+00 %booltmp = uitofp i1 %cmptmp to double %ifcond = fcmp one double %booltmp, 0.000000e+00 br i1 %ifcond, label %then, label %ifcont then: ; preds = %entry ret double 1.000000e+00 br label %ifcont ifcont: ; preds = %then, %entry %n3 = load double, double* %n1, align 8 %n4 = load double, double* %n1, align 8 %subtmp = fsub double %n4, 1.000000e+00 %calltmp = call double @fact(double %subtmp) %multmp = fmul double %n3, %calltmp ret double %multmp } Validating function... Terminator found in the middle of a basic block! label %then Validation failed -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211020/f762255d/attachment.html>
Min-Yih Hsu via llvm-dev
2021-Oct-20 20:18 UTC
[llvm-dev] verifyFunction fails validation with Terminator found in the middle of a basic block
On Wed, Oct 20, 2021 at 12:52 PM Vijay via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Hi, > > 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 >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. 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. -Min> > 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. > > Thanks in advance, > Vijay > > define double @fact(double %n) { > entry: > %n1 = alloca double, align 8 > store double %n, double* %n1, align 8 > %n2 = load double, double* %n1, align 8 > %cmptmp = fcmp ule double %n2, 1.000000e+00 > %booltmp = uitofp i1 %cmptmp to double > %ifcond = fcmp one double %booltmp, 0.000000e+00 > br i1 %ifcond, label %then, label %ifcont > > then: ; preds = %entry > ret double 1.000000e+00 > br label %ifcont > > ifcont: ; preds = %then, %entry > %n3 = load double, double* %n1, align 8 > %n4 = load double, double* %n1, align 8 > %subtmp = fsub double %n4, 1.000000e+00 > %calltmp = call double @fact(double %subtmp) > %multmp = fmul double %n3, %calltmp > ret double %multmp > } > Validating function... > Terminator found in the middle of a basic block! > label %then > Validation failed > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- Min-Yih Hsu Ph.D Student in ICS Department, University of California, Irvine (UCI). -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211020/0f92a49d/attachment.html>