[llvm-commits] byval arg lowering (was: [PATCH, RFC] Fix PR13891 (AliasChain not properly maintained in ScheduleDAGInstrs::buildSchedGraph()))

Andrew Trick atrick at apple.com
Thu Sep 27 09:00:36 PDT 2012


On Sep 27, 2012, at 8:50 AM, Sergei Larin <slarin at codeaurora.org> wrote:
>  
> Akira-san,
>  
>   Those are good questions. Do you have some sort of exemplary code to illustrate it? We also had to plow through a similar issue with byval operands in Hexagon, but I have not seen any issues with tail call optimizations so far.

Roman committed r164553. I seems as simple to fix as I had hoped.
-Andy

>  
> Sergei.
>  
> ---
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
>  
> From: Akira Hatanaka [mailto:ahatanak at gmail.com] 
> Sent: Tuesday, September 25, 2012 5:11 PM
> To: Sergei Larin
> Cc: Andrew Trick; William J. Schmidt; llvm commits
> Subject: Re: [llvm-commits] byval arg lowering (was: [PATCH, RFC] Fix PR13891 (AliasChain not properly maintained in ScheduleDAGInstrs::buildSchedGraph()))
>  
> For mips, the problem was fixed by making MachinePointerInfo refer to function argument + offset, which seemed to be the simplest way. There were also a couple other alternative ways suggested by Andy (I didn't try any of them, so I don't know whether there will be any problems):
> 
> http://thread.gmane.org/gmane.comp.compilers.llvm.devel/48116/focus=48238
> 
> I have two related questions:
> 
> 1. Does function MachinePointerInfo with argument + offset work if the target does tail call optimization? It seems to me that functions with byval arguments require extra care to ensure loads/stores are serialized correctly, if you want to do tail call optimization. Function SelectionDAG::getStackArgumentTokenFactor assumes the nodes which load the incoming arguments have chain inputs which are output by the entry node. This is no longer true if you have store nodes that write to the incoming stack area.
> 
> 2. Is it not possible to preprocess functions with byval arguments at the IR level and get rid of byval arguments altogether by the time the backend sees the function? clang does some of that in CodeGen/TargetInfo.cpp. If the preprocessing is done later (but before isel/codegen), the code which is needed to handle byval args can be simplified or completely removed.
> 
> 
> On Tue, Sep 25, 2012 at 9:45 AM, Sergei Larin <slarin at codeaurora.org> wrote:
> I am late to the party :(
> 
> ...though I am glad it is clear now. I can go under anesthesia peacefully
> today :)
> 
> Sergei
> 
> ---
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by
> The Linux Foundation
> 
> 
> > -----Original Message-----
> > From: llvm-commits-bounces at cs.uiuc.edu [mailto:llvm-commits-
> > bounces at cs.uiuc.edu] On Behalf Of Andrew Trick
> > Sent: Monday, September 24, 2012 2:08 PM
> > To: William J. Schmidt
> > Cc: llvm commits
> > Subject: Re: [llvm-commits] byval arg lowering (was: [PATCH, RFC] Fix
> > PR13891 (AliasChain not properly maintained in
> > ScheduleDAGInstrs::buildSchedGraph()))
> >
> >
> > On Sep 24, 2012, at 12:00 PM, Andrew Trick <atrick at apple.com> wrote:
> >
> > >
> > > On Sep 24, 2012, at 11:47 AM, "William J. Schmidt"
> > <wschmidt at linux.vnet.ibm.com> wrote:
> > >
> > >> On Mon, 2012-09-24 at 11:04 -0700, Andrew Trick wrote:
> > >>> On Sep 21, 2012, at 1:34 PM, William J. Schmidt
> > <wschmidt at linux.vnet.ibm.com> wrote:
> > >>>
> > >>>> PR13891 identifies a test case where a load and store that
> > >>>> reference the same memory location may be improperly interchanged.
> > >>>> Investigation showed this was due to a lost aliasing dependence.
> > >>>> If the only dependence between two instructions is a may-alias via
> > >>>> the AliasChain, that dependence may be missed because the head of
> > >>>> the AliasChain is not always properly updated.  This patch fixes
> > that.
> > >>>>
> > >>>> There was one regression failure in test/CodeGen/ARM/vstlane.ll.
> > I
> > >>>> found that the code gen was identical before and after the patch,
> > >>>> modulo one change in assigned registers.  I modified the test to
> > be
> > >>>> less dogmatic about which register is assigned in this case.
> > >>>>
> > >>>> test/CodeGen/PowerPC/pr13891.ll is a new test that verifies the
> > fix.
> > >>>>
> > >>>> No additional regressions in llvm/tests or in llvm/projects/test-
> > suite.
> > >>>> Is this OK to commit?
> > >>>
> > >>>
> > >>> Hi Bill,
> > >>>
> > >>> The problem here is that the PowerPC machine code tells the
> > scheduler that the load and store are two independent objects: one
> > being an argument, and another being a local stack slot:
> > >>>
> > >>>   STH8 %X3<kill>, 162, %X1; mem:ST2[FixedStack-1]
> > >>>   %R3<def> = LHA 162, %X1; mem:LD2[%0]
> > >>>
> > >>> In general, we don't want these kind of memory references to be
> > serialized using the AliasChain.
> > >>>
> > >>> MIPS had a similar problem: http://llvm.org/pr12205
> > >>>
> > >>> I'm honestly not sure how to best handle this. My suggestion for
> > Mips was to fix byval lowering to generate a MachinePointerInfo that
> > refers to the argument value and offset of the store. That way, the
> > stack initialization will naturally alias with any loads from the byval
> > argument. That's still my best suggestion.
> > >>>
> > >>> If anyone else has ideas for the proper way to handle byval
> > lowering, please chime in!
> > >>>
> > >>> -Andy
> > >>>
> > >>
> > >> OK, thanks for the prompt reply!  We'll work on this.
> > >>
> > >> It's still not quite clear to me what the AliasChain manipulations
> > >> are doing at the moment.  Both objects end up being flagged as
> > >> MayAlias, causing them to be added to the AliasChain.  Since the
> > head
> > >> of the AliasChain isn't updated, this results in them both being
> > >> DAG'd to the compare at the end of the scheduling region, which
> > >> essentially has no effect on anything.  Perhaps this is all WAD; it
> > >> just seemed peculiar to me. ;)
> > >
> > >
> > > That's right. The head of the AliasChain is a store to an unknown
> > > location. Stores to known locations (as determined by
> > > getUnderlyingObjectForInstr) effectively have their own chain. You
> > have a load and store, both to known locations that appear to be
> > different locations at the MachineMemOperand level.
> >
> > I forgot to add... the MayAlias flag means that other unknown addresses
> > may point to this known location. It does not mean that this known
> > location may alias with other known locations. AFAIK, we have no way to
> > express that two known locations (fixed stack slot vs. argument) may
> > actually alias.
> >
> > -Andy
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120927/e5388376/attachment.html>


More information about the llvm-commits mailing list