<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<br>
<div class="moz-cite-prefix">On 08/13/2015 05:49 PM, David Jones via
llvm-dev wrote:<br>
</div>
<blockquote
cite="mid:CAEwg-Q+h2428hNH_L+4in_yTUQUw3jDgcq2TEddEUOq6LrURqQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>I have an IR file that takes an
unacceptably long time to optimize and
generate code for.<br>
<br>
</div>
<div>I am using LLVM 3.5.1 for now.<br>
<br>
</div>
If I run<br>
<br>
</div>
opt -time-passes -std-compile-opts -o opt.bc
my.ll<br>
<br>
</div>
opt takes about 3-4 minutes, only to report that
it spent about 25 seconds optimizing the code.<br>
<br>
</div>
After running perf, it appears to me that opt is
not accounting for a lot of time spent in
Verifier::visitGlobalVariable(). This routine
appears to traverse complex initializer
expressions looking for bitcasts between address
spaces. Such bitcasts do not occur in my code - I
use only the default address space.<br>
<br>
</div>
My IR has lots of complex interlinked data
structures, e.g.:<br>
<br>
@xxx.Std = constant [24 x i64] [i64 5665, i64
ptrtoint ([13 x i8]* @25342 to i64), i64 72, i64
ptrtoint ([2360 x i64]* @yyy.Std to i64), i64
ptrtoint ([4 x i64]* @25343 to i64), i64 ptrtoint
([11 x i8]* @25344 to i64), i64 24, i64 -1, i64
ptrtoint ([4 x i64]* @25345 to i64), i64 ptrtoint
([6 x i8]* @25346 to i64), i64 48, i64 -1, i64
ptrtoint ([2 x i64]* @25348 to i64), i64 ptrtoint
([10 x i8]* @25349 to i64), i64 0, i64 -1, i64
ptrtoint ([2 x i64]* @25351 to i64), i64 ptrtoint
([4 x i8]* @25352 to i64), i64 0, i64 -1, i64 0, i64
0, i64 0, i64 0]<br>
<br>
</div>
<div>@yyy.Std likely contains a reference to @xxx.Std.<br>
<br>
</div>
These data structures document the layout of types and
variables in the program in ways that runtime
functions can easily use.<br>
<br>
</div>
<div>If I hand-edit my IR to remove all function
definitions, replacing them with equivalent
declarations, but otherwise keep all type and data
definitions the same, then opt takes almost just as
long, but happily reports that it was able to optimize
my code in 0.2 seconds. Not bad, because there is no
code. :-)<br>
<br>
</div>
My question: what can I do about this?<br>
</div>
- Does it make sense to disable the verifier in
production?<br>
</div>
- Can I recode my data declarations in some way to reduce
the impact? I was planning on changing the format of the
data structures; the planned changes would remove the
ptrtoint instructions. Would doing so help?<br>
</div>
- Would it help to reduce the amount of other constant data in
the IR? Although LLVM itself collapses duplicate constant
data, I could easily do so myself. Would doing so help?<br>
</div>
</div>
</blockquote>
My first suggestion would be to improve the code in the verifier
that's problematic for you. I suspect you could make that piece of
code far faster and the patch would be easy to get accepted
upstream. <br>
<br>
Two particular suggestions:<br>
- Filter common elements before adding to worklist. If you use a
SmallVectorSet rather than the two data structures currently used,
this will happen for you.<br>
- Increase the 'small size' of the SmallX data structures to
something reasonable like 32. This will get the algorithm running
entirely in stack memory for your example rather than allocating for
each visited global. <br>
<br>
After those two, I suspect you'll see this function disappear from
your profile. <br>
<blockquote
cite="mid:CAEwg-Q+h2428hNH_L+4in_yTUQUw3jDgcq2TEddEUOq6LrURqQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><br>
</div>
(Note: the interlinked data structures do not contain duplicate
data, so any attempt at manually reducing the duplicate data
would have zero impact on the linked structures.)<br>
<br>
<div>
<div><br>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<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="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>