<div dir="ltr"><div>Ah - the degenerate case was based on:</div><div><a href="https://bugs.llvm.org/show_bug.cgi?id=49785#c2">https://bugs.llvm.org/show_bug.cgi?id=49785#c2</a></div><div><br></div><div>But I just reverted this locally:<br></div><div><a href="https://reviews.llvm.org/rGbb907b26e2bf2a0d5ea3fcb13ba0ccef3420a38c">https://reviews.llvm.org/rGbb907b26e2bf2a0d5ea3fcb13ba0ccef3420a38c</a></div><div><br></div><div>And neither the original C example from PR49785 nor the IR reduction are taking forever to compile for me. Something else must have changed in the past 2 weeks to mask the problem. So I'm not sure how to trigger this again.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 28, 2021 at 5:19 PM Philip Reames <<a href="mailto:listmail@philipreames.com">listmail@philipreames.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>Sanjay,</p>
<p>Neither of these seem to be the degenerate test case you saw the
compile time impact on. Could you point me to that? I'm looking
for something to run to understand the compile time opportunities
in this code.</p>
<p>Philip<br>
</p>
<div>On 4/15/21 6:48 AM, Sanjay Patel wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>I'm not understanding the question. 🤔<br>
</div>
<div><br>
</div>
<div>I suspect this doesn't answer it, but more of the trail
that led here:<br>
</div>
<div>There was a gap where isKnownNonEqual was succeeding where
simplifyICmpWithZero() did not - it was plugged with:</div>
<div><a href="https://reviews.llvm.org/rG5ae5d25e38efad1d59ed97d969a5e930b58a5e16" target="_blank">https://reviews.llvm.org/rG5ae5d25e38efad1d59ed97d969a5e930b58a5e16</a></div>
<div><br>
</div>
<div>That was exposed by this test (and that's what the unittest
in the above commit is based on):</div>
<div><a href="https://github.com/llvm/llvm-project/blob/9345f9fa5d6401bf9b98ce915bf4fbde9d183ce7/llvm/test/Analysis/ValueTracking/monotonic-phi.ll#L185" target="_blank">https://github.com/llvm/llvm-project/blob/9345f9fa5d6401bf9b98ce915bf4fbde9d183ce7/llvm/test/Analysis/ValueTracking/monotonic-phi.ll#L185</a></div>
<div><br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, Apr 14, 2021 at 6:04
PM Philip Reames <<a href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hm,
this seems interesting.<br>
<br>
I had been thinking about inverting this API by having the
shared code <br>
return the two pointers which imply equality/inequality and
having <br>
instcombine rewrite the condition. However, I couldn't find a
case <br>
where the existing logic didn't already do that inversion
through some <br>
other (more general) path. Do you happen to have an IR
fragment where <br>
we trip this example? I'd like to take a look at it with that
lens.<br>
<br>
Philip<br>
<br>
On 4/14/21 6:12 AM, Sanjay Patel via llvm-commits wrote:<br>
> Author: Sanjay Patel<br>
> Date: 2021-04-14T09:04:15-04:00<br>
> New Revision: 7ef2c68a3d24af0b0d540e748e8b564180f4e18a<br>
><br>
> URL: <a href="https://github.com/llvm/llvm-project/commit/7ef2c68a3d24af0b0d540e748e8b564180f4e18a" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/7ef2c68a3d24af0b0d540e748e8b564180f4e18a</a><br>
> DIFF: <a href="https://github.com/llvm/llvm-project/commit/7ef2c68a3d24af0b0d540e748e8b564180f4e18a.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/7ef2c68a3d24af0b0d540e748e8b564180f4e18a.diff</a><br>
><br>
> LOG: [InstSimplify] improve efficiency for detecting
non-zero value<br>
><br>
> Stepping through callstacks in the example from D99759
reveals<br>
> this potential compile-time improvement.<br>
><br>
> The savings come from avoiding ValueTracking's computing
known<br>
> bits if we have already dealt with special-case patterns.<br>
><br>
> Further improvements in this direction seem possible.<br>
><br>
> This makes a degenerate test based on PR49785 about 40x
faster<br>
> (25 sec -> 0.6 sec), but it does not address the
larger question<br>
> of how to limit computeKnownBitsFromAssume(). Ie, the
original<br>
> test there is still infinite-time for all practical
purposes.<br>
><br>
> Differential Revision: <a href="https://reviews.llvm.org/D100408" rel="noreferrer" target="_blank">https://reviews.llvm.org/D100408</a><br>
><br>
> Added:<br>
> <br>
><br>
> Modified:<br>
> llvm/lib/Analysis/InstructionSimplify.cpp<br>
><br>
> Removed:<br>
> <br>
><br>
><br>
>
################################################################################<br>
> diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp
b/llvm/lib/Analysis/InstructionSimplify.cpp<br>
> index b233a0f3eb2d..08f504a0ce37 100644<br>
> --- a/llvm/lib/Analysis/InstructionSimplify.cpp<br>
> +++ b/llvm/lib/Analysis/InstructionSimplify.cpp<br>
> @@ -3432,6 +3432,8 @@ static Value
*SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,<br>
> if (Value *V = simplifyICmpOfBools(Pred, LHS, RHS,
Q))<br>
> return V;<br>
> <br>
> + // TODO: Sink/common this with other potentially
expensive calls that use<br>
> + // ValueTracking? See comment below for
isKnownNonEqual().<br>
> if (Value *V = simplifyICmpWithZero(Pred, LHS, RHS,
Q))<br>
> return V;<br>
> <br>
> @@ -3637,7 +3639,9 @@ static Value
*SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,<br>
> }<br>
> <br>
> // icmp eq|ne X, Y -> false|true if X != Y<br>
> - if (ICmpInst::isEquality(Pred) &&<br>
> + // This is potentially expensive, and we have already
computedKnownBits for<br>
> + // compares with 0 above here, so only try this for a
non-zero compare.<br>
> + if (ICmpInst::isEquality(Pred) && !match(RHS,
m_Zero()) &&<br>
> isKnownNonEqual(LHS, RHS, Q.DL, <a href="http://Q.AC" rel="noreferrer" target="_blank">Q.AC</a>, Q.CxtI, Q.DT,
Q.IIQ.UseInstrInfo)) {<br>
> return Pred == ICmpInst::ICMP_NE ? getTrue(ITy) :
getFalse(ITy);<br>
> }<br>
><br>
><br>
> <br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote>
</div>
</blockquote>
</div>
</blockquote></div>