<div dir="ltr">Thanks very much Hal.<div><br></div><div>Cheers,</div><div>Lang.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 9, 2014 at 1:00 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">----- Original Message -----<br>
> From: "Hal Finkel" <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>><br>
> To: "James Molloy" <<a href="mailto:james@jamesmolloy.co.uk">james@jamesmolloy.co.uk</a>><br>
> Cc: "Commit Messages and Patches for LLVM" <<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a>>, "Nicholas White" <<a href="mailto:n.j.white@gmail.com">n.j.white@gmail.com</a>><br>
</span><span class="">> Sent: Thursday, October 9, 2014 2:55:16 PM<br>
> Subject: Re: [llvm] r219135 - [BasicAA] Revert "Revert r218714 - Make better  use of zext and sign information."<br>
><br>
> ----- Original Message -----<br>
> > From: "James Molloy" <<a href="mailto:james@jamesmolloy.co.uk">james@jamesmolloy.co.uk</a>><br>
> > To: "Hal Finkel" <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>><br>
> > Cc: "Lang Hames" <<a href="mailto:lhames@gmail.com">lhames@gmail.com</a>>, "Commit Messages and Patches<br>
> > for LLVM" <<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a>>, "Nicholas<br>
> > White" <<a href="mailto:n.j.white@gmail.com">n.j.white@gmail.com</a>><br>
> > Sent: Thursday, October 9, 2014 2:52:08 PM<br>
> > Subject: Re: [llvm] r219135 - [BasicAA] Revert "Revert r218714 -<br>
> > Make better use of zext and sign information."<br>
> ><br>
> ><br>
> > Hi,<br>
> ><br>
> ><br>
> > I've just narrowed down a build failure on povray in SPEC2k6 to<br>
> > this<br>
> > too.<br>
> ><br>
> ><br>
> > Could you please revert?<br>
><br>
> Yes, will do now.<br>
<br>
</span>r219432.<br>
<span class="HOEnZb"><font color="#888888"><br>
 -Hal<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
>  -Hal<br>
><br>
> >I can try and get you a testcase in the<br>
> > morning (SPEC2k6 testcases need to be anonymised which takes time<br>
> > :(<br>
> > )<br>
> ><br>
> ><br>
> > Cheers,<br>
> ><br>
> ><br>
> > James<br>
> ><br>
> ><br>
> > On 9 October 2014 19:45, Hal Finkel < <a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a> > wrote:<br>
> ><br>
> ><br>
> > ----- Original Message -----<br>
> > > From: "Lang Hames" < <a href="mailto:lhames@gmail.com">lhames@gmail.com</a> ><br>
> > > To: "Hal Finkel" < <a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a> ><br>
> > > Cc: "Commit Messages and Patches for LLVM" <<br>
> > > <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a> >, "Nicholas White" <<br>
> > > <a href="mailto:n.j.white@gmail.com">n.j.white@gmail.com</a><br>
> > > ><br>
> > > Sent: Thursday, October 9, 2014 1:34:19 PM<br>
> > > Subject: Re: [llvm] r219135 - [BasicAA] Revert "Revert r218714 -<br>
> > > Make better use of zext and sign information."<br>
> > ><br>
> > ><br>
> > > Hi Hal, Nick,<br>
> > ><br>
> > ><br>
> > > It looks like this broke SPEC2k6/464.h264ref on x86-64 (and<br>
> > > possibly<br>
> > > ARM as well - I'm still investigating there). Do you guys have<br>
> > > access to SPEC2k6? Have you seen any failures locally?<br>
> ><br>
> > I do, but I don't have it running nightly (likely should). Feel<br>
> > free<br>
> > to revert while we figure it out.<br>
> ><br>
> > Thanks again,<br>
> > Hal<br>
> ><br>
> ><br>
> ><br>
> > ><br>
> > ><br>
> > > Cheers,<br>
> > > Lang.<br>
> > ><br>
> > ><br>
> > ><br>
> > ><br>
> > > On Mon, Oct 6, 2014 at 11:38 AM, Hal Finkel < <a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a> ><br>
> > > wrote:<br>
> > ><br>
> > ><br>
> > > Author: hfinkel<br>
> > > Date: Mon Oct 6 13:37:59 2014<br>
> > > New Revision: 219135<br>
> > ><br>
> > > URL: <a href="http://llvm.org/viewvc/llvm-project?rev=219135&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=219135&view=rev</a><br>
> > > Log:<br>
> > > [BasicAA] Revert "Revert r218714 - Make better use of zext and<br>
> > > sign<br>
> > > information."<br>
> > ><br>
> > > This reverts r218944, which reverted r218714, plus a bug fix.<br>
> > ><br>
> > > Description of the bug in r218714 (by Nick)<br>
> > ><br>
> > > The original patch forgot to check if the Scale in<br>
> > > VariableGEPIndex<br>
> > > flipped the<br>
> > > sign of the variable. The BasicAA pass iterates over the<br>
> > > instructions<br>
> > > in the<br>
> > > order they appear in the function, and so<br>
> > > BasicAliasAnalysis::aliasGEP is<br>
> > > called with the variable it first comes across as parameter GEP1.<br>
> > > Adding a<br>
> > > %reorder label puts the definition of %a after %b so aliasGEP is<br>
> > > called with %b<br>
> > > as the first parameter and %a as the second. aliasGEP later<br>
> > > calculates that %a<br>
> > > == %b + 1 - %idxprom where %idxprom >= 0 (if %a was passed as the<br>
> > > first<br>
> > > parameter it would calculate %b == %a - 1 + %idxprom where<br>
> > > %idxprom<br>
> > > >= 0) -<br>
> > > ignoring that %idxprom is scaled by -1 here lead the patch to<br>
> > > incorrectly<br>
> > > conclude that %a > %b.<br>
> > ><br>
> > > Revised patch by Nick White, thanks! Thanks to Lang to isolating<br>
> > > the<br>
> > > bug.<br>
> > > Slightly modified by me to add an early exit from the loop and<br>
> > > avoid<br>
> > > unnecessary, but expensive, function calls.<br>
> > ><br>
> > > Original commit message:<br>
> > ><br>
> > > Two related things:<br>
> > ><br>
> > > 1. Fixes a bug when calculating the offset in<br>
> > > GetLinearExpression.<br>
> > > The code<br>
> > > previously used zext to extend the offset, so negative offsets<br>
> > > were<br>
> > > converted<br>
> > > to large positive ones.<br>
> > ><br>
> > > 2. Enhance aliasGEP to deduce that, if the difference between two<br>
> > > GEP<br>
> > > allocations is positive and all the variables that govern the<br>
> > > offset<br>
> > > are also<br>
> > > positive (i.e. the offset is strictly after the higher base<br>
> > > pointer),<br>
> > > then<br>
> > > locations that fit in the gap between the two base pointers are<br>
> > > NoAlias.<br>
> > ><br>
> > > Patch by Nick White!<br>
> > ><br>
> > > Added:<br>
> > > llvm/trunk/test/Analysis/BasicAA/zext.ll<br>
> > > Modified:<br>
> > > llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp<br>
> > > llvm/trunk/test/Analysis/BasicAA/phi-aa.ll<br>
> > ><br>
> > > Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp<br>
> > > URL:<br>
> > > <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=219135&r1=219134&r2=219135&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=219135&r1=219134&r2=219135&view=diff</a><br>
> > > ==============================================================================<br>
> > > --- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original)<br>
> > > +++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Mon Oct 6<br>
> > > 13:37:59<br>
> > > 2014<br>
> > > @@ -254,7 +254,10 @@ static Value *GetLinearExpression(Value<br>
> > > Value *Result = GetLinearExpression(CastOp, Scale, Offset,<br>
> > > Extension,<br>
> > > DL, Depth+1, AT, DT);<br>
> > > Scale = Scale.zext(OldWidth);<br>
> > > - Offset = Offset.zext(OldWidth);<br>
> > > +<br>
> > > + // We have to sign-extend even if Extension == EK_ZeroExt as we<br>
> > > can't<br>
> > > + // decompose a sign extension (i.e. zext(x - 1) != zext(x) -<br>
> > > zext(-1)).<br>
> > > + Offset = Offset.sext(OldWidth);<br>
> > ><br>
> > > return Result;<br>
> > > }<br>
> > > @@ -1055,8 +1058,38 @@ BasicAliasAnalysis::aliasGEP(const GEPOp<br>
> > > // Grab the least significant bit set in any of the scales.<br>
> > > if (!GEP1VariableIndices.empty()) {<br>
> > > uint64_t Modulo = 0;<br>
> > > - for (unsigned i = 0, e = GEP1VariableIndices.size(); i != e;<br>
> > > ++i)<br>
> > > + bool AllPositive = true;<br>
> > > + for (unsigned i = 0, e = GEP1VariableIndices.size();<br>
> > > + i != e && AllPositive; ++i) {<br>
> > > + const Value *V = GEP1VariableIndices[i].V;<br>
> > > Modulo |= (uint64_t)GEP1VariableIndices[i].Scale;<br>
> > > +<br>
> > > + bool SignKnownZero, SignKnownOne;<br>
> > > + ComputeSignBit(<br>
> > > + const_cast<Value *>(V),<br>
> > > + SignKnownZero, SignKnownOne,<br>
> > > + DL, 0, AT, nullptr, DT);<br>
> > > +<br>
> > > + // Zero-extension widens the variable, and so forces the sign<br>
> > > + // bit to zero.<br>
> > > + bool IsZExt = GEP1VariableIndices[i].Extension == EK_ZeroExt;<br>
> > > + SignKnownZero |= IsZExt;<br>
> > > + SignKnownOne &= !IsZExt;<br>
> > > +<br>
> > > + // If the variable begins with a zero then we know it's<br>
> > > + // positive, regardless of whether the value is signed or<br>
> > > + // unsigned.<br>
> > > + int64_t Scale = GEP1VariableIndices[i].Scale;<br>
> > > + AllPositive &=<br>
> > > + (SignKnownZero && Scale >= 0) ||<br>
> > > + (SignKnownOne && Scale < 0);<br>
> > > +<br>
> > > + // If the Value is currently positive but could change in a<br>
> > > cycle,<br>
> > > + // then we can't guarantee it'll always br positive.<br>
> > > + if (AllPositive && !isValueEqualInPotentialCycles(V, V))<br>
> > > + AllPositive = false;<br>
> > > + }<br>
> > > +<br>
> > > Modulo = Modulo ^ (Modulo & (Modulo - 1));<br>
> > ><br>
> > > // We can compute the difference between the two addresses<br>
> > > @@ -1066,6 +1099,12 @@ BasicAliasAnalysis::aliasGEP(const GEPOp<br>
> > > if (V1Size != UnknownSize && V2Size != UnknownSize &&<br>
> > > ModOffset >= V2Size && V1Size <= Modulo - ModOffset)<br>
> > > return NoAlias;<br>
> > > +<br>
> > > + // If we know all the variables are positive, then GEP1 >=<br>
> > > GEP1BasePtr.<br>
> > > + // If GEP1BasePtr > V2 (GEP1BaseOffset > 0) then we know the<br>
> > > pointers<br>
> > > + // don't alias if V2Size can fit in the gap between V2 and<br>
> > > GEP1BasePtr.<br>
> > > + if (AllPositive && GEP1BaseOffset > 0 && V2Size <= (uint64_t)<br>
> > > GEP1BaseOffset)<br>
> > > + return NoAlias;<br>
> > > }<br>
> > ><br>
> > > // Statically, we can see that the base objects are the same, but<br>
> > > the<br>
> > ><br>
> > > Modified: llvm/trunk/test/Analysis/BasicAA/phi-aa.ll<br>
> > > URL:<br>
> > > <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BasicAA/phi-aa.ll?rev=219135&r1=219134&r2=219135&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BasicAA/phi-aa.ll?rev=219135&r1=219134&r2=219135&view=diff</a><br>
> > > ==============================================================================<br>
> > > --- llvm/trunk/test/Analysis/BasicAA/phi-aa.ll (original)<br>
> > > +++ llvm/trunk/test/Analysis/BasicAA/phi-aa.ll Mon Oct 6 13:37:59<br>
> > > 2014<br>
> > > @@ -39,6 +39,7 @@ return:<br>
> > ><br>
> > > ; CHECK-LABEL: pr18068<br>
> > > ; CHECK: MayAlias: i32* %0, i32* %arrayidx5<br>
> > > +; CHECK: NoAlias: i32* %arrayidx13, i32* %arrayidx5<br>
> > ><br>
> > > define i32 @pr18068(i32* %jj7, i32* %j) {<br>
> > > entry:<br>
> > ><br>
> > > Added: llvm/trunk/test/Analysis/BasicAA/zext.ll<br>
> > > URL:<br>
> > > <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BasicAA/zext.ll?rev=219135&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BasicAA/zext.ll?rev=219135&view=auto</a><br>
> > > ==============================================================================<br>
> > > --- llvm/trunk/test/Analysis/BasicAA/zext.ll (added)<br>
> > > +++ llvm/trunk/test/Analysis/BasicAA/zext.ll Mon Oct 6 13:37:59<br>
> > > 2014<br>
> > > @@ -0,0 +1,87 @@<br>
> > > +; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info<br>
> > > -disable-output 2>&1 | FileCheck %s<br>
> > > +target datalayout =<br>
> > > "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"<br>
> > > +target triple = "x86_64-unknown-linux-gnu"<br>
> > > +<br>
> > > +; CHECK-LABEL: test_with_zext<br>
> > > +; CHECK: NoAlias: i8* %a, i8* %b<br>
> > > +<br>
> > > +define void @test_with_zext() {<br>
> > > + %1 = tail call i8* @malloc(i64 120)<br>
> > > + %a = getelementptr inbounds i8* %1, i64 8<br>
> > > + %2 = getelementptr inbounds i8* %1, i64 16<br>
> > > + %3 = zext i32 3 to i64<br>
> > > + %b = getelementptr inbounds i8* %2, i64 %3<br>
> > > + ret void<br>
> > > +}<br>
> > > +<br>
> > > +; CHECK-LABEL: test_with_lshr<br>
> > > +; CHECK: NoAlias: i8* %a, i8* %b<br>
> > > +<br>
> > > +define void @test_with_lshr(i64 %i) {<br>
> > > + %1 = tail call i8* @malloc(i64 120)<br>
> > > + %a = getelementptr inbounds i8* %1, i64 8<br>
> > > + %2 = getelementptr inbounds i8* %1, i64 16<br>
> > > + %3 = lshr i64 %i, 2<br>
> > > + %b = getelementptr inbounds i8* %2, i64 %3<br>
> > > + ret void<br>
> > > +}<br>
> > > +<br>
> > > +; CHECK-LABEL: test_with_a_loop<br>
> > > +; CHECK: NoAlias: i8* %a, i8* %b<br>
> > > +<br>
> > > +define void @test_with_a_loop() {<br>
> > > + %1 = tail call i8* @malloc(i64 120)<br>
> > > + %a = getelementptr inbounds i8* %1, i64 8<br>
> > > + %2 = getelementptr inbounds i8* %1, i64 16<br>
> > > + br label %for.loop<br>
> > > +<br>
> > > +for.loop:<br>
> > > + %i = phi i32 [ 0, %0 ], [ %i.next, %for.loop ]<br>
> > > + %3 = zext i32 %i to i64<br>
> > > + %b = getelementptr inbounds i8* %2, i64 %3<br>
> > > + %i.next = add nuw nsw i32 %i, 1<br>
> > > + %4 = icmp eq i32 %i.next, 10<br>
> > > + br i1 %4, label %for.loop.exit, label %for.loop<br>
> > > +<br>
> > > +for.loop.exit:<br>
> > > + ret void<br>
> > > +}<br>
> > > +<br>
> > > +; CHECK-LABEL: test_sign_extension<br>
> > > +; CHECK: PartialAlias: i64* %b.i64, i8* %a<br>
> > > +<br>
> > > +define void @test_sign_extension(i32 %p) {<br>
> > > + %1 = tail call i8* @malloc(i64 120)<br>
> > > + %p.64 = zext i32 %p to i64<br>
> > > + %a = getelementptr inbounds i8* %1, i64 %p.64<br>
> > > + %p.minus1 = add i32 %p, -1<br>
> > > + %p.minus1.64 = zext i32 %p.minus1 to i64<br>
> > > + %b.i8 = getelementptr inbounds i8* %1, i64 %p.minus1.64<br>
> > > + %b.i64 = bitcast i8* %b.i8 to i64*<br>
> > > + ret void<br>
> > > +}<br>
> > > +<br>
> > > +; CHECK-LABEL: test_fe_tools<br>
> > > +; CHECK: PartialAlias: i32* %a, i32* %b<br>
> > > +<br>
> > > +define void @test_fe_tools([8 x i32]* %values) {<br>
> > > + br label %reorder<br>
> > > +<br>
> > > +for.loop:<br>
> > > + %i = phi i32 [ 0, %reorder ], [ %i.next, %for.loop ]<br>
> > > + %idxprom = zext i32 %i to i64<br>
> > > + %b = getelementptr inbounds [8 x i32]* %values, i64 0, i64<br>
> > > %idxprom<br>
> > > + %i.next = add nuw nsw i32 %i, 1<br>
> > > + %1 = icmp eq i32 %i.next, 10<br>
> > > + br i1 %1, label %for.loop.exit, label %for.loop<br>
> > > +<br>
> > > +reorder:<br>
> > > + %a = getelementptr inbounds [8 x i32]* %values, i64 0, i64 1<br>
> > > + br label %for.loop<br>
> > > +<br>
> > > +for.loop.exit:<br>
> > > + ret void<br>
> > > +}<br>
> > > +<br>
> > > +; Function Attrs: nounwind<br>
> > > +declare noalias i8* @malloc(i64)<br>
> > ><br>
> > ><br>
> > > _______________________________________________<br>
> > > llvm-commits mailing list<br>
> > > <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> > > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
> > ><br>
> > ><br>
> ><br>
> > --<br>
> > Hal Finkel<br>
> > Assistant Computational Scientist<br>
> > Leadership Computing Facility<br>
> > Argonne National Laboratory<br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > llvm-commits mailing list<br>
> > <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
> ><br>
> ><br>
><br>
> --<br>
> Hal Finkel<br>
> Assistant Computational Scientist<br>
> Leadership Computing Facility<br>
> Argonne National Laboratory<br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
<br>
--<br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
</div></div></blockquote></div><br></div>