<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Can you post the two IR online?<div class=""><br class=""></div><div class="">— </div><div class="">Mehdi</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 21, 2015, at 8:27 PM, Xiangyang Guo via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi, <div class=""><br class=""></div><div class="">I just tried llvm-3.8 (LLVM SVN Repository). With this version, -fno-rtti can help me to compile my code and -irce can help me to do a better job for loop unrolling. However, I still have one question. If I use Clang to compile a piece of c++ code to .bc and then use 'opt -loop-rotate -loop-unroll -irce', I can get what I want. I mean, there is no conditional branch at the end of each unrolled part. However, If I use LLVM API such as IRBuilder (CreateAdd, CreateGEP, CreateLoad and so on) to generate the .bc (I dump the two .bc files and they looks like almost same except the variable name), then 'opt -loop-rotate -loop-unroll -irce'I cannot get what I want. I mean, in this case, there is still loop boundary checking (add, compare, conditional branch) at the end of each unrolled part. </div><div class=""><br class=""></div><div class="">I'm really confused about this. Does Clang do something special? Or do I need to do something else to eliminate the unnecessary loop boundary checking at the end of each unrolled part?</div><div class=""><br class=""></div><div class="">Thanks for your help.</div><div class=""><br class=""></div><div class="">Xiangyang</div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Aug 21, 2015 at 11:29 AM, Xiangyang Guo <span dir="ltr" class=""><<a href="mailto:xguo6@ncsu.edu" target="_blank" class="">xguo6@ncsu.edu</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Hi, Jeremy,<div class=""><br class=""></div><div class="">Thanks for your reply. I tried -fno-rtti yesterday and no luck.</div><div class=""><br class=""></div><div class="">Regards,</div><div class=""><br class=""></div><div class="">Xiangyang</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Aug 21, 2015 at 11:05 AM, Jeremy Lakeman <span dir="ltr" class=""><<a href="mailto:Jeremy.Lakeman@gmail.com" target="_blank" class="">Jeremy.Lakeman@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="">There's been some recent noise on the mailing list about requiring -fno-rtti;<br class=""><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_pipermail_llvm-2Ddev_2015-2DAugust_089010.html&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=v-ruWq0KCv2O3thJZiK6naxuXK8mQHZUmGq5FBtAmZ4&m=iK-4Sl62Seah5JOtnUG-QuscAiOsYnFzalJonc_U6VU&s=ymrIB-O3ZSdNYeAr6O77yr2EXY5oYesx1dTE2lvYifs&e=" target="_blank" class="">http://lists.llvm.org/pipermail/llvm-dev/2015-August/089010.html</a><br class=""><br class=""></div>Could that be it?<br class=""></div><div class=""><div class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sat, Aug 22, 2015 at 12:21 AM, Xiangyang Guo via llvm-dev <span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Hi, James and Philip, Thanks for your help.<div class=""><br class=""></div><div class="">Based on your advice, I downloaded llvm-3.7. However, with this new version of LLVM, I have the following errors when I compile my previous code:</div><div class=""><br class=""></div><div class=""><div class="">g++ -o parser main.o `llvm-config --libs all` `llvm-config --ldflags --system-libs` -lpthread -ldl -rdynamic -ltinfo</div><div class="">main.o:(.data.rel.ro._ZTIN4llvm17GetElementPtrInstE[_ZTIN4llvm17GetElementPtrInstE]+0x10): undefined reference to `typeinfo for llvm::Instruction'</div><div class="">main.o:(.data.rel.ro._ZTIN4llvm8ICmpInstE[_ZTIN4llvm8ICmpInstE]+0x10): undefined reference to `typeinfo for llvm::CmpInst'</div></div><div class=""><br class=""></div><div class="">BTW, in my code, I use LLVM API (IRBuilder and so on) to generate one Module and then use PassManager to add several passes. And my Makefile is pretty simple, it looks like this:</div><div class="">***********************************************************************************************</div><div class=""><div class="">all: parser</div><div class=""><br class=""></div><div class="">OBJS = main.o \</div><div class=""><br class=""></div><div class="">LLVMCONFIG = llvm-config</div><div class="">CPPFLAGS = `$(LLVMCONFIG) --cxxflags` -std=c++11</div><div class="">LDFLAGS = `$(LLVMCONFIG) --ldflags --system-libs` -lpthread -ldl -rdynamic -ltinfo</div><div class="">LIBS = `$(LLVMCONFIG) --libs all`</div><div class=""><br class=""></div><div class="">clean:</div><div class=""><span style="white-space:pre-wrap" class=""> </span>$(RM) -rf parser $(OBJS)</div><div class=""><br class=""></div><div class="">%.o: %.cpp</div><div class=""><span style="white-space:pre-wrap" class=""> </span>g++ -g -c $(CPPFLAGS) -o $@ $<</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">parser: $(OBJS)</div><div class=""><span style="white-space:pre-wrap" class=""> </span>g++ -o $@ $(OBJS) $(LIBS) $(LDFLAGS)</div></div><div class="">**********************************************************************************************</div><div class="">Do you have any idea? Thanks a lot.</div><div class=""><br class=""></div><div class="">Regards,</div><div class=""><br class=""></div><div class="">Xiangyang </div></div><div class=""><div class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Aug 20, 2015 at 2:23 PM, James Molloy <span dir="ltr" class=""><<a href="mailto:james@jamesmolloy.co.uk" target="_blank" class="">james@jamesmolloy.co.uk</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Hi Xiangyang,<div class=""><br class=""></div><div class="">The algorithm for loop unrolling was changed post-3.5 to do more what you'd expect. If you use 3.6 or 3.7 you'll likely get better results.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">James</div></div><div class=""><div class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, 20 Aug 2015 at 18:09 Philip Reames via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000" class="">
<div class="">On 08/20/2015 07:38 AM, Xiangyang Guo
via llvm-dev wrote:<br class="">
</div>
<blockquote type="cite" class="">
<div dir="ltr" class=""><span style="font-size:12.8000001907349px" class="">Hi, </span>
<div style="font-size:12.8000001907349px" class=""><br class="">
</div>
<div style="font-size:12.8000001907349px" class="">I want to use loop
unrolling pass, however, I find that loop unrolling will
introduces conditional branch at end of every "unrolled" part.
For example, consider the following code</div>
<div style="font-size:12.8000001907349px" class=""><br class="">
</div>
<div style="font-size:12.8000001907349px" class="">
<div class=""><i class="">void foo( int n, int array_x[])</i></div>
<div class=""><i class="">{</i></div>
<div class=""><i class=""> for (int i=0; i < n; i++)</i></div>
<div class=""><i class=""><span style="white-space:pre-wrap" class=""> </span>
array_x[i] = i; </i></div>
<div class=""><i class="">}</i></div>
</div>
<div style="font-size:12.8000001907349px" class=""><br class="">
</div>
<div style="font-size:12.8000001907349px" class="">Then I use this
command "opt-3.5 try.bc -mem2reg -loops -loop-simplify
-loop-rotate -lcssa -indvars -loop-unroll -unroll-count=3
-simplifycfg -S", it gives me this IR:</div>
<div style="font-size:12.8000001907349px" class=""><br class="">
</div>
<div style="font-size:12.8000001907349px" class="">
<div class=""><i class="">define void @_Z3fooiPi(i32 %n, i32* %array_x) #0 {</i></div>
<div class=""><i class=""> %1 = icmp slt i32 0, %n</i></div>
<div class=""><i class=""> br i1 %1, label %.<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lr.ph_&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=v-ruWq0KCv2O3thJZiK6naxuXK8mQHZUmGq5FBtAmZ4&m=iK-4Sl62Seah5JOtnUG-QuscAiOsYnFzalJonc_U6VU&s=EfR7wZAtVvK4UskGT4q9WtTD1gQPKtWnoc6nhM3hQoQ&e=" target="_blank" class="">lr.ph</a>, label
%._crit_edge</i></div>
<div class=""><i class=""><br class="">
</i></div>
<div class=""><i class="">.<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lr.ph_&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=v-ruWq0KCv2O3thJZiK6naxuXK8mQHZUmGq5FBtAmZ4&m=iK-4Sl62Seah5JOtnUG-QuscAiOsYnFzalJonc_U6VU&s=EfR7wZAtVvK4UskGT4q9WtTD1gQPKtWnoc6nhM3hQoQ&e=" target="_blank" class="">lr.ph</a>:
; preds = %0, %7</i></div>
<div class=""><i class=""> %indvars.iv = phi i64 [ %indvars.iv.next.2, %7 ], [
0, %0 ]</i></div>
<div class=""><i class=""> %2 = getelementptr inbounds i32* %array_x, i64
%indvars.iv</i></div>
<div class=""><i class=""> %3 = trunc i64 %indvars.iv to i32</i></div>
<div class=""><i class=""> store i32 %3, i32* %2</i></div>
<div class=""><i class=""> %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1</i></div>
<div class=""><i class=""> %lftr.wideiv = trunc i64 %indvars.iv.next to i32</i></div>
<div class=""><i class=""> %exitcond = icmp ne i32 %lftr.wideiv, %n</i></div>
<div class=""><i class=""> br i1 %exitcond, label %4, label %._crit_edge</i></div>
<div class=""><i class=""><br class="">
</i></div>
<div class=""><i class="">._crit_edge: ;
preds = %.<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lr.ph_&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=v-ruWq0KCv2O3thJZiK6naxuXK8mQHZUmGq5FBtAmZ4&m=iK-4Sl62Seah5JOtnUG-QuscAiOsYnFzalJonc_U6VU&s=EfR7wZAtVvK4UskGT4q9WtTD1gQPKtWnoc6nhM3hQoQ&e=" target="_blank" class="">lr.ph</a>, %4, %7, %0</i></div>
<div class=""><i class=""> ret void</i></div>
<div class=""><i class=""><br class="">
</i></div>
<div class=""><i class="">; <label>:4
; preds = %.<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lr.ph_&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=v-ruWq0KCv2O3thJZiK6naxuXK8mQHZUmGq5FBtAmZ4&m=iK-4Sl62Seah5JOtnUG-QuscAiOsYnFzalJonc_U6VU&s=EfR7wZAtVvK4UskGT4q9WtTD1gQPKtWnoc6nhM3hQoQ&e=" target="_blank" class="">lr.ph</a></i></div>
<div class=""><i class=""> %5 = getelementptr inbounds i32* %array_x, i64
%indvars.iv.next</i></div>
<div class=""><i class=""> %6 = trunc i64 %indvars.iv.next to i32</i></div>
<div class=""><i class=""> store i32 %6, i32* %5</i></div>
<div class=""><i class=""> %indvars.iv.next.1 = add nuw nsw i64
%indvars.iv.next, 1</i></div>
<div class=""><i class=""> %lftr.wideiv.1 = trunc i64 %indvars.iv.next.1 to i32</i></div>
<div class=""><i class=""> %exitcond.1 = icmp ne i32 %lftr.wideiv.1, %n</i></div>
<div class=""><i class=""> br i1 %exitcond.1, label %7, label %._crit_edge</i></div>
<div class=""><i class=""><br class="">
</i></div>
<div class=""><i class="">; <label>:7
; preds = %4</i></div>
<div class=""><i class=""> %8 = getelementptr inbounds i32* %array_x, i64
%indvars.iv.next.1</i></div>
<div class=""><i class=""> %9 = trunc i64 %indvars.iv.next.1 to i32</i></div>
<div class=""><i class=""> store i32 %9, i32* %8</i></div>
<div class=""><i class=""> %indvars.iv.next.2 = add nuw nsw i64
%indvars.iv.next.1, 1</i></div>
<div class=""><i class=""> %lftr.wideiv.2 = trunc i64 %indvars.iv.next.2 to i32</i></div>
<div class=""><i class=""> %exitcond.2 = icmp ne i32 %lftr.wideiv.2, %n</i></div>
<div class=""><i class=""> br i1 %exitcond.2, label %.<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lr.ph_&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=v-ruWq0KCv2O3thJZiK6naxuXK8mQHZUmGq5FBtAmZ4&m=iK-4Sl62Seah5JOtnUG-QuscAiOsYnFzalJonc_U6VU&s=EfR7wZAtVvK4UskGT4q9WtTD1gQPKtWnoc6nhM3hQoQ&e=" target="_blank" class="">lr.ph</a>, label
%._crit_edge</i></div>
<div class=""><i class="">}</i></div>
</div>
<div style="font-size:12.8000001907349px" class=""><br class="">
</div>
<div style="font-size:12.8000001907349px" class="">As you can see, at the
end of BB <label>4 and BB<label>7 there are "add",
"icmp" and "br" instrcutions to check the boundary. I
understand this is for the correctness. However, I would
expect the loop unrolling can change my code to something like
this:</div>
<div style="font-size:12.8000001907349px" class=""><br class="">
</div>
<div style="font-size:12.8000001907349px" class="">
<div class=""><i class="">void foo( int n, int array_x[])</i></div>
<div class=""><i class="">{</i></div>
<div class=""><i class=""> int j = n%3;</i></div>
<div class=""><i class=""> int m = n - j;</i></div>
<div class=""><i class=""> for (int i=0; i < m; i+=3){</i></div>
<div class=""><i class=""><span style="white-space:pre-wrap" class=""> </span>
array_x[i] = i;</i></div>
<div class=""><i class=""><span style="white-space:pre-wrap" class=""> </span>
array_x[i+1] = i+1;</i></div>
<div class=""><i class=""><span style="white-space:pre-wrap" class=""> </span>
array_x[i+2] = i+2; </i></div>
<div class=""><i class=""> }</i></div>
<div class=""><i class=""> for(i=m; i<n; i++)</i></div>
<div class=""><i class=""><span style="white-space:pre-wrap" class=""> </span>
array_x[i] = i; </i></div>
<div class=""><i class="">}</i></div>
</div>
<div style="font-size:12.8000001907349px" class=""><br class="">
</div>
<div style="font-size:12.8000001907349px" class="">In this case, the
BB<label>4 and BB<label>7 will do not have the
"add", "icmp" and "br" instructions because these BBs can be
merged together.</div>
<div style="font-size:12.8000001907349px" class=""><br class="">
</div>
<div style="font-size:12.8000001907349px" class="">How can I achieve
this? Thanks.</div>
</div>
</blockquote></div><div bgcolor="#FFFFFF" text="#000000" class="">
One - rather heavy weight - way to do this would be to add the -irce
pass after the loop unroll step. InductiveRangeCheckElimination
will introduce a post loop so as to eliminate the range checks in
the inner loop. This might not be the ideal transformation for this
code, but it might get you closer to what you want.<br class="">
<br class="">
A couple of caveats:<br class="">
- 3.5 isn't recent enough to have a stable IRCE. Download ToT.<br class="">
- IRCE requires profiling information on the branches. I'd start by
manually annotating your IR to see if it works, then exploring a
profile build if it does. <br class="">
<br class="">
For the record, teaching the unroller to do this transformation (or
a creating a new pass) would seem interesting. You might check with
Chandler and/or Michael (see recent review threads) for what their
plans in this area are. <br class=""></div><div bgcolor="#FFFFFF" text="#000000" class="">
<blockquote type="cite" class="">
<div dir="ltr" class="">
<div style="font-size:12.8000001907349px" class=""><br class="">
</div>
<div style="font-size:12.8000001907349px" class="">Regards,</div>
<div style="font-size:12.8000001907349px" class=""><br class="">
</div>
<div style="font-size:12.8000001907349px" class="">Xiangyang</div>
</div>
<br class="">
<fieldset class=""></fieldset>
<br class="">
<pre class="">_______________________________________________
LLVM Developers mailing list
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Ddev&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=v-ruWq0KCv2O3thJZiK6naxuXK8mQHZUmGq5FBtAmZ4&m=iK-4Sl62Seah5JOtnUG-QuscAiOsYnFzalJonc_U6VU&s=mU0cUMoFPfz5slShAmRjaZoumLcsbxGp-IZOS-__wUk&e=" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<br class="">
</div>
_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Ddev&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=v-ruWq0KCv2O3thJZiK6naxuXK8mQHZUmGq5FBtAmZ4&m=iK-4Sl62Seah5JOtnUG-QuscAiOsYnFzalJonc_U6VU&s=mU0cUMoFPfz5slShAmRjaZoumLcsbxGp-IZOS-__wUk&e=" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
</blockquote></div>
</div></div></blockquote></div><br class=""></div>
</div></div><br class="">_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Ddev&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=v-ruWq0KCv2O3thJZiK6naxuXK8mQHZUmGq5FBtAmZ4&m=iK-4Sl62Seah5JOtnUG-QuscAiOsYnFzalJonc_U6VU&s=mU0cUMoFPfz5slShAmRjaZoumLcsbxGp-IZOS-__wUk&e=" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></div></blockquote></div><br class=""></div>
</div></div></blockquote></div><br class=""></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Ddev&d=BQIGaQ&c=eEvniauFctOgLOKGJOplqw&r=v-ruWq0KCv2O3thJZiK6naxuXK8mQHZUmGq5FBtAmZ4&m=iK-4Sl62Seah5JOtnUG-QuscAiOsYnFzalJonc_U6VU&s=mU0cUMoFPfz5slShAmRjaZoumLcsbxGp-IZOS-__wUk&e= <br class=""></div></blockquote></div><br class=""></div></body></html>