[llvm-commits] [PATCH] Optimistically analyse phi cycles in BasicAA

Arnold Schwaighofer arnold.schwaighofer at gmail.com
Mon Dec 10 13:54:50 PST 2012


Hi Nick,

thanks for looking at this, the more eyes the better (also thanks to
Dan and Duncan!)

No, for this case it will return MayAlias because it will ask

aliasCheck(%y, %pn1)

which will in turn call (because of aliasCheck(%y, phi(%x,%y)))

aliasCheck(%y, %x) and aliasCheck(%y, %y) => alias



cat phi-speculation.ll

arget datalayout =
"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"

; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info
-disable-output 2>&1 | FileCheck %s



define i32 @test_noalias_3(i8* noalias %x, i8* noalias %y, i8* noalias
%z, i32 %count) {
entry:
  br label %while.body

while.body:
  %num = phi i32 [ %count, %entry ], [ %dec, %while.body ]
  %ptr_phi = phi i8* [ %x, %entry ], [ %z, %while.body ]
  %ptr2_phi = phi i8* [ %y, %entry ], [ %ptr_phi, %while.body ]
  %dec = add nsw i32 %num, -1
  %tobool = icmp eq i32 %dec, 0
  br i1 %tobool, label %the_exit, label %while.body

the_exit:
  ret i32 1
}

build-patched/Release+Asserts/bin/opt -basicaa --aa-eval
-print-all-alias-modref-info -disable-output < phi-speculation.ll
Function: test_noalias_3: 5 pointers, 0 call sites
  NoAlias: i8* %x, i8* %y
  NoAlias: i8* %x, i8* %z
  NoAlias: i8* %y, i8* %z
  MayAlias: i8* %ptr_phi, i8* %x
  NoAlias: i8* %ptr_phi, i8* %y
  MayAlias: i8* %ptr_phi, i8* %z
  MayAlias: i8* %ptr2_phi, i8* %x
  MayAlias: i8* %ptr2_phi, i8* %y
  MayAlias: i8* %ptr2_phi, i8* %z
  MayAlias: i8* %ptr2_phi, i8* %ptr_phi
===== Alias Analysis Evaluator Report =====
  10 Total Alias Queries Performed
  4 no alias responses (40.0%)
  6 may alias responses (60.0%)
  0 partial alias responses (0.0%)
  0 must alias responses (0.0%)
  Alias Analysis Evaluator Pointer Alias Summary: 40%/60%/0%/0%
  Alias Analysis Mod/Ref Evaluator Summary: no mod/ref!

On Mon, Dec 10, 2012 at 3:07 PM, Nick Lewycky <nlewycky at google.com> wrote:
> On 8 December 2012 10:12, Hal Finkel <hfinkel at anl.gov> wrote:
>>
>> Nick,
>>
>> You had okayed the previous version of this. Would you like to look at
>> this one as well?
>
>
> Thanks for the ping!
>
> I took a look, and I must be missing something. Won't this miscompile:
>
> bb2:
>   %pn1 = phi i8* [ %x, %bb1 ], [ %y, %bb2 ]
>   %pn2 = phi i8* [ %z, %bb1 ], [ %pn1, %bb2 ]
>
> when %x, %y and %z are all NoAlias? It will speculate that %pn1 and %pn2
> don't alias and the proceed to confirm that just because it speculated it.
>
> Nick
>
>>
>>  -Hal
>>
>> ----- Original Message -----
>> > From: "Dan Gohman" <dan433584 at gmail.com>
>> > To: "Hal Finkel" <hfinkel at anl.gov>
>> > Cc: "Arnold Schwaighofer" <arnold.schwaighofer at gmail.com>, "Commit
>> > Messages and Patches for LLVM"
>> > <llvm-commits at cs.uiuc.edu>
>> > Sent: Thursday, December 6, 2012 4:32:32 PM
>> > Subject: Re: [llvm-commits] [PATCH] Optimistically analyse phi cycles in
>> > BasicAA
>> >
>> > The basic idea sounds fine.
>> >
>> > Dan
>> >
>> > On Thu, Dec 6, 2012 at 9:31 AM, Hal Finkel <hfinkel at anl.gov> wrote:
>> > > Dan,
>> > >
>> > > Do you have an opinion on this?
>> > >
>> > > Thanks again,
>> > > Hal
>> > >
>> > > ----- Original Message -----
>> > >> From: "Arnold Schwaighofer" <arnold.schwaighofer at gmail.com>
>> > >> Cc: "Commit Messages and Patches for LLVM"
>> > >> <llvm-commits at cs.uiuc.edu>
>> > >> Sent: Wednesday, November 21, 2012 9:24:13 AM
>> > >> Subject: Re: [llvm-commits] [PATCH] Optimistically analyse phi
>> > >> cycles in      BasicAA
>> > >>
>> > >> Also send to list ...
>> > >>
>> > >> On Wed, Nov 21, 2012 at 3:37 AM, Duncan Sands <baldrick at free.fr>
>> > >> wrote:
>> > >> >
>> > >> > what happens if the recursion bails out due to hitting a
>> > >> > recursion
>> > >> > limit?
>> > >> > Will the conservatively correct MayAlias be returned in that
>> > >> > case?
>> > >>
>> > >> Yes, because when we hit the limit in the recursion we return
>> > >> MayAlias
>> > >> from this recursion. This result will be merged with the phi's
>> > >> alias
>> > >> result, setting the phi to MayAlias.
>> > >>
>> > >>       AliasResult Alias = NoAlias;
>> > >>       AliasResult OrigAliasResult = AliasCache[Locs]; // Is
>> > >>       MayAlias
>> > >> if we have never seen this node.
>> > >>       AliasCache[Locs] = NoAlias;
>> > >>
>> > >>       for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e;
>> > >>       ++i) {
>> > >>         AliasResult ThisAlias =
>> > >>                      [1]
>> > >>           aliasCheck(PN->getIncomingValue(i), PNSize, PNTBAAInfo,
>> > >>
>> > >> PN2->getIncomingValueForBlock(PN->getIncomingBlock(i)),
>> > >>                      V2Size, V2TBAAInfo);
>> > >>         Alias = MergeAliasResults(ThisAlias, Alias);
>> > >>         if (Alias == MayAlias)
>> > >>           break;
>> > >>       }
>> > >>
>> > >>       // Reset if speculation failed.
>> > >>       if (Alias != NoAlias)
>> > >>         AliasCache[Locs] = OrigAliasResult;
>> > >>
>> > >> We either process all nodes in the phis' input graph and
>> > >> eventually
>> > >> see a MayAlias result or we give up early and return MayAlias
>> > >> through
>> > >> the recursion.
>> > >> The interesting case when we handle two phi nodes. We assume the
>> > >> phis
>> > >> to be NoAlias and they are not. Let say we process all inputs
>> > >> recursively then we eventually will see an input that is MayAlias,
>> > >> this will be propagate up to the call aliasCheck [1] above,
>> > >> resulting
>> > >> in the phi to be set to MayAlias.
>> > >> In the case were we hit the recursion limit this again will happen
>> > >> in
>> > >> the call to aliasCheck [1] which then returns MayAlias and again
>> > >> the
>> > >> phis' result will be reset to MayAlias.
>> > >> _______________________________________________
>> > >> llvm-commits mailing list
>> > >> llvm-commits at cs.uiuc.edu
>> > >> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>> > >>
>> > >
>> > > --
>> > > Hal Finkel
>> > > Postdoctoral Appointee
>> > > Leadership Computing Facility
>> > > Argonne National Laboratory
>> >
>>
>> --
>> Hal Finkel
>> Postdoctoral Appointee
>> Leadership Computing Facility
>> Argonne National Laboratory
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>



More information about the llvm-commits mailing list