<html><body>
<p><font size="2" face="sans-serif">Inlined.</font><br>
<br>
<img width="16" height="16" src="cid:2__=0ABBF40ADFC93D7C8f9e8a93df938@us.ibm.com" border="0" alt="Inactive hide details for Gerolf Hoflehner ---08/06/2015 12:11:45 AM---> On Aug 5, 2015, at 9:08 PM, Gerolf Hoflehner <ghoflehn"><font size="2" color="#424282" face="sans-serif">Gerolf Hoflehner ---08/06/2015 12:11:45 AM---> On Aug 5, 2015, at 9:08 PM, Gerolf Hoflehner <ghoflehner@apple.com> wrote: ></font><br>
<br>
<font size="1" color="#5F5F5F" face="sans-serif">From: </font><font size="1" face="sans-serif">Gerolf Hoflehner <ghoflehner@apple.com></font><br>
<font size="1" color="#5F5F5F" face="sans-serif">To: </font><font size="1" face="sans-serif">Hyojin Sung/Watson/IBM@IBMUS</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Cc: </font><font size="1" face="sans-serif">Hal Finkel <hfinkel@anl.gov>, llvm-dev@lists.llvm.org</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Date: </font><font size="1" face="sans-serif">08/06/2015 12:11 AM</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Subject: </font><font size="1" face="sans-serif">Re: [LLVMdev] Improving loop vectorizer support for loops with a volatile iteration variable</font><br>
<hr width="100%" size="2" align="left" noshade style="color:#8091A5; "><br>
<br>
<br>
<ul style="padding-left: 36pt"><font size="3" face="serif">On Aug 5, 2015, at 9:08 PM, Gerolf Hoflehner <</font><a href="mailto:ghoflehner@apple.com"><font size="3" color="#0000FF" face="serif"><u>ghoflehner@apple.com</u></font></a><font size="3" face="serif">> wrote:</font><br>
<br>
<font size="3" face="serif">Ok, assuming a verifier/checker was in place the information could look like:</font><br>
<br>
<font size="3" face="serif">...</font><br>
<font size="3" face="serif">LV: Not vectorizing: Cannot prove legality.</font><br>
<font size="3" face="serif">LV: Legal to vectorize. — after loop rotation</font><br>
<font size="3" face="serif">LV: Legal to vectorize.</font><br>
<font size="3" face="serif">...</font><br>
<font size="3" face="serif">LV: Legal to vectorize.</font><br>
<font size="3" face="serif">LV: Not vectorizing: Cannot prove legality. — after Jump Threading (later also — after CFG Simplify)</font><br>
<br>
<font size="3" face="serif">Note that in your example the second round of loop rotation fails making a loop vectorizable (from the comment that is its purpose, though!). It might be more appropriate to generalize that approach to any transformation that makes a loop vectorizable (not just rotation) rather than tweaking jump threading + simplification.</font><br>
<br>
<font size="3" face="serif">To clarify, the loop is vectorizable before and after loop rotation. At least for the example, loop rotation does not affect the vectorizability of a loop. The LLVM loop vectorizer and vectorization legality checker rely on loops in a canonical form. So if there's no interfering passes, a check should be able to tell if a loop is vectorizable after loop simplify.</font><br>
<br>
<br>
<font size="3" face="serif">I’m convinced there are more cases like yours and the following framework would give a systematic way to handle them:</font><br>
<br>
<font size="3" face="serif">a) a checker for is_vectorizable (from refactoring the legal class in the loop vectorizer - but properly, not hacked like my prototype …) </font><br>
<font size="3" face="serif">b) invoke checker optionally. The checker can be used for testing, analysis and - independently - as a service for loop transformations (eg. if the loop is vectorizable already, perhaps a transformation is not needed or vice versa). I’m not sure about the architecture yet. Perhaps the pass manager could run a checker automatically after every pass when an option is set. Adding extra calls after every pass is too clumsy.</font><br>
<br>
<font size="3" face="serif">c) fix violators if appropriate and/or add transformations that morph a loop into a vectorizable form when possible (especially when it has been in vectorizable shape at some point).</font><br>
<br>
<font size="3" face="serif">We can design a more general form of checker/verifier that is optionally executed after LLVM passes can help with identifying interfering transformations. We can use the checker only for debugging (reporting which transformation is interfering with others) or for dynamically triggering or reverting transformations to maintain desired properties like vectorizability as you said. If the checker dynamically affects actual pass executions, then I think it can require extensive changes to the incremental way LLVM applies transformations. </font><br>
<br>
<br>
<font size="3" face="serif">Regards,</font><br>
<font size="3" face="serif">Hyojin</font><br>
<br>
<br>
<br>
<font size="3" face="serif">-Gerolf</font><br>
<br>
<ul style="padding-left: 36pt"><font size="3" face="serif">On Aug 4, 2015, at 8:04 PM, Gerolf Hoflehner <</font><a href="mailto:ghoflehner@apple.com"><font size="3" color="#0000FF" face="serif"><u>ghoflehner@apple.com</u></font></a><font size="3" face="serif">> wrote:</font><br>
<br>
<font size="3" face="serif">The approach would be to run the legal check before + after transformations on demand. For loops that “should” be vectorized it would give the means to isolate the transformation that introduces a barrier. I’ll see that can get a dirty prototype to illustrate this on your test case. I could give a warning/remark when the code was (loop-) vectorizable at some point but not anymore when the vectorizer actually kicks in and speed-up diagnosis when comparing good/bad cases (like in your instance w/ and w/o the volatile modifier).</font><br>
<br>
<font size="3" face="serif">Gerolf</font><br>
<ul style="padding-left: 36pt"><font size="3" face="serif">On Aug 4, 2015, at 8:40 AM, Hyojin Sung <</font><a href="mailto:hsung@us.ibm.com"><font size="3" color="#0000FF" face="serif"><u>hsung@us.ibm.com</u></font></a><font size="3" face="serif">> wrote:</font><br>
<p><font size="2" face="sans-serif">Hi Gerolf,</font><font size="3" face="serif"><br>
</font><font size="2" face="sans-serif"><br>
Thanks for the comment. Yes, I agree that compiler transformation as a whole should not render vectorizable loops unvectorizable. However, some passes may temporarily make a loop unvectorizable (e.g., by aggressive GVN or DCE/DBE) then later passes may revert the effect. Trying to keep the invariants after each pass may prevent useful optimizations. Regarding your concern about the example-based approach, LoopVectorizationLegality class gives a good idea about what will be such invariants and they are mostly related to check for canonical loop structures. I think that there are only a handful of transformation passes that may disrupt loop structures mainly through aggressively eliminating BB's. Focusing on such transformations may be sufficient to prevent prior transformations from destroying vectorizable loops. I'd be glad to hear more of your thoughts. </font><font size="3" face="serif"><br>
</font><font size="2" face="sans-serif"><br>
Best,<br>
Hyojin</font><font size="3" face="serif"><br>
<br>
<br>
<graycol.gif></font><font size="2" color="#424282" face="sans-serif">Gerolf Hoflehner ---08/03/2015 06:14:22 PM---I see a more fundamental problem and perhaps this example can serve as a stepping stone towards a so</font><font size="3" face="serif"><br>
</font><font size="1" color="#5F5F5F" face="sans-serif"><br>
From: </font><font size="1" face="sans-serif">Gerolf Hoflehner <</font><a href="mailto:ghoflehner@apple.com"><font size="1" color="#0000FF" face="sans-serif"><u>ghoflehner@apple.com</u></font></a><font size="1" face="sans-serif">></font><font size="1" color="#5F5F5F" face="sans-serif"><br>
To: </font><font size="1" face="sans-serif">Hyojin Sung/Watson/IBM@IBMUS</font><font size="1" color="#5F5F5F" face="sans-serif"><br>
Cc: </font><font size="1" face="sans-serif">Hal Finkel <</font><a href="mailto:hfinkel@anl.gov"><font size="1" color="#0000FF" face="sans-serif"><u>hfinkel@anl.gov</u></font></a><font size="1" face="sans-serif">>, </font><a href="mailto:llvmdev-bounces@cs.uiuc.edu"><font size="1" color="#0000FF" face="sans-serif"><u>llvmdev-bounces@cs.uiuc.edu</u></font></a><font size="1" face="sans-serif">, </font><a href="mailto:llvmdev@cs.uiuc.edu"><font size="1" color="#0000FF" face="sans-serif"><u>llvmdev@cs.uiuc.edu</u></font></a><font size="1" color="#5F5F5F" face="sans-serif"><br>
Date: </font><font size="1" face="sans-serif">08/03/2015 06:14 PM</font><font size="1" color="#5F5F5F" face="sans-serif"><br>
Subject: </font><font size="1" face="sans-serif">Re: [LLVMdev] Improving loop vectorizer support for loops with a volatile iteration variable</font>
<p><hr width="100%" size="2" align="left" noshade><font size="3" face="serif"><br>
<br>
<br>
I see a more fundamental problem and perhaps this example can serve as a stepping stone towards a solution.<br>
<br>
There is a desired property: In this case, loop is vectorizable.<br>
There are N compiler transformations. These transformations must either establish the property or keep it invariant, but never destroy it.<br>
<br>
If there is agreement to this then the first step is to have the analysis of ‘is vectorizable’ runnable after every transformation and report violations in detail, likely under a flag. Then comparing a set of loops not vectorizable with clang but with other compilers (gcc, clang, …) should shape precise ideas on normal forms for the vectorizer and general improvements to transformations to the keep/establish the invariant/desired property.<br>
<br>
I’m worried that the one example at time approach over time confuscates matters within transformations resulting in less maintainable code. <br>
<br>
Gerolf<br>
<br>
</font>
<ul style="padding-left: 36pt"><font size="3" face="serif">On Aug 3, 2015, at 2:33 PM, Hyojin Sung <</font><a href="mailto:hsung@us.ibm.com"><font size="3" color="#0000FF" face="serif"><u>hsung@us.ibm.com</u></font></a><font size="3" face="serif">> wrote:</font>
<p><font size="2" face="sans-serif">Hi,<br>
<br>
I discussed the issue offline with Hal, and would like to clarify what is exactly going on, what are trade-offs for different solutions, and ask for more feedback on my proposed solution (</font><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D11728&d=AwMGaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=N2de3NabFW69oQ6in3ydIBGGRddU65HAGvjpTRC7uvA&s=q8HlQbw3XXnWU7Og4HMcdBjGw-Y2XDB7h9xSiuRtZFs&e="><font size="2" color="#0000FF" face="sans-serif"><u>http://reviews.llvm.org/D11728</u></font></a><font size="2" face="sans-serif">). I will use the example from Hal's post: </font><font size="2" face="serif"><br>
<br>
void foo2(float * restrict x, float * restrict y, float * restrict z) {<br>
for (volatile int i = 0; i < 1000; ++i) {<br>
for (int j = 0; j < 1600; ++j) {<br>
x[j] = y[j] + z[j];<br>
}<br>
}<br>
}</font><font size="2" face="sans-serif"><br>
<br>
IR after the first loop simplify: A preheader is created. </font><font size="2" face="serif"><br>
<br>
; Function Attrs: nounwind<br>
define void @foo2(float* noalias nocapture %x, float* noalias nocapture readonly %y, float* noalias nocapture readonly %z) #0 {<br>
entry:<br>
%i = alloca i32, align 4<br>
tail call void @llvm.dbg.value(metadata float* %x, i64 0, metadata !11, metadata !25), !dbg !26<br>
tail call void @llvm.dbg.value(metadata float* %y, i64 0, metadata !12, metadata !25), !dbg !27<br>
tail call void @llvm.dbg.value(metadata float* %z, i64 0, metadata !13, metadata !25), !dbg !28<br>
%i.0.i.0..sroa_cast = bitcast i32* %i to i8*<br>
call void @llvm.lifetime.start(i64 4, i8* %i.0.i.0..sroa_cast)<br>
tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !14, metadata !25), !dbg !29<br>
store volatile i32 0, i32* %i, align 4, !dbg !29<br>
br label %for.cond, !dbg !30<br>
<br>
for.cond: ; preds = %for.cond.cleanup.3, %entry<br>
tail call void @llvm.dbg.value(metadata i32* %i, i64 0, metadata !14, metadata !25), !dbg !29<br>
%i.0.i.0. = load volatile i32, i32* %i, align 4, !dbg !31<br>
%cmp = icmp slt i32 %i.0.i.0., 1000, !dbg !34<br>
br i1 %cmp, label %for.cond.1.preheader, label %for.cond.cleanup, !dbg !35<br>
<br>
for.cond.1.preheader: ; preds = %for.cond<br>
br label %for.cond.1, !dbg !36<br>
<br>
for.cond.cleanup: ; preds = %for.cond<br>
call void @llvm.lifetime.end(i64 4, i8* %i.0.i.0..sroa_cast)<br>
ret void, !dbg !38<br>
<br>
for.cond.1: ; preds = %for.cond.1.preheader, %for.body.4<br>
%j.0 = phi i32 [ %inc, %for.body.4 ], [ 0, %for.cond.1.preheader ]<br>
%cmp2 = icmp slt i32 %j.0, 1600, !dbg !36<br>
br i1 %cmp2, label %for.body.4, label %for.cond.cleanup.3, !dbg !39<br>
<br>
for.cond.cleanup.3: ; preds = %for.cond.1<br>
tail call void @llvm.dbg.value(metadata i32* %i, i64 0, metadata !14, metadata !25), !dbg !29<br>
%i.0.i.0.17 = load volatile i32, i32* %i, align 4, !dbg !40<br>
%inc10 = add nsw i32 %i.0.i.0.17, 1, !dbg !40<br>
tail call void @llvm.dbg.value(metadata i32 %inc10, i64 0, metadata !14, metadata !25), !dbg !29<br>
store volatile i32 %inc10, i32* %i, align 4, !dbg !40<br>
br label %for.cond, !dbg !41<br>
<br>
for.body.4: ; preds = %for.cond.1<br>
%idxprom = sext i32 %j.0 to i64, !dbg !42<br>
%arrayidx = getelementptr inbounds float, float* %y, i64 %idxprom, !dbg !42<br>
%0 = load float, float* %arrayidx, align 4, !dbg !42, !tbaa !44<br>
%arrayidx6 = getelementptr inbounds float, float* %z, i64 %idxprom, !dbg !48<br>
%1 = load float, float* %arrayidx6, align 4, !dbg !48, !tbaa !44<br>
%add = fadd float %0, %1, !dbg !49<br>
%arrayidx8 = getelementptr inbounds float, float* %x, i64 %idxprom, !dbg !50<br>
store float %add, float* %arrayidx8, align 4, !dbg !51, !tbaa !44<br>
%inc = add nsw i32 %j.0, 1, !dbg !52<br>
tail call void @llvm.dbg.value(metadata i32 %inc, i64 0, metadata !18, metadata !25), !dbg !53<br>
br label %for.cond.1, !dbg !54<br>
}<br>
<br>
IR after loop rotation: After loop rotation, a rotated preheader (for.cond.1.preheader.lr.ph) is created. A test for (i < 1000) is added at the end of "entry" block. If true, the control jumps unconditionally to "for.body.4" through "for.cond.1.preheader.lr.ph" and "for.cond.1.preheader". You can see that these two blocks ("for.cond.1.preheader.lr.ph" and "for.cond.1.preheader") are practically empty, and they will get eliminated later by Jump Threading and/or Simplify-the-CFG. *IF* the outer loop has a non-volatile induction variable, the loop will not be rotated in the first place as "for.cond.1.preheader" has a PHI node for "i", and these blocks will not be eliminated. <br>
<br>
; Function Attrs: nounwind<br>
define void @foo2(float* noalias nocapture %x, float* noalias nocapture readonly %y, float* noalias nocapture readonly %z) #0 {<br>
entry:<br>
%i = alloca i32, align 4<br>
tail call void @llvm.dbg.value(metadata float* %x, i64 0, metadata !11, metadata !25), !dbg !26<br>
tail call void @llvm.dbg.value(metadata float* %y, i64 0, metadata !12, metadata !25), !dbg !27<br>
tail call void @llvm.dbg.value(metadata float* %z, i64 0, metadata !13, metadata !25), !dbg !28<br>
%i.0.i.0..sroa_cast = bitcast i32* %i to i8*<br>
call void @llvm.lifetime.start(i64 4, i8* %i.0.i.0..sroa_cast)<br>
tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !14, metadata !25), !dbg !29<br>
store volatile i32 0, i32* %i, align 4, !dbg !29<br>
tail call void @llvm.dbg.value(metadata i32* %i, i64 0, metadata !14, metadata !25), !dbg !29<br>
%i.0.i.0..21 = load volatile i32, i32* %i, align 4, !dbg !30<br>
%cmp.22 = icmp slt i32 %i.0.i.0..21, 1000, !dbg !33<br>
br i1 %cmp.22, label %for.cond.1.preheader.lr.ph, label %for.cond.cleanup, !dbg !34<br>
<br>
for.cond.1.preheader.lr.ph: ; preds = %entry<br>
br label %for.cond.1.preheader, !dbg !34<br>
<br>
for.cond.1.preheader: ; preds = %for.cond.1.preheader.lr.ph, %for.cond.cleanup.3<br>
br label %for.body.4, !dbg !35<br>
<br>
for.cond.for.cond.cleanup_crit_edge: ; preds = %for.cond.cleanup.3<br>
br label %for.cond.cleanup, !dbg !34<br>
<br>
for.cond.cleanup: ; preds = %for.cond.for.cond.cleanup_crit_edge, %entry<br>
call void @llvm.lifetime.end(i64 4, i8* %i.0.i.0..sroa_cast)<br>
ret void, !dbg !36<br>
<br>
for.cond.cleanup.3: ; preds = %for.body.4<br>
tail call void @llvm.dbg.value(metadata i32* %i, i64 0, metadata !14, metadata !25), !dbg !29<br>
%i.0.i.0.17 = load volatile i32, i32* %i, align 4, !dbg !37<br>
%inc10 = add nsw i32 %i.0.i.0.17, 1, !dbg !37<br>
tail call void @llvm.dbg.value(metadata i32 %inc10, i64 0, metadata !14, metadata !25), !dbg !29<br>
store volatile i32 %inc10, i32* %i, align 4, !dbg !37<br>
tail call void @llvm.dbg.value(metadata i32* %i, i64 0, metadata !14, metadata !25), !dbg !29<br>
%i.0.i.0. = load volatile i32, i32* %i, align 4, !dbg !30<br>
%cmp = icmp slt i32 %i.0.i.0., 1000, !dbg !33<br>
br i1 %cmp, label %for.cond.1.preheader, label %for.cond.for.cond.cleanup_crit_edge, !dbg !34<br>
<br>
for.body.4: ; preds = %for.cond.1.preheader, %for.body.4<br>
%j.020 = phi i32 [ 0, %for.cond.1.preheader ], [ %inc, %for.body.4 ]<br>
%idxprom = sext i32 %j.020 to i64, !dbg !38<br>
%arrayidx = getelementptr inbounds float, float* %y, i64 %idxprom, !dbg !38<br>
%0 = load float, float* %arrayidx, align 4, !dbg !38, !tbaa !41<br>
%arrayidx6 = getelementptr inbounds float, float* %z, i64 %idxprom, !dbg !45<br>
%1 = load float, float* %arrayidx6, align 4, !dbg !45, !tbaa !41<br>
%add = fadd float %0, %1, !dbg !46<br>
%arrayidx8 = getelementptr inbounds float, float* %x, i64 %idxprom, !dbg !47<br>
store float %add, float* %arrayidx8, align 4, !dbg !48, !tbaa !41<br>
%inc = add nsw i32 %j.020, 1, !dbg !49<br>
tail call void @llvm.dbg.value(metadata i32 %inc, i64 0, metadata !18, metadata !25), !dbg !50<br>
%cmp2 = icmp slt i32 %inc, 1600, !dbg !51<br>
br i1 %cmp2, label %for.body.4, label %for.cond.cleanup.3, !dbg !35</font><font size="3" face="serif"><br>
</font><font size="2" face="serif"><br>
<br>
After Jump Threading: "for.cond.1.preheader.lr.ph" and "for.cond.1.preheader" are merged into "for.body.4" by TryToSimplifyUnconditionalBranchFromEmptyBlock() in Transforms/Utils/Local.cpp. Now "for.body.4" has three incoming edges (two backedges).<br>
<br>
; Function Attrs: nounwind<br>
define void @foo2(float* noalias nocapture %x, float* noalias nocapture readonly %y, float* noalias nocapture readonly %z) #0 {<br>
entry:<br>
%i = alloca i32, align 4<br>
tail call void @llvm.dbg.value(metadata float* %x, i64 0, metadata !11, metadata !25), !dbg !26<br>
tail call void @llvm.dbg.value(metadata float* %y, i64 0, metadata !12, metadata !25), !dbg !27<br>
tail call void @llvm.dbg.value(metadata float* %z, i64 0, metadata !13, metadata !25), !dbg !28<br>
%i.0.i.0..sroa_cast = bitcast i32* %i to i8*<br>
call void @llvm.lifetime.start(i64 4, i8* %i.0.i.0..sroa_cast)<br>
tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !14, metadata !25), !dbg !29<br>
store volatile i32 0, i32* %i, align 4, !dbg !29<br>
tail call void @llvm.dbg.value(metadata i32* %i, i64 0, metadata !14, metadata !25), !dbg !29<br>
%i.0.i.0..21 = load volatile i32, i32* %i, align 4, !dbg !30<br>
%cmp.22 = icmp slt i32 %i.0.i.0..21, 1000, !dbg !33<br>
br i1 %cmp.22, label %for.body.4, label %for.cond.cleanup, !dbg !34<br>
<br>
for.cond.cleanup: ; preds = %for.cond.cleanup.3, %entry<br>
call void @llvm.lifetime.end(i64 4, i8* %i.0.i.0..sroa_cast)<br>
ret void, !dbg !35<br>
<br>
for.cond.cleanup.3: ; preds = %for.body.4<br>
tail call void @llvm.dbg.value(metadata i32* %i, i64 0, metadata !14, metadata !25), !dbg !29<br>
%i.0.i.0.17 = load volatile i32, i32* %i, align 4, !dbg !36<br>
%inc10 = add nsw i32 %i.0.i.0.17, 1, !dbg !36<br>
tail call void @llvm.dbg.value(metadata i32 %inc10, i64 0, metadata !14, metadata !25), !dbg !29<br>
store volatile i32 %inc10, i32* %i, align 4, !dbg !36<br>
tail call void @llvm.dbg.value(metadata i32* %i, i64 0, metadata !14, metadata !25), !dbg !29<br>
%i.0.i.0. = load volatile i32, i32* %i, align 4, !dbg !30<br>
%cmp = icmp slt i32 %i.0.i.0., 1000, !dbg !33<br>
br i1 %cmp, label %for.body.4, label %for.cond.cleanup, !dbg !34<br>
<br>
for.body.4: ; preds = %for.cond.cleanup.3, %entry, %for.body.4<br>
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body.4 ], [ 0, %entry ], [ 0, %for.cond.cleanup.3 ]<br>
%arrayidx = getelementptr inbounds float, float* %y, i64 %indvars.iv, !dbg !37<br>
%0 = load float, float* %arrayidx, align 4, !dbg !37, !tbaa !40<br>
%arrayidx6 = getelementptr inbounds float, float* %z, i64 %indvars.iv, !dbg !44<br>
%1 = load float, float* %arrayidx6, align 4, !dbg !44, !tbaa !40<br>
%add = fadd float %0, %1, !dbg !45<br>
%arrayidx8 = getelementptr inbounds float, float* %x, i64 %indvars.iv, !dbg !46<br>
store float %add, float* %arrayidx8, align 4, !dbg !47, !tbaa !40<br>
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !48<br>
%exitcond = icmp eq i64 %indvars.iv.next, 1600, !dbg !48<br>
br i1 %exitcond, label %for.cond.cleanup.3, label %for.body.4, !dbg !48</font><font size="3" face="serif"><br>
</font><font size="2" face="serif"><br>
<br>
After another loop simplify: Loop simplify tries to separate out nested loops but fails to do so with this loop since it does not has a PHI node for the outer loop variable. Instead, it creates a backedge block.<br>
<br>
for.cond.cleanup.3: ; preds = %for.body.4<br>
tail call void @llvm.dbg.value(metadata i32* %i, i64 0, metadata !14, metadata !25), !dbg !29<br>
%i.0.i.0.17 = load volatile i32, i32* %i, align 4, !dbg !39<br>
%inc10 = add nsw i32 %i.0.i.0.17, 1, !dbg !39<br>
tail call void @llvm.dbg.value(metadata i32 %inc10, i64 0, metadata !14, metadata !25), !dbg !29<br>
store volatile i32 %inc10, i32* %i, align 4, !dbg !39<br>
tail call void @llvm.dbg.value(metadata i32* %i, i64 0, metadata !14, metadata !25), !dbg !29<br>
%i.0.i.0. = load volatile i32, i32* %i, align 4, !dbg !30<br>
%cmp = icmp slt i32 %i.0.i.0., 1000, !dbg !33<br>
br i1 %cmp, label %for.body.4.backedge, label %for.cond.cleanup.loopexit, !dbg !34<br>
<br>
for.body.4: ; preds = %for.body.4.backedge, %for.body.4.preheader<br>
%indvars.iv = phi i64 [ 0, %for.body.4.preheader ], [ %</font><a href="http://indvars.iv.be/"><font size="2" color="#0000FF" face="serif"><u>indvars.iv.be</u></font></a><font size="2" face="serif">, %for.body.4.backedge ]<br>
%arrayidx = getelementptr inbounds float, float* %y, i64 %indvars.iv, !dbg !35<br>
%0 = load float, float* %arrayidx, align 4, !dbg !35, !tbaa !40<br>
%arrayidx6 = getelementptr inbounds float, float* %z, i64 %indvars.iv, !dbg !44<br>
%1 = load float, float* %arrayidx6, align 4, !dbg !44, !tbaa !40<br>
%add = fadd float %0, %1, !dbg !45<br>
%arrayidx8 = getelementptr inbounds float, float* %x, i64 %indvars.iv, !dbg !46<br>
store float %add, float* %arrayidx8, align 4, !dbg !47, !tbaa !40<br>
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !48<br>
%exitcond = icmp eq i64 %indvars.iv.next, 1600, !dbg !48<br>
br i1 %exitcond, label %for.cond.cleanup.3, label %for.body.4.backedge, !dbg !48<br>
<br>
for.body.4.backedge: ; preds = %for.body.4, %for.cond.cleanup.3<br>
%</font><a href="http://indvars.iv.be/"><font size="2" color="#0000FF" face="serif"><u>indvars.iv.be</u></font></a><font size="2" face="serif"> = phi i64 [ %indvars.iv.next, %for.body.4 ], [ 0, %for.cond.cleanup.3 ]<br>
br label %for.body.4x</font><font size="3" face="serif"><br>
</font><font size="2" face="sans-serif"><br>
<br>
LLVM loop vectorizer rejects to vectorize any loop for which a loop latch (for.body.4.backedge) is different from a loop exiting block (for.cond.cleanup.3). The loop vectorizer can assume that all instructions in the loop are executed the same number of times with the test. <br>
<br>
I believe a fix is in order in one way or another because the example is simple and common enough and vectorized by other compilers. We may approach it by either (1) preventing loops from being collapsed in the first place or (2) teaching loop vectorizer to handle collapsed loops. For (2), we may need to allow loop vectorizer to forego the assumption and handle the loop as it is. The assumption seems fundamental to many of the vectorization algorithms, so it will require extensive updates or may end up with reverting the loop back to a properly nested form. The downside of (1) is that it may slow down common optimization passes that are repeatedly executed before vectorization. <br>
<br>
My patch (</font><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D11728&d=AwMGaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=N2de3NabFW69oQ6in3ydIBGGRddU65HAGvjpTRC7uvA&s=q8HlQbw3XXnWU7Og4HMcdBjGw-Y2XDB7h9xSiuRtZFs&e="><font size="2" color="#0000FF" face="sans-serif"><u>http://reviews.llvm.org/D11728</u></font></a><font size="2" face="sans-serif">) is a prototype fix for (1) that modifies Jump Threading and Simplify-the-CFG to not eliminate an empty loop header BB even when the loop does not have a PHI node for its induction variable. The details can be found at </font><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D11728&d=AwMGaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=N2de3NabFW69oQ6in3ydIBGGRddU65HAGvjpTRC7uvA&s=q8HlQbw3XXnWU7Og4HMcdBjGw-Y2XDB7h9xSiuRtZFs&e="><font size="2" color="#0000FF" face="sans-serif"><u>http://reviews.llvm.org/D11728</u></font></a><font size="2" face="sans-serif">. I would welcome and appreciate any comments or feedback. <br>
<br>
Best,<br>
Hyojin</font><font size="3" face="serif"><br>
<br>
<br>
<graycol.gif></font><font size="2" color="#424282" face="sans-serif">Hal Finkel ---07/16/2015 03:19:24 AM-------- Original Message ----- > From: "Hal Finkel" <</font><a href="mailto:hfinkel@anl.gov"><font size="2" color="#0000FF" face="sans-serif"><u>hfinkel@anl.gov</u></font></a><font size="2" color="#424282" face="sans-serif">></font><font size="2" face="sans-serif"><br>
<br>
From: Hal Finkel <</font><a href="mailto:hfinkel@anl.gov"><font size="2" color="#0000FF" face="sans-serif"><u>hfinkel@anl.gov</u></font></a><font size="2" face="sans-serif">><br>
To: Chandler Carruth <</font><a href="mailto:chandlerc@google.com"><font size="2" color="#0000FF" face="sans-serif"><u>chandlerc@google.com</u></font></a><font size="2" face="sans-serif">><br>
Cc: </font><a href="mailto:llvmdev@cs.uiuc.edu"><font size="2" color="#0000FF" face="sans-serif"><u>llvmdev@cs.uiuc.edu</u></font></a><font size="2" face="sans-serif"><br>
Date: 07/16/2015 03:19 AM<br>
Subject: Re: [LLVMdev] Improving loop vectorizer support for loops with a volatile iteration variable<br>
Sent by: </font><a href="mailto:llvmdev-bounces@cs.uiuc.edu"><font size="2" color="#0000FF" face="sans-serif"><u>llvmdev-bounces@cs.uiuc.edu</u></font></a><font size="3" face="serif"> </font>
<p><br>
<hr width="100%" size="2" align="left" noshade><font size="3" face="serif"><br>
</font><font size="2" face="Arial"><br>
<br>
</font><font size="3" face="serif"><br>
<br>
</font><hr width="100%" size="2" align="left" id="zwchr">
<ul style="padding-left: 36pt"><font size="2" face="Helvetica"><b>From: </b></font><font size="2" face="Helvetica">"Hal Finkel" <</font><a href="mailto:hfinkel@anl.gov"><font size="2" color="#0000FF" face="Helvetica"><u>hfinkel@anl.gov</u></font></a><font size="2" face="Helvetica">></font><font size="2" face="Helvetica"><b><br>
To: </b></font><font size="2" face="Helvetica">"Chandler Carruth" <</font><a href="mailto:chandlerc@google.com"><font size="2" color="#0000FF" face="Helvetica"><u>chandlerc@google.com</u></font></a><font size="2" face="Helvetica">></font><font size="2" face="Helvetica"><b><br>
Cc: </b></font><a href="mailto:llvmdev@cs.uiuc.edu"><font size="2" color="#0000FF" face="Helvetica"><u>llvmdev@cs.uiuc.edu</u></font></a><font size="2" face="Helvetica"><b><br>
Sent: </b></font><font size="2" face="Helvetica">Thursday, July 16, 2015 1:58:02 AM</font><font size="2" face="Helvetica"><b><br>
Subject: </b></font><font size="2" face="Helvetica">Re: [LLVMdev] Improving loop vectorizer support for loops with a volatile iteration variable</font><font size="2" face="Arial"><br>
<br>
</font><font size="3" face="serif"><br>
<br>
</font><hr width="100%" size="2" align="left" id="zwchr_1">
<ul style="padding-left: 36pt"><font size="2" face="Helvetica"><b>From: </b></font><font size="2" face="Helvetica">"Hal Finkel" <</font><a href="mailto:hfinkel@anl.gov"><font size="2" color="#0000FF" face="Helvetica"><u>hfinkel@anl.gov</u></font></a><font size="2" face="Helvetica">></font><font size="2" face="Helvetica"><b><br>
To: </b></font><font size="2" face="Helvetica">"Chandler Carruth" <</font><a href="mailto:chandlerc@google.com"><font size="2" color="#0000FF" face="Helvetica"><u>chandlerc@google.com</u></font></a><font size="2" face="Helvetica">></font><font size="2" face="Helvetica"><b><br>
Cc: </b></font><a href="mailto:llvmdev@cs.uiuc.edu"><font size="2" color="#0000FF" face="Helvetica"><u>llvmdev@cs.uiuc.edu</u></font></a><font size="2" face="Helvetica"><b><br>
Sent: </b></font><font size="2" face="Helvetica">Thursday, July 16, 2015 1:46:42 AM</font><font size="2" face="Helvetica"><b><br>
Subject: </b></font><font size="2" face="Helvetica">Re: [LLVMdev] Improving loop vectorizer support for loops with a volatile iteration variable</font><font size="2" face="Arial"><br>
</font><font size="3" face="serif"><br>
<br>
</font><hr width="100%" size="2" align="left" id="zwchr_2">
<ul style="padding-left: 36pt"><font size="2" face="Helvetica"><b>From: </b></font><font size="2" face="Helvetica">"Chandler Carruth" <</font><a href="mailto:chandlerc@google.com"><font size="2" color="#0000FF" face="Helvetica"><u>chandlerc@google.com</u></font></a><font size="2" face="Helvetica">></font><font size="2" face="Helvetica"><b><br>
To: </b></font><font size="2" face="Helvetica">"Hal Finkel" <</font><a href="mailto:hfinkel@anl.gov"><font size="2" color="#0000FF" face="Helvetica"><u>hfinkel@anl.gov</u></font></a><font size="2" face="Helvetica">></font><font size="2" face="Helvetica"><b><br>
Cc: </b></font><font size="2" face="Helvetica">"Hyojin Sung" <</font><a href="mailto:hsung@us.ibm.com"><font size="2" color="#0000FF" face="Helvetica"><u>hsung@us.ibm.com</u></font></a><font size="2" face="Helvetica">>, </font><a href="mailto:llvmdev@cs.uiuc.edu"><font size="2" color="#0000FF" face="Helvetica"><u>llvmdev@cs.uiuc.edu</u></font></a><font size="2" face="Helvetica"><b><br>
Sent: </b></font><font size="2" face="Helvetica">Thursday, July 16, 2015 1:06:03 AM</font><font size="2" face="Helvetica"><b><br>
Subject: </b></font><font size="2" face="Helvetica">Re: [LLVMdev] Improving loop vectorizer support for loops with a volatile iteration variable<br>
<br>
On Wed, Jul 15, 2015 at 6:36 PM Hal Finkel <</font><a href="mailto:hfinkel@anl.gov" target="_blank"><font size="2" color="#0000FF" face="Helvetica"><u>hfinkel@anl.gov</u></font></a><font size="2" face="Helvetica">> wrote:</font><font size="3" face="serif"> </font>
<ul style="padding-left: 36pt"><font size="3" face="serif"><br>
</font><hr width="100%" size="2" align="left">
<ul style="padding-left: 36pt"><font size="2" face="Helvetica"><b>From: </b></font><font size="2" face="Helvetica">"Chandler Carruth" <</font><a href="mailto:chandlerc@google.com" target="_blank"><font size="2" color="#0000FF" face="Helvetica"><u>chandlerc@google.com</u></font></a><font size="2" face="Helvetica">></font><font size="2" face="Helvetica"><b><br>
To: </b></font><font size="2" face="Helvetica">"Hyojin Sung" <</font><a href="mailto:hsung@us.ibm.com" target="_blank"><font size="2" color="#0000FF" face="Helvetica"><u>hsung@us.ibm.com</u></font></a><font size="2" face="Helvetica">>, </font><a href="mailto:llvmdev@cs.uiuc.edu" target="_blank"><font size="2" color="#0000FF" face="Helvetica"><u>llvmdev@cs.uiuc.edu</u></font></a><font size="2" face="Helvetica"><b><br>
Sent: </b></font><font size="2" face="Helvetica">Wednesday, July 15, 2015 7:34:54 PM</font><font size="2" face="Helvetica"><b><br>
Subject: </b></font><font size="2" face="Helvetica">Re: [LLVMdev] Improving loop vectorizer support for loops with a volatile iteration variable</font><font size="3" face="serif"><br>
</font><font size="2" face="Helvetica"><br>
<br>
On Wed, Jul 15, 2015 at 12:55 PM Hyojin Sung <</font><a href="mailto:hsung@us.ibm.com" target="_blank"><font size="2" color="#0000FF" face="Helvetica"><u>hsung@us.ibm.com</u></font></a><font size="2" face="Helvetica">> wrote:</font><font size="3" face="serif"> </font>
<ul style="padding-left: 36pt"><font size="2" face="Helvetica">Hi all,<br>
<br>
I would like to propose an improvement of the “almost dead” block elimination in Transforms/Local.cpp so that it will preserve the canonical loop form for loops with a volatile iteration variable.<br>
<br>
*** Problem statement<br>
Nested loops in LCALS Subset B (</font><a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__codesign.llnl.gov_LCALS.php&d=AwMGaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=aWKfvN4c8lvUSvVn8J0Z2ajTctlBJf0198Au28epBr0&s=4d9dt5ODcDWHHatSrwu5ZYT9ebgVzNEtpOlIR87izCM&e=" target="_blank"><font size="2" color="#0000FF" face="Helvetica"><u>https://codesign.llnl.gov/LCALS.php</u></font></a><font size="2" face="Helvetica">) are not vectorized with LLVM -O3 because the LLVM loop vectorizer fails the test whether the loop latch and exiting block of a loop is the same. The loops are vectorizable, and get vectorized with LLVM -O2</font></ul>
<font size="2" face="Helvetica"><br>
I would be interested to know why -O2 succeeds here.</font><font size="3" face="serif"><br>
</font>
<ul style="padding-left: 36pt"><font size="2" face="Helvetica">and also with other commercial compilers (icc, xlc). <br>
<br>
*** Details<br>
These loops ended up with different loop latch and exiting block after a series of optimizations including loop unswitching, jump threading, simplify-the-CFG, and loop simplify. The fundamental problem here is that the above optimizations cannot recognize a loop with a volatile iteration variable and do not preserve its canonical loop structure.</font></ul>
<font size="2" face="Helvetica"><br>
Ok, meta-level question first:<br>
<br>
Why do we care about performance of loops with a volatile iteration variable? </font></ul>
<font size="2" face="Arial">I don't think we do, however, I think that misses the point. In this case, the volatile iteration variable is just an easy way to expose this problem that we have with nested loop canonicalization and the vectorizer. To be specific:<br>
<br>
This we vectorizer just fine:<br>
<br>
void foo1(float * restrict x, float * restrict y, float * restrict z) {<br>
for (int i = 0; i < 1000; ++i) {<br>
for (int j = 0; j < 1600; ++j) {<br>
x[j] = y[j] + z[j];<br>
}<br>
}<br>
}<br>
<br>
And, indeed, this we don't (the only change is adding volatile on i):<br>
<br>
void foo2(float * restrict x, float * restrict y, float * restrict z) {<br>
for (volatile int i = 0; i < 1000; ++i) {<br>
for (int j = 0; j < 1600; ++j) {<br>
x[j] = y[j] + z[j];<br>
}<br>
}<br>
}<br>
<br>
However, this we don't either, and that's a big problem:<br>
<br>
int done(float *x, float *y, float *z);<br>
void foo3(float * restrict x, float * restrict y, float * restrict z) {<br>
while (!done(x, y, z)) {<br>
for (int j = 0; j < 1600; ++j) {<br>
x[j] = y[j] + z[j];<br>
}<br>
}<br>
}<br>
<br>
And the underlying reason is the same. The IR at the point in time when the loop vectorizer runs looks like this:<br>
<br>
define void @foo3(float* noalias %x, float* noalias %y, float* noalias %z) #0 {<br>
entry:<br>
%call.14 = tail call i32 @done(float* %x, float* %y, float* %z) #1<br>
%lnot.15 = icmp eq i32 %call.14, 0<br>
br i1 %lnot.15, label %for.body.preheader, label %while.end<br>
<br>
for.body.preheader: ; preds = %entry<br>
br label %for.body<br>
<br>
while.cond.loopexit: ; preds = %for.body<br>
%call = tail call i32 @done(float* %x, float* %y, float* %z) #1<br>
%lnot = icmp eq i32 %call, 0<br>
br i1 %lnot, label %for.body.backedge, label %while.end.loopexit<br>
<br>
for.body: ; preds = %for.body.backedge, %for.body.preheader<br>
%indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %</font><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__indvars.iv.be&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=OE36IJuCyZctA3s37X7WGup5iAkOM11AM2CnhP5TBUk&s=JDHk2pO2X8ONZI6T-EtaJWjtJLzbBdKTvULQ6Te-xGI&e=" target="_blank"><font size="2" color="#0000FF" face="Arial"><u>indvars.iv.be</u></font></a><font size="2" face="Arial">, %for.body.backedge ]<br>
...<br>
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1<br>
%exitcond = icmp eq i64 %indvars.iv.next, 1600<br>
br i1 %exitcond, label %while.cond.loopexit, label %for.body.backedge<br>
<br>
for.body.backedge: ; preds = %for.body, %while.cond.loopexit<br>
%</font><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__indvars.iv.be&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=OE36IJuCyZctA3s37X7WGup5iAkOM11AM2CnhP5TBUk&s=JDHk2pO2X8ONZI6T-EtaJWjtJLzbBdKTvULQ6Te-xGI&e=" target="_blank"><font size="2" color="#0000FF" face="Arial"><u>indvars.iv.be</u></font></a><font size="2" face="Arial"> = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %while.cond.loopexit ]<br>
br label %for.body<br>
<br>
while.end.loopexit: ; preds = %while.cond.loopexit<br>
br label %while.end<br>
<br>
while.end: ; preds = %while.end.loopexit, %entry<br>
ret void<br>
}<br>
<br>
and we can currently only vectorize loops where the loop latch is also the loop's exiting block. In this case, as in the case with the volatile variable, vectorization is blocked by this constraint (here the backedge is from the terminator of %for.body.backedge, but the loop exiting block is %for.body). The check in the vectorizer is explicit:<br>
<br>
// We only handle bottom-tested loops, i.e. loop in which the condition is<br>
// checked at the end of each iteration. With that we can assume that all<br>
// instructions in the loop are executed the same number of times.<br>
if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch()) {<br>
...</font></ul>
<font size="2" face="Helvetica"><br>
Thanks for the detailed explanation. This makes much more sense why we need to handle it. I think its much better to look at nested loops of this form than anything to do with volatile -- the latter is too prone to other random optimizations turning off.<br>
<br>
Regarding this problem, it would be interesting to know based on this explanation what the desired fix would be. I see at least these options:<br>
<br>
1) Canonicalize loops harder to make them look the way the vectorizer wants. If this can be done without causing significant problems, it seems likely the best approach.</font></ul>
<font size="2" face="Arial">I agree. In this case, we could certainly fold the trivial %for.body.backedge block into %for.body, meaning transforming this:<br>
<br>
for.body.backedge: ; preds = %while.cond.loopexit, %for.body<br>
%</font><a href="http://indvars.iv.be/"><font size="2" color="#0000FF" face="Arial"><u>indvars.iv.be</u></font></a><font size="2" face="Arial"> = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %while.cond.loopexit ]<br>
br label %for.body<br>
<br>
for.body: ; preds = %for.body.backedge, %for.body.preheader<br>
%indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %</font><a href="http://indvars.iv.be/"><font size="2" color="#0000FF" face="Arial"><u>indvars.iv.be</u></font></a><font size="2" face="Arial">, %for.body.backedge ]<br>
...<br>
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1<br>
%exitcond = icmp eq i64 %indvars.iv.next, 1600<br>
br i1 %exitcond, label %while.cond.loopexit, label %for.body.backedge<br>
<br>
into this:<br>
<br>
for.body: ; preds = %for.body.backedge, %for.body.preheader<br>
%</font><a href="http://indvars.iv.be/"><font size="2" color="#0000FF" face="Arial"><u>indvars.iv.be</u></font></a><font size="2" face="Arial"> = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %while.cond.loopexit ]<br>
%indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %</font><a href="http://indvars.iv.be/"><font size="2" color="#0000FF" face="Arial"><u>indvars.iv.be</u></font></a><font size="2" face="Arial">, %for.body ]<br>
...<br>
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1<br>
%exitcond = icmp eq i64 %indvars.iv.next, 1600<br>
br i1 %exitcond, label %while.cond.loopexit, label %for.body<br>
<br>
and this seems pretty trivial when %for.body.backedge is completely empty (as in this case), but if it had non-PHI instructions in it on which the existing PHIs in %for.body depended, then maybe this becomes less trivial?</font></ul>
<font size="2" face="Arial">Although, based on what I said below, the case with instructions there we can't currently vectorize anyway for more-fundamental reasons.<br>
<br>
-Hal</font></ul>
<font size="2" face="Arial"><br>
Also worth pointing out that SimplifyCFG does this exact transformation. The vectorizer never sees it, however, because LoopSimplify prefers this form with the separate backedge block that the vectorizer can't handle.<br>
<br>
-Hal</font><font size="3" face="serif"> </font>
<ul style="padding-left: 36pt"><font size="2" face="Helvetica"><br>
2) Teach the vectorizer to vectorize without this constraint by instead establishing the actual invariant it cares about.</font><font size="2" face="Arial"><br>
It really cares that there's no code that comes in between the latch and the exit, because such code is not really part of the loop (it only runs once), or code in between the exit and the latch (because such code runs in one fewer iterations than the code before the exit). At least nothing with side effects I presume.<br>
<br>
-Hal</font><font size="3" face="serif"> </font>
<ul style="padding-left: 36pt"><font size="2" face="Helvetica"><br>
Maybe there is another strategy? </font><font size="3" face="serif"><br>
</font><font size="2" face="Helvetica"><br>
</font><font size="3" face="serif"><br>
</font>
<ul style="padding-left: 36pt"><font size="2" face="Arial"> -Hal</font><font size="3" face="serif"> </font>
<ul style="padding-left: 36pt"><font size="2" face="Helvetica">That seems both counter-intuitive and unlikely to be a useful goal. We simply don't optimize volatile operations well in *any* part of the optimizer, and I'm not sure why we need to start trying to fix that. This seems like an irreparably broken benchmark, but perhaps there is a motivation I don't yet see.</font><font size="3" face="serif"><br>
</font><font size="2" face="Helvetica"><br>
<br>
Assuming that sufficient motivation arises to try to fix this, see my comments below:</font><font size="3" face="serif"><br>
</font>
<ul style="padding-left: 36pt"><font size="2" face="Helvetica"><br>
<br>
(1) Loop unswitching generates several empty placeholder BBs only with PHI nodes after separating out a shorter path with no inner loop execution from a standard path. <br>
<br>
(2) Jump threading and simplify-the-CFG passes independently calls TryToSimplifyUnconditionalBranchFromEmptyBlock() in Transforms/Utils/Local.cpp to get rid of almost empty BBs. <br>
<br>
(3) TryToSimplifyUnconditionalBranchFromEmtpyBlock() eliminates the placeholder BBs after loop unswitching and merges them into subsequent blocks including the header of the inner loop. Before eliminating the blocks, the function checks if the block is a loop header by looking at its PHI nodes so that it can be saved, but the test fails with the loops with a volatile iteration variable.</font></ul>
<font size="2" face="Helvetica"><br>
Why does this fail for a volatile iteration variable but not for a non-volatile one? I think understanding that will be key to understanding how it should be fixed.<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list</font><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank"><font size="2" color="#0000FF" face="Helvetica"><u>LLVMdev@cs.uiuc.edu</u></font></a><font size="2" face="Helvetica"> </font><a href="http://llvm.cs.uiuc.edu/" target="_blank"><font size="2" color="#0000FF" face="Helvetica"><u>http://llvm.cs.uiuc.edu</u></font></a><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank"><font size="2" color="#0000FF" face="Helvetica"><u>http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</u></font></a></ul>
<font size="2" face="Arial"><br>
<br>
<br>
-- <br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory</font></ul>
</ul>
<font size="2" face="Arial"><br>
<br>
<br>
-- <br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory</font><font size="2" face="Helvetica"><br>
<br>
_______________________________________________<br>
LLVM Developers mailing list</font><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="mailto:LLVMdev@cs.uiuc.edu"><font size="2" color="#0000FF" face="Helvetica"><u>LLVMdev@cs.uiuc.edu</u></font></a><font size="2" face="Helvetica"> </font><a href="http://llvm.cs.uiuc.edu/"><font size="2" color="#0000FF" face="Helvetica"><u>http://llvm.cs.uiuc.edu</u></font></a><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev"><font size="2" color="#0000FF" face="Helvetica"><u>http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</u></font></a><br>
<font size="2" face="Arial"><br>
<br>
<br>
-- <br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory</font><font size="2" face="Helvetica"><br>
<br>
_______________________________________________<br>
LLVM Developers mailing list</font><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="mailto:LLVMdev@cs.uiuc.edu"><font size="2" color="#0000FF" face="Helvetica"><u>LLVMdev@cs.uiuc.edu</u></font></a><font size="2" face="Helvetica"> </font><a href="http://llvm.cs.uiuc.edu/"><font size="2" color="#0000FF" face="Helvetica"><u>http://llvm.cs.uiuc.edu</u></font></a><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev"><font size="2" color="#0000FF" face="Helvetica"><u>http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</u></font></a></ul>
<font size="2" face="Arial"><br>
<br>
<br>
-- <br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory</font><tt><font size="2">_______________________________________________<br>
LLVM Developers mailing list</font></tt><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="mailto:LLVMdev@cs.uiuc.edu"><tt><font size="2" color="#0000FF"><u>LLVMdev@cs.uiuc.edu</u></font></tt></a><tt><font size="2"> </font></tt><a href="http://llvm.cs.uiuc.edu/"><tt><font size="2" color="#0000FF"><u>http://llvm.cs.uiuc.edu</u></font></tt></a><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev"><tt><font size="2" color="#0000FF"><u>http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</u></font></tt></a><font size="3" face="serif"><br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list</font><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="mailto:LLVMdev@cs.uiuc.edu"><font size="3" color="#0000FF" face="serif"><u>LLVMdev@cs.uiuc.edu</u></font></a><font size="3" face="serif"> </font><a href="http://llvm.cs.uiuc.edu/"><font size="3" color="#0000FF" face="serif"><u>http://llvm.cs.uiuc.edu</u></font></a><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev"><font size="3" color="#0000FF" face="serif"><u>http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</u></font></a></ul>
<font size="3" face="serif"><br>
</font></ul>
</ul>
</ul>
<br>
<br>
</body></html>