<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><p style="margin: 0;">Hi, </p><div style="margin: 0;">sorry for not describing it clearly. I modified a simple generated IR for for-loop. The example is as below:</div><div style="margin: 0;">---------------------------------------------------------------------------------------------------------------------</div><div style="margin: 0;">; Function Attrs: noinline nounwind optnone<br>define dso_local i32 @test(i32 %max, i32 %cmp1, i32 %cmp2) #0 {<br>entry:<br> %max.addr = alloca i32, align 4<br> %cmp1.addr = alloca i32, align4<br> %cmp2.addr = alloca i32, align4<br> %result = alloca i32, align 4<br> %i = alloca i32, align 4<br> store i32 %max, i32* %max.addr, align 4<br> store i32 0, i32* %result, align 4<br> store i32 0, i32* %i, align 4<br> br label %for.cond</div><div style="margin: 0;">for.cond: ; preds = %for.inc, %entry<br> %0 = load i32, i32* %i, align 4<br> %1 = load i32, i32* %max.addr, align 4<br> %cmp = icmp sle i32 %0, %1<br> br i1 %cmp, label %for.body, label %for.end</div><div style="margin: 0;">for.cond.2:<br> %6 = load i32, i32* %cmp1.addr, align4<br> %7 = load i32, i32* %cmp2.addr, align4<br> %cmp.2 = icmp sle i32 %6, %7<br> br i1 %cmp.2, label %for.body, label %for.end</div><div style="margin: 0;">for.body: ; preds = %for.cond<br> %2 = load i32, i32* %i, align 4<br> %3 = load i32, i32* %result, align 4<br> %add = add nsw i32 %3, %2<br> store i32 %add, i32* %result, align 4<br> br label %for.inc</div><div style="margin: 0;">for.inc: ; preds = %for.body<br> %4 = load i32, i32* %i, align 4<br> %inc = add nsw i32 %4, 1<br> store i32 %inc, i32* %i, align 4<br> br label %for.cond</div><div style="margin: 0;">for.end: ; preds = %for.cond<br> %5 = load i32, i32* %result, align 4<br> ret i32 %5<br>}<br></div><div style="margin: 0;">---------------------------------------------------------------------------------------------------------------------</div><div style="margin: 0;"> Thanks,</div><div style="margin: 0;">Jerry</div><p style="margin: 0;"><br></p><p style="margin: 0;"><br></p><div style="position:relative;zoom:1"></div><div id="divNeteaseMailCard"></div><p style="margin: 0;"><br></p><p>At 2020-03-20 15:25:28, "Johannes Doerfert" <johannesdoerfert@gmail.com> wrote:</p><blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<p>Hi Jerry,</p>
<p><br>
</p>
<p>I cannot follow your example nor do I understand your question.<br>
</p>
<p>Could you please post a minimal but complete LLVM-IR example and
rephrase the question.</p>
<p><br>
</p>
<p>Thanks,</p>
<p> Johannes</p>
<p><br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 3/19/20 8:47 PM, ÁÖÕþ×Ú via llvm-dev
wrote:<br>
</div>
<blockquote cite="mid:311610db.1dd4.170f59f555b.Coremail.jackie_linzz@126.com" type="cite">
<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial">
<div style="margin:0;">Hi,</div>
<div style="margin:0;">I have read an email from the mail list.
And I have a question about loop rotation. What is it if it is
the case below.</div>
<div style="margin:0;"><font face="Consolas"><font size="2"><span style="text-align: left; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; font-variant: normal; word-spacing: 0px; display: inline !important; white-space: pre-wrap; orphans: 2; float: none; -webkit-text-stroke-width: 0px; background-color: transparent;"><div style="background-color: transparent; color: rgb(0, 0, 0); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">--------------------------------------------------------------------------</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"><font face="Consolas" style="background-color: transparent; color: rgb(0, 0, 0); font-family: Consolas; font-size: 14px; line-height: 23.8px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><font size="2" style="background-color: transparent; color: rgb(0, 0, 0); font-family: Consolas; font-size: 13.33px; line-height: 22.66px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">loop:</font></font></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"><font face="Consolas" style="background-color: transparent; color: rgb(0, 0, 0); font-family: Consolas; font-size: 14px; line-height: 23.8px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><font size="2" style="background-color: transparent; color: rgb(0, 0, 0); font-family: Consolas; font-size: 13.33px; line-height: 22.66px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="background-color: transparent; color: rgb(0, 0, 0); display: inline; float: none; font-family: Consolas; font-size: 13.33px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre-wrap; word-spacing: 0px;">A
br X
B
br Y
C
br loop, Z
-------------------------------------------------
Thanks!
Jerry
<h1 style="background-color: transparent; color: rgb(0, 0, 0); font-family: Times New Roman; font-size: 32px; font-style: normal; font-variant: normal; font-weight: 700; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">[LLVMdev] Loop rotation and loop inversion in LLVM?</h1><span style="display: inline !important; float: none; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">
</span><b style="background-color: transparent; color: rgb(0, 0, 0); font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 700; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">Andrew Trick</b><span style="display: inline !important; float: none; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">
</span><a title="[LLVMdev] Loop rotation and loop inversion in LLVM?" style="background-color: transparent; color: rgb(0, 102, 204); font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: underline; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;" moz-do-not-send="true">atrick at apple.com
</a>
<span style="display: inline !important; float: none; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">
</span><i style="background-color: transparent; color: rgb(0, 0, 0); font-family: Times New Roman; font-size: 16px; font-style: italic; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">Mon May 20 10:36:00 PDT 2013</i><span style="display: inline !important; float: none; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">
</span><ul style="background-color: transparent; color: rgb(0, 0, 0); font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">
<li>Previous message: <a href="http://lists.llvm.org/pipermail/llvm-dev/2013-May/062185.html" moz-do-not-send="true">[LLVMdev] Loop rotation and loop inversion in LLVM?
</a></li>
<li>Next message: <a href="http://lists.llvm.org/pipermail/llvm-dev/2013-May/062186.html" moz-do-not-send="true">[LLVMdev] Vararg Intrinsics still supported?
</a></li>
<li> <b>Messages sorted by:</b>
<a href="http://lists.llvm.org/pipermail/llvm-dev/2013-May/date.html#62260" moz-do-not-send="true">[ date ]</a>
<a href="http://lists.llvm.org/pipermail/llvm-dev/2013-May/thread.html#62260" moz-do-not-send="true">[ thread ]</a>
<a href="http://lists.llvm.org/pipermail/llvm-dev/2013-May/subject.html#62260" moz-do-not-send="true">[ subject ]</a>
<a href="http://lists.llvm.org/pipermail/llvm-dev/2013-May/author.html#62260" moz-do-not-send="true">[ author ]</a>
</li>
</ul><span style="display: inline !important; float: none; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">
</span><hr style="background-color: transparent; color: rgb(0, 0, 0); font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: center; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"><span style="display: inline !important; float: none; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">
</span><span style="display: inline !important; float: none; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">
</span><pre style="background-color: transparent; color: rgb(0, 0, 0); font-family: Consolas; font-size: 13.33px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre-wrap; word-spacing: 0px;">On May 16, 2013, at 5:07 PM, Paul Sokolovsky <<a style="white-space: pre-wrap;" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" moz-do-not-send="true">pmiscml at gmail.com</a>> wrote:
><i style="white-space: pre-wrap;"> Hello,
</i>><i style="white-space: pre-wrap;">
</i>><i style="white-space: pre-wrap;"> I'd be interested in knowing which pass performs loop inversion, i.e.
</i>><i style="white-space: pre-wrap;"> transforms while loop into do/while wrapped with if. So, it's pretty
</i>><i style="white-space: pre-wrap;"> easy to understand concept, <a style="white-space: pre-wrap;" href="http://en.wikipedia.org/wiki/Loop_inversion" moz-do-not-send="true">http://en.wikipedia.org/wiki/Loop_inversion</a>
</i>><i style="white-space: pre-wrap;"> provides description of how its done and motivation, googling gives
</i>><i style="white-space: pre-wrap;"> several relevant references, i.e. it's pretty settled term.
</i>><i style="white-space: pre-wrap;">
</i>><i style="white-space: pre-wrap;"> I also see this transform to be actually performed on trivial strlen
</i>><i style="white-space: pre-wrap;"> function by clang -O2. However opt --help or grepping LLVM doesn't give
</i>><i style="white-space: pre-wrap;"> any hints.
</i>><i style="white-space: pre-wrap;">
</i>><i style="white-space: pre-wrap;"> However, -loop-rotate calls attention, described as "A simple loop
</i>><i style="white-space: pre-wrap;"> rotation transformation." However, Wikipedia doesn't gives hits for
</i>><i style="white-space: pre-wrap;"> that related to compilation/optimization theory, nor google hits are
</i>><i style="white-space: pre-wrap;"> relevant either - mostly LLVM-related hits just mentioning the term.
</i>><i style="white-space: pre-wrap;">
</i>><i style="white-space: pre-wrap;"> Trying -loop-rotate, I see loop being converted to post-condition, but
</i>><i style="white-space: pre-wrap;"> don't see if wrapper around it.
</i>><i style="white-space: pre-wrap;">
</i>><i style="white-space: pre-wrap;"> So, can anyone suggest if LLVM loop rotation is related to loop
</i>><i style="white-space: pre-wrap;"> inversion in Wikipedia terms, and if not, what it is.
</i>
On simple ¡®for¡¯ loops, rotation degenerates to inversion. Rotation is a more general transform that spans the range from inversion to loop peeling...
loop:
A
br X
B
br loop, Y
A¡¯
br X
loop:
B
br Y
A
br loop, X
Sorry I don¡¯t know of a text-book reference off-hand. I¡¯ve seen it in practice before and assumed it was pretty standard. In LLVM it¡¯s mostly used to put loops in a canonical form, but it¡¯s also a cheap and dirty way to expose LICM. Another benefit is simplifying trip count expressions.
><i style="white-space: pre-wrap;"> And I hope that this feedback will allow maintainers to make
</i>><i style="white-space: pre-wrap;"> documentation clearer and more user-friendly.
</i>
Me too :) Not sure if I¡¯ll get around to it, but I¡¯d be happy to review a patch.
-Andy
><i style="white-space: pre-wrap;"> Thanks,
</i>><i style="white-space: pre-wrap;"> Paul mailto:<a style="white-space: pre-wrap;" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" moz-do-not-send="true">pmiscml at gmail.com</a>
</i>><i style="white-space: pre-wrap;"> _______________________________________________
</i>><i style="white-space: pre-wrap;"> LLVM Developers mailing list
</i>><i style="white-space: pre-wrap;"> <a style="white-space: pre-wrap;" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" moz-do-not-send="true">LLVMdev at cs.uiuc.edu</a> <a style="white-space: pre-wrap;" href="http://llvm.cs.uiuc.edu/" moz-do-not-send="true">http://llvm.cs.uiuc.edu</a>
</i>><i style="white-space: pre-wrap;"> <a style="white-space: pre-wrap;" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" moz-do-not-send="true">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</i>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <<a style="white-space: pre-wrap;" href="http://lists.llvm.org/pipermail/llvm-dev/attachments/20130520/49bb14f9/attachment.html" moz-do-not-send="true">http://lists.llvm.org/pipermail/llvm-dev/attachments/20130520/49bb14f9/attachment.html</a>>
</pre>
</span></font></font></div><b>
</b></span></font></font></div>
<div style="margin:0;"><font face="Consolas"><font size="2"><span style="text-align: left; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; word-spacing: 0px; display: inline !important; white-space: pre-wrap; orphans: 2; float: none; -webkit-text-stroke-width: 0px; background-color: transparent;">
</span></font></font><br>
</div>
</div>
<br>
<br>
<span title="neteasefooter">
<p> </p>
</span><br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
</blockquote></div><br><br><span title="neteasefooter"><p> </p></span>