<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I have some LLVM IR after the optimization passes defined in <span class="Apple-style-span" style="color: rgb(65, 27, 127); font-family: Menlo; font-size: 11px; ">createStandardModulePasses <span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Arial; font-size: medium; ">with the optimization level set to 3. It contains what appears to me to be an easily optimizable branch statement.</span></span><div><br></div><div><span class="Apple-style-span" style="color: rgb(65, 27, 127); font-family: Menlo; font-size: 11px; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Arial; font-size: medium; "></span></span>In particular, note in the code below that at the end of the "loop" BasicBlock that there is a conditional branch where in the false case, it branches to the label "<span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; font-weight: bold; ">%loop.endif_crit_edge<span class="Apple-style-span" style="font-family: Arial; font-size: medium; font-weight: normal; ">", this label contains only the single statement "<span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; font-weight: bold; ">br label %endif<span class="Apple-style-span" style="font-family: Arial; font-size: medium; font-weight: normal; ">", Therefore, the conditional branch could simply branch directly to the "<span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; font-weight: bold; ">%endif<span class="Apple-style-span" style="font-family: Arial; font-size: medium; font-weight: normal; ">" label in one step instead of taking the two steps it currently does. I have bolded the relevant code below which starts 13 lines into the routine.</span></span></span></span></span></span></div><div><br></div><div>It appears that the BasicBlock "<span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; font-weight: bold; ">%loop.endif_crit_edge<span class="Apple-style-span" style="font-family: Arial; font-size: medium; font-weight: normal; ">" was created by one of the optimization passes which also created the phi node at the beginning of the "<span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; font-weight: bold; ">%endif<span class="Apple-style-span" style="font-family: Arial; font-size: medium; font-weight: normal; ">" block. In this particular case, the phi node could just as easily be using "<span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; font-weight: bold; ">%loop" <span class="Apple-style-span" style="font-family: Arial; font-size: medium; font-weight: normal; ">as the predecessor. So it appears that the "<span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; font-weight: bold; ">%loop.endif_crit_edge<span class="Apple-style-span" style="font-family: Arial; font-size: medium; font-weight: normal; ">" block and associated branch statement is completely unnecessary.</span></span></span></span></span></span></span></span></div><div><br></div><div>Am I missing something here?</div><div><br></div><div>Is there an optimization pass that I should add which should handle this case?</div><div><br></div><div>Finally, I want to look at the machine code to see if perhaps this sort of thing is handled by the optimization passes during machine code emission but I can't figure out how to easily print out the machine code. Is there an easy way to add a <span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; ">createMachineFunctionPrinterPass <span class="Apple-style-span" style="font-family: Arial; font-size: medium; ">pass to the ExecutionEngine's JIT so that it will print out the machine code after all the optimizations have been done and the code has been generated for MachineCodeEmission?</span></span></div><div><br></div><div>Thank you in advance,</div><div><br></div><div>Curtis</div><div><br></div><div><br></div><div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; ">define void @main() nounwind {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; ">bb.nph:</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> br label %loop</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; ">loop: ; preds = %bb.nph, %endif15</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %lsr.iv = phi i32 [ 1, %bb.nph ], [ %lsr.iv.next, %endif15 ] ; <i32> [#uses=4]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %fp = sitofp i32 %lsr.iv to double ; <double> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %r_fmul = fmul double %fp, 3.151900e+00 ; <double> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %r_fadd = fadd double %r_fmul, 2.800000e+00 ; <double> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %r_fmul5 = fmul double %r_fadd, 5.320000e+00 ; <double> [#uses=2]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %r_srem = srem i32 %lsr.iv, 17 ; <i32> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %r_icmpeq = icmp eq i32 %r_srem, 1 ; <i1> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> br i1 %r_icmpeq, label %then, label <b>%loop.endif_crit_edge</b></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; "><b>loop.endif_crit_edge:</b> ; preds = %loop</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> <b>br label %endif</b></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; ">then: ; preds = %loop</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %r_fmul8 = fmul double %r_fmul5, 1.000000e+02 ; <double> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> br label %endif</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; ">endif: ; preds = %loop.endif_crit_edge, %then</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %anotherFloat.1 = <b>phi double [ %r_fmul8, %then ], [ %r_fmul5, %loop.endif_crit_edge ]</b> ; <double> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %r_srem10 = srem i32 %lsr.iv, 16 ; <i32> [#uses=2]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %r_icmpsgt = icmp sgt i32 %r_srem10, 10 ; <i1> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> br i1 %r_icmpsgt, label %then11, label %endif.endif15_crit_edge</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; ">endif.endif15_crit_edge: ; preds = %endif</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> br label %endif15</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; ">then11: ; preds = %endif</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %phitmp = sitofp i32 %r_srem10 to double ; <double> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> br label %endif15</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; ">endif15: ; preds = %endif.endif15_crit_edge, %then11</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %storemerge26 = phi double [ %phitmp, %then11 ], [ 1.000000e+01, %endif.endif15_crit_edge ] ; <double> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %lsr.iv.next = add i32 %lsr.iv, 1 ; <i32> [#uses=2]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %exitcond = icmp eq i32 %lsr.iv.next, 10001 ; <i1> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> br i1 %exitcond, label %afterloop, label %loop</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; ">afterloop: ; preds = %endif15</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %r_fadd19 = fadd double %anotherFloat.1, %storemerge26 ; <double> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %phitmp32 = fcmp ogt double %r_fadd19, 3.535200e+03 ; <i1> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> %storemerge27 = zext i1 %phitmp32 to i32 ; <i32> [#uses=1]</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> store i32 %storemerge27, i32* @testSuccessful</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "> ret void</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; ">}</div><div style="text-indent: -28px;"><font class="Apple-style-span" face="Menlo" size="3"><span class="Apple-style-span" style="font-size: 11px; "><b><br></b></span></font></div></div></div></body></html>