<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 4/20/2017 3:10 PM, Mikhail
Zolotukhin wrote:<br>
</div>
<blockquote type="cite"
cite="mid:D578A2DF-FEB7-4E43-B35B-C91DB81FFE6F@apple.com">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<br class="">
<div>
<blockquote type="cite" class="">
<div class="">On Apr 20, 2017, at 2:39 PM, Friedman, Eli <<a
href="mailto:efriedma@codeaurora.org" class=""
moz-do-not-send="true">efriedma@codeaurora.org</a>>
wrote:</div>
<br class="Apple-interchange-newline">
<div class=""><span style="font-family: Helvetica; font-size:
12px; font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; float: none; display:
inline !important;" class="">The testcase is derived from
a loop we were looking at while doing some polly-related
work; not sure if it has any visible performance benefit
elsewhere.</span><br style="font-family: Helvetica;
font-size: 12px; font-style: normal; font-variant-caps:
normal; font-weight: normal; letter-spacing: normal;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px;" class="">
<br style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px;" class="">
<span style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; float: none; display:
inline !important;" class="">That said, I wasn't expecting
a compile-time regression, and the codesize regression is
definitely weird. Can you get a preprocessed source file
for me to look at?</span><br style="font-family:
Helvetica; font-size: 12px; font-style: normal;
font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;"
class="">
</div>
</blockquote>
Here it is:<br class="">
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<div><br class="">
</div>
<div>It's one of source files of ClamAV, which is a part of LLVM
test-suite. Compile time on this file increased almost 3x in my
preliminary measurements (and looking at the source, function
"body" has a lot of ORs, so probably it's the culprit).</div>
</blockquote>
<br>
Yes, that's the loop with the problem.<br>
<br>
The loop has a bunch of repeated operations... and basically every
operation in the loop is an addition involving a previous operation
in the loop. Before, we would treat the rotate as an opaque
operation, which prevented the size of the expression from
exploding, but this patch allows SCEV to model a rotate expression
as "(x * pow(2, 7)) + (x / pow(2,(32-7)))", so we build complicated
SCEV expressions for every instruction in the loop. I'm seeing call
stacks with hundreds of calls to getSCEV.<br>
<br>
We aren't spending time in haveNoCommonBitsSet itself.<br>
<br>
I'm not sure what the right solution is to limit the amount of time
we spend in SCEV here. Sanjoy, any ideas?<br>
<br>
-Eli<br>
<br>
<blockquote type="cite"
cite="mid:D578A2DF-FEB7-4E43-B35B-C91DB81FFE6F@apple.com">
<div><br class="">
</div>
<div>Michael<br class="">
<blockquote type="cite" class="">
<div class=""><br style="font-family: Helvetica; font-size:
12px; font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px;" class="">
<span style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; float: none; display:
inline !important;" class="">-Eli</span><br
style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px;" class="">
<br style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px;" class="">
<span style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; float: none; display:
inline !important;" class="">On 4/20/2017 1:02 PM, Mikhail
Zolotukhin wrote:</span><br style="font-family: Helvetica;
font-size: 12px; font-style: normal; font-variant-caps:
normal; font-weight: normal; letter-spacing: normal;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px;" class="">
<blockquote type="cite" style="font-family: Helvetica;
font-size: 12px; font-style: normal; font-variant-caps:
normal; font-weight: normal; letter-spacing: normal;
orphans: auto; text-align: start; text-indent: 0px;
text-transform: none; white-space: normal; widows: auto;
word-spacing: 0px; -webkit-text-size-adjust: auto;
-webkit-text-stroke-width: 0px;" class="">Hi Eli,<br
class="">
<br class="">
It looks like this change caused a big compile time and
codesize regression on clamscan [1]. Is it expected, and
if so, are there any gains from this change that overweigh
the losses? I realize that the change itself looks right
useful, but if we get nothing from it then probably we
should find a way to mitigate negative effects first.<br
class="">
<br class="">
Thanks,<br class="">
Michael<br class="">
<br class="">
[1] <a
href="http://104.154.54.203/db_default/v4/nts/44526"
class="" moz-do-not-send="true">http://104.154.54.203/db_default/v4/nts/44526</a><br
class="">
<br class="">
<br class="">
<blockquote type="cite" class="">On Apr 19, 2017, at 1:19
PM, Eli Friedman via llvm-commits <<a
href="mailto:llvm-commits@lists.llvm.org" class=""
moz-do-not-send="true">llvm-commits@lists.llvm.org</a>>
wrote:<br class="">
<br class="">
Author: efriedma<br class="">
Date: Wed Apr 19 15:19:58 2017<br class="">
New Revision: 300746<br class="">
<br class="">
URL: <a
href="http://llvm.org/viewvc/llvm-project?rev=300746&view=rev"
class="" moz-do-not-send="true">http://llvm.org/viewvc/llvm-project?rev=300746&view=rev</a><br
class="">
Log:<br class="">
[SCEV] Make SCEV or modeling more aggressive.<br
class="">
<br class="">
Use haveNoCommonBitsSet to figure out whether an "or"
instruction<br class="">
is equivalent to addition. This handles more cases than
just<br class="">
checking for a constant on the RHS.<br class="">
<br class="">
Differential Revision: <a
href="https://reviews.llvm.org/D32239" class=""
moz-do-not-send="true">https://reviews.llvm.org/D32239</a><br
class="">
<br class="">
<br class="">
Added:<br class="">
llvm/trunk/test/Analysis/ScalarEvolution/or-as-add.ll<br
class="">
Modified:<br class="">
llvm/trunk/lib/Analysis/ScalarEvolution.cpp<br
class="">
<br class="">
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp<br
class="">
URL: <a
href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=300746&r1=300745&r2=300746&view=diff"
class="" moz-do-not-send="true">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=300746&r1=300745&r2=300746&view=diff</a><br
class="">
==============================================================================<br
class="">
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp
(original)<br class="">
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed Apr
19 15:19:58 2017<br class="">
@@ -5328,28 +5328,12 @@ const SCEV
*ScalarEvolution::createSCEV(<br class="">
break;<br class="">
<br class="">
case Instruction::Or:<br class="">
- // If the RHS of the Or is a constant, we may
have something like:<br class="">
- // X*4+1 which got turned into X*4|1. Handle
this as an Add so loop<br class="">
- // optimizations will transparently handle this
case.<br class="">
- //<br class="">
- // In order for this transformation to be safe,
the LHS must be of the<br class="">
- // form X*(2^n) and the Or constant must be less
than 2^n.<br class="">
- if (ConstantInt *CI =
dyn_cast<ConstantInt>(BO->RHS)) {<br class="">
- const SCEV *LHS = getSCEV(BO->LHS);<br
class="">
- const APInt &CIVal = CI->getValue();<br
class="">
- if (GetMinTrailingZeros(LHS) >=<br class="">
- (CIVal.getBitWidth() -
CIVal.countLeadingZeros())) {<br class="">
- // Build a plain add SCEV.<br class="">
- const SCEV *S = getAddExpr(LHS, getSCEV(CI));<br
class="">
- // If the LHS of the add was an addrec and it
has no-wrap flags,<br class="">
- // transfer the no-wrap flags, since an or
won't introduce a wrap.<br class="">
- if (const SCEVAddRecExpr *NewAR =
dyn_cast<SCEVAddRecExpr>(S)) {<br class="">
- const SCEVAddRecExpr *OldAR =
cast<SCEVAddRecExpr>(LHS);<br class="">
- const_cast<SCEVAddRecExpr
*>(NewAR)->setNoWrapFlags(<br class="">
- OldAR->getNoWrapFlags());<br
class="">
- }<br class="">
- return S;<br class="">
- }<br class="">
+ // Use ValueTracking to check whether this is
actually an add.<br class="">
+ if (haveNoCommonBitsSet(BO->LHS, BO->RHS,
getDataLayout(), &AC,<br class="">
+ nullptr, &DT)) {<br
class="">
+ // There aren't any common bits set, so the add
can't wrap.<br class="">
+ auto Flags = SCEV::NoWrapFlags(SCEV::FlagNUW |
SCEV::FlagNSW);<br class="">
+ return getAddExpr(getSCEV(BO->LHS),
getSCEV(BO->RHS), Flags);<br class="">
}<br class="">
break;<br class="">
<br class="">
<br class="">
Added:
llvm/trunk/test/Analysis/ScalarEvolution/or-as-add.ll<br
class="">
URL: <a
href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/or-as-add.ll?rev=300746&view=auto"
class="" moz-do-not-send="true">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/or-as-add.ll?rev=300746&view=auto</a><br
class="">
==============================================================================<br
class="">
---
llvm/trunk/test/Analysis/ScalarEvolution/or-as-add.ll
(added)<br class="">
+++
llvm/trunk/test/Analysis/ScalarEvolution/or-as-add.ll
Wed Apr 19 15:19:58 2017<br class="">
@@ -0,0 +1,38 @@<br class="">
+; RUN: opt < %s -analyze -scalar-evolution |
FileCheck %s<br class="">
+<br class="">
+declare void @z(i32)<br class="">
+declare void @z2(i64)<br class="">
+<br class="">
+define void @fun(i1 %bool, i32 %x) {<br class="">
+entry:<br class="">
+ br label %body<br class="">
+body:<br class="">
+ %i = phi i32 [ 0, %entry ], [ %i.next, %body ]<br
class="">
+ %bottom_zero = mul i32 %i, 2<br class="">
+ %a = or i32 %bottom_zero, 1<br class="">
+ call void @z(i32 %a)<br class="">
+ %bool_ext = zext i1 %bool to i32<br class="">
+ %b = or i32 %bool_ext, %bottom_zero<br class="">
+ call void @z(i32 %b)<br class="">
+ %shifted = lshr i32 %x, 31<br class="">
+ %c = or i32 %shifted, %bottom_zero<br class="">
+ call void @z(i32 %c)<br class="">
+ %i_ext = zext i32 %i to i64<br class="">
+ %d = or i64 %i_ext, 4294967296<br class="">
+ call void @z2(i64 %d)<br class="">
+ %i.next = add i32 %i, 1<br class="">
+ %cond = icmp eq i32 %i.next, 10<br class="">
+ br i1 %cond, label %exit, label %body<br
class="">
+exit:<br class="">
+ ret void<br class="">
+}<br class="">
+<br class="">
+; CHECK: %a = or i32 %bottom_zero, 1<br class="">
+; CHECK-NEXT: --> {1,+,2}<%body><br class="">
+; CHECK: %b = or i32 %bool_ext, %bottom_zero<br
class="">
+; CHECK-NEXT: --> {(zext i1 %bool to i32),+,2}<br
class="">
+; CHECK: %c = or i32 %shifted, %bottom_zero<br class="">
+; CHECK-NEXT: --> {(%x /u
-2147483648),+,2}<%body><br class="">
+; CHECK: %d = or i64 %i_ext, 4294967296<br class="">
+; CHECK-NEXT: -->
{4294967296,+,1}<nuw><nsw><%body><br
class="">
+<br class="">
<br class="">
<br class="">
_______________________________________________<br
class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@lists.llvm.org" class=""
moz-do-not-send="true">llvm-commits@lists.llvm.org</a><br
class="">
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="">
</blockquote>
</blockquote>
<br style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px;" class="">
<br style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px;" class="">
<span style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; float: none; display:
inline !important;" class="">--<span
class="Apple-converted-space"> </span></span><br
style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px;" class="">
<span style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; float: none; display:
inline !important;" class="">Employee of Qualcomm
Innovation Center, Inc.</span><br style="font-family:
Helvetica; font-size: 12px; font-style: normal;
font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;"
class="">
<span style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; float: none; display:
inline !important;" class="">Qualcomm Innovation Center,
Inc. is a member of Code Aurora Forum, a Linux Foundation
Collaborative Project</span></div>
</blockquote>
</div>
<br class="">
</blockquote>
<p><br>
</p>
<pre class="moz-signature" cols="72">--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project</pre>
</body>
</html>