<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>In the scenario you gave, mul is a binary operator, 0 is not.
Calling tryReassociateBinary on the operand would be suspicious.
<br>
</p>
%1 = mul nsw i8 42, %0<br>
<br>
(I'd also not expect '42' to be a binary operator in the above.
Having i8 42 be an argument to tryReassociateBinaryOp would also
seem wrong.)<br>
<br>
<div class="moz-cite-prefix">On 03/08/2018 02:43 PM, Evgeny
Stupachenko wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAOvf_xwP0gNyimhy4kCJfFeiejtxk54QzwJWrc24Tat4tWZcKQ@mail.gmail.com">
<div dir="ltr">Well, is
<div><br>
<div>
<span
style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span>%1
= mul nsw i8 0, %0</span><br>
</div>
</div>
<div><span style="font-size:12.8px"><br>
</span></div>
<div><span style="font-size:12.8px">binary operator?</span><br>
</div>
<div>It has Zero SCEV.</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Mar 8, 2018 at 1:57 PM, Philip
Reames <span dir="ltr"><<a
href="mailto:listmail@philipreames.com" target="_blank"
moz-do-not-send="true">listmail@philipreames.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">Huh? Zero
is not a binary operator. So how'd it get here? This patch
looks wrong or at least incomplete.<span class="HOEnZb"><font
color="#888888"><br>
<br>
Philip</font></span>
<div class="HOEnZb">
<div class="h5"><br>
<br>
<br>
On 03/06/2018 06:17 PM, Evgeny Stupachenko via
llvm-commits wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: evstupac<br>
Date: Tue Mar 6 18:17:08 2018<br>
New Revision: 326861<br>
<br>
URL: <a
href="http://llvm.org/viewvc/llvm-project?rev=326861&view=rev"
rel="noreferrer" target="_blank"
moz-do-not-send="true">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=326861&view=rev</a><br>
Log:<br>
Add early exit on reassociation of 0 expression.<br>
<br>
Summary:<br>
<br>
Before the patch a try to reassociate ((v * 16) * 0) *
1 fall into infinite loop<br>
<br>
Reviewers: pankajchawla<br>
<br>
Differential Revision: <a
href="http://reviews.llvm.org/D41467"
rel="noreferrer" target="_blank"
moz-do-not-send="true">http://reviews.llvm.org/D41467</a><br>
<br>
From: Evgeny Stupachenko <<a
href="mailto:evstupac@gmail.com" target="_blank"
moz-do-not-send="true">evstupac@gmail.com</a>><br>
<<a
href="mailto:evgeny.v.stupachenko@intel.com"
target="_blank" moz-do-not-send="true">evgeny.v.stupachenko@intel.co<wbr>m</a>><br>
<br>
Added:<br>
llvm/trunk/test/Transforms/Na<wbr>ryReassociate/pr35710.ll<br>
Modified:<br>
llvm/trunk/lib/Transforms/Sca<wbr>lar/NaryReassociate.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/Scal<wbr>ar/NaryReassociate.cpp<br>
URL: <a
href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NaryReassociate.cpp?rev=326861&r1=326860&r2=326861&view=diff"
rel="noreferrer" target="_blank"
moz-do-not-send="true">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/lib/Transform<wbr>s/Scalar/NaryReassociate.cpp?<wbr>rev=326861&r1=326860&r2=<wbr>326861&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Transforms/Scal<wbr>ar/NaryReassociate.cpp
(original)<br>
+++ llvm/trunk/lib/Transforms/Scal<wbr>ar/NaryReassociate.cpp
Tue Mar 6 18:17:08 2018<br>
@@ -429,6 +429,9 @@ NaryReassociatePass::tryReasso<wbr>ciateGEPAt<br>
Instruction *NaryReassociatePass::tryReass<wbr>ociateBinaryOp(BinaryOperator
*I) {<br>
Value *LHS = I->getOperand(0), *RHS =
I->getOperand(1);<br>
+ // There is no need to reassociate 0.<br>
+ if (SE->getSCEV(I)->isZero())<br>
+ return nullptr;<br>
if (auto *NewI = tryReassociateBinaryOp(LHS, RHS,
I))<br>
return NewI;<br>
if (auto *NewI = tryReassociateBinaryOp(RHS, LHS,
I))<br>
<br>
Added: llvm/trunk/test/Transforms/Nar<wbr>yReassociate/pr35710.ll<br>
URL: <a
href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/NaryReassociate/pr35710.ll?rev=326861&view=auto"
rel="noreferrer" target="_blank"
moz-do-not-send="true">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/test/Transfor<wbr>ms/NaryReassociate/pr35710.ll?<wbr>rev=326861&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/Transforms/Nar<wbr>yReassociate/pr35710.ll
(added)<br>
+++ llvm/trunk/test/Transforms/Nar<wbr>yReassociate/pr35710.ll
Tue Mar 6 18:17:08 2018<br>
@@ -0,0 +1,19 @@<br>
+; NOTE: Assertions have been autogenerated by
utils/update_test_checks.py<br>
+; RUN: opt < %s -nary-reassociate -S | FileCheck
%s<br>
+<br>
+; The test check that compilation does not fall into
infinite loop.<br>
+<br>
+define i8 @foo(i8 %v) local_unnamed_addr #0 {<br>
+; CHECK-LABEL: @foo(<br>
+; CHECK-NEXT: region.0:<br>
+; CHECK-NEXT: [[TMP0:%.*]] = mul nsw i8 16,
[[V:%.*]]<br>
+; CHECK-NEXT: [[TMP1:%.*]] = mul nsw i8 0,
[[TMP0]]<br>
+; CHECK-NEXT: [[TMP2:%.*]] = mul nsw i8 1,
[[TMP1]]<br>
+; CHECK-NEXT: ret i8 [[TMP2]]<br>
+;<br>
+region.0:<br>
+ %0 = mul nsw i8 16, %v<br>
+ %1 = mul nsw i8 0, %0<br>
+ %2 = mul nsw i8 1, %1<br>
+ ret i8 %2<br>
+}<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org"
target="_blank" moz-do-not-send="true">llvm-commits@lists.llvm.org</a><br>
<a
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits"
rel="noreferrer" target="_blank"
moz-do-not-send="true">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote>
<br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</body>
</html>