<div dir="ltr">Hi,<div><br></div><div>if you use opt -simplifycfg, the third BB can be eliminated.</div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-09-20 0:03 GMT-04:00 Russell Wallace via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">The following function compiles with -O3 into the following IR. <a href="http://llvm.org/docs/Passes.html#simplifycfg-simplify-the-cfg" target="_blank">http://llvm.org/docs/Passes.html#simplifycfg-simplify-the-cfg</a> says <ul style="color:rgb(0,0,0);font-family:'Lucida Grande','Lucida Sans Unicode',Geneva,Verdana,sans-serif;font-size:14px;line-height:21px"><li>Eliminates a basic block that only contains an unconditional branch.</li></ul><div><font color="#000000" face="Lucida Grande, Lucida Sans Unicode, Geneva, Verdana, sans-serif"><span style="font-size:14px;line-height:21px">but the first and third blocks in the compiled function only contain an unconditional branch; I would have expected them to be eliminated. What am I missing?</span></font></div><div><font color="#000000" face="Lucida Grande, Lucida Sans Unicode, Geneva, Verdana, sans-serif"><span style="font-size:14px;line-height:21px"><br></span></font></div><div><font color="#000000" face="Lucida Grande, Lucida Sans Unicode, Geneva, Verdana, sans-serif"><div><span style="font-size:14px;line-height:21px">double f(double *a) {</span></div><div><span style="font-size:14px;line-height:21px"> for (int i = 0; i < 1000; i++)</span></div><div><span style="font-size:14px;line-height:21px"> a[i] *= 2;</span></div><div><span style="font-size:14px;line-height:21px"> for (int i = 0; i < 1000; i++)</span></div><div><span style="font-size:14px;line-height:21px"> a[i] *= 2;</span></div><div><span style="font-size:14px;line-height:21px"> return a[0] + a[1];</span></div><div><span style="font-size:14px;line-height:21px">}</span></div><div style="font-size:14px;line-height:21px"><br></div></font></div><div><font color="#000000" face="Lucida Grande, Lucida Sans Unicode, Geneva, Verdana, sans-serif"><div><span style="font-size:14px;line-height:21px">; Function Attrs: nounwind uwtable</span></div><div><span style="font-size:14px;line-height:21px">define double @"\01?f@@YANPEAN@Z"(double* nocapture %a) #1 {</span></div><div><span style="font-size:14px;line-height:21px">overflow.checked:</span></div><div><span style="font-size:14px;line-height:21px"> br label %vector.body, !dbg !18</span></div><div><span style="font-size:14px;line-height:21px"><br></span></div><div><span style="font-size:14px;line-height:21px">vector.body: ; preds = %vector.body, %overflow.checked</span></div><div><span style="font-size:14px;line-height:21px"> %index = phi i64 [ 0, %overflow.checked ], [ %index.next.1, %vector.body ], !dbg !18</span></div><div><span style="font-size:14px;line-height:21px"> %0 = getelementptr inbounds double, double* %a, i64 %index, !dbg !19</span></div><div><span style="font-size:14px;line-height:21px"> %1 = bitcast double* %0 to <2 x double>*, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %wide.load = load <2 x double>, <2 x double>* %1, align 8, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %2 = getelementptr double, double* %0, i64 2, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %3 = bitcast double* %2 to <2 x double>*, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %wide.load8 = load <2 x double>, <2 x double>* %3, align 8, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %4 = fmul <2 x double> %wide.load, <double 2.000000e+00, double 2.000000e+00>, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %5 = fmul <2 x double> %wide.load8, <double 2.000000e+00, double 2.000000e+00>, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %6 = bitcast double* %0 to <2 x double>*, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> store <2 x double> %4, <2 x double>* %6, align 8, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %7 = bitcast double* %2 to <2 x double>*, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> store <2 x double> %5, <2 x double>* %7, align 8, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %index.next = or i64 %index, 4, !dbg !18</span></div><div><span style="font-size:14px;line-height:21px"> %8 = getelementptr inbounds double, double* %a, i64 %index.next, !dbg !19</span></div><div><span style="font-size:14px;line-height:21px"> %9 = bitcast double* %8 to <2 x double>*, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %wide.load.1 = load <2 x double>, <2 x double>* %9, align 8, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %10 = getelementptr double, double* %8, i64 2, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %11 = bitcast double* %10 to <2 x double>*, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %wide.load8.1 = load <2 x double>, <2 x double>* %11, align 8, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %12 = fmul <2 x double> %wide.load.1, <double 2.000000e+00, double 2.000000e+00>, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %13 = fmul <2 x double> %wide.load8.1, <double 2.000000e+00, double 2.000000e+00>, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %14 = bitcast double* %8 to <2 x double>*, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> store <2 x double> %12, <2 x double>* %14, align 8, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %15 = bitcast double* %10 to <2 x double>*, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> store <2 x double> %13, <2 x double>* %15, align 8, !dbg !20</span></div><div><span style="font-size:14px;line-height:21px"> %index.next.1 = add nsw i64 %index, 8, !dbg !18</span></div><div><span style="font-size:14px;line-height:21px"> %16 = icmp eq i64 %index.next.1, 1000, !dbg !18</span></div><div><span style="font-size:14px;line-height:21px"> br i1 %16, label %vector.body10.preheader, label %vector.body, !dbg !18, !llvm.loop !21</span></div><div><span style="font-size:14px;line-height:21px"><br></span></div><div><span style="font-size:14px;line-height:21px">vector.body10.preheader: ; preds = %vector.body</span></div><div><span style="font-size:14px;line-height:21px"> br label %vector.body10, !dbg !24</span></div><div><span style="font-size:14px;line-height:21px"><br></span></div><div><span style="font-size:14px;line-height:21px">vector.body10: ; preds = %vector.body10, %vector.body10.preheader</span></div><div><span style="font-size:14px;line-height:21px"> %index13 = phi i64 [ 0, %vector.body10.preheader ], [ %index.next21.1, %vector.body10 ], !dbg !25</span></div><div><span style="font-size:14px;line-height:21px"> %17 = getelementptr inbounds double, double* %a, i64 %index13, !dbg !24</span></div><div><span style="font-size:14px;line-height:21px"> %18 = bitcast double* %17 to <2 x double>*, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %wide.load26 = load <2 x double>, <2 x double>* %18, align 8, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %19 = getelementptr double, double* %17, i64 2, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %20 = bitcast double* %19 to <2 x double>*, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %wide.load27 = load <2 x double>, <2 x double>* %20, align 8, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %21 = fmul <2 x double> %wide.load26, <double 2.000000e+00, double 2.000000e+00>, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %22 = fmul <2 x double> %wide.load27, <double 2.000000e+00, double 2.000000e+00>, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %23 = bitcast double* %17 to <2 x double>*, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> store <2 x double> %21, <2 x double>* %23, align 8, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %24 = bitcast double* %19 to <2 x double>*, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> store <2 x double> %22, <2 x double>* %24, align 8, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %index.next21 = or i64 %index13, 4, !dbg !25</span></div><div><span style="font-size:14px;line-height:21px"> %25 = getelementptr inbounds double, double* %a, i64 %index.next21, !dbg !24</span></div><div><span style="font-size:14px;line-height:21px"> %26 = bitcast double* %25 to <2 x double>*, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %wide.load26.1 = load <2 x double>, <2 x double>* %26, align 8, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %27 = getelementptr double, double* %25, i64 2, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %28 = bitcast double* %27 to <2 x double>*, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %wide.load27.1 = load <2 x double>, <2 x double>* %28, align 8, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %29 = fmul <2 x double> %wide.load26.1, <double 2.000000e+00, double 2.000000e+00>, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %30 = fmul <2 x double> %wide.load27.1, <double 2.000000e+00, double 2.000000e+00>, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %31 = bitcast double* %25 to <2 x double>*, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> store <2 x double> %29, <2 x double>* %31, align 8, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %32 = bitcast double* %27 to <2 x double>*, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> store <2 x double> %30, <2 x double>* %32, align 8, !dbg !26</span></div><div><span style="font-size:14px;line-height:21px"> %index.next21.1 = add nsw i64 %index13, 8, !dbg !25</span></div><div><span style="font-size:14px;line-height:21px"> %33 = icmp eq i64 %index.next21.1, 1000, !dbg !25</span></div><div><span style="font-size:14px;line-height:21px"> br i1 %33, label %middle.block11, label %vector.body10, !dbg !25, !llvm.loop !27</span></div><div><span style="font-size:14px;line-height:21px"><br></span></div><div><span style="font-size:14px;line-height:21px">middle.block11: ; preds = %vector.body10</span></div><div><span style="font-size:14px;line-height:21px"> %34 = load double, double* %a, align 8, !dbg !28</span></div><div><span style="font-size:14px;line-height:21px"> %35 = getelementptr inbounds double, double* %a, i64 1, !dbg !29</span></div><div><span style="font-size:14px;line-height:21px"> %36 = load double, double* %35, align 8, !dbg !29</span></div><div><span style="font-size:14px;line-height:21px"> %37 = fadd double %34, %36, !dbg !30</span></div><div><span style="font-size:14px;line-height:21px"> ret double %37, !dbg !31</span></div><div><span style="font-size:14px;line-height:21px">}</span></div><div style="font-size:14px;line-height:21px"><br></div></font></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>