[llvm-dev] persuading licm to do the right thing

Preston Briggs via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 10 14:49:18 PST 2015


Hi Hal,

We compile in three stages:

   - clang -O -S -emit-llvm
   - opt -load Private.so -expandgep -O1 -dumpPrivate -S
   - privateCG

We could never get close to building an LLVM backend for our target,
so we wrote our own. Originally it worked on the LLVM IR created by
clang using -emit-llvm. More recently, I wrote a pass to expand GEPs
and we run that using opt, followed by O1, and a pass that spits out
the IR in an easy-to-parse form for consumption by our code generator.

If I have to write my own versions of value numbering and licm,
I would either put them immediate after expanding the GEPs
(so I can take advantage of al the LLVM support)
or as an early part of our code generator
(so I can understand/control what's going on).

Preston




On Thu, Dec 10, 2015 at 9:54 AM, Hal Finkel <hfinkel at anl.gov> wrote:

> ----- Original Message -----
> > From: "Preston Briggs via llvm-dev" <llvm-dev at lists.llvm.org>
> > To: "Mehdi Amini" <mehdi.amini at apple.com>
> > Cc: "llvm-dev" <llvm-dev at lists.llvm.org>
> > Sent: Wednesday, December 9, 2015 4:25:38 PM
> > Subject: Re: [llvm-dev] persuading licm to do the right thing
> >
> >
> >
> > I understand that GEPs do not access memory.
> > They do a (possibly expensive) address calculation,
> > perhaps adding a few values to a label and leaving the result in a
> > register.
> > Getting a label into a register is (to me) just like loading a 64-bit
> > integer value
> > into a register. It can happen in many places and it can cost a few
> > instructions
> > and several bytes. I'd like to see such things commoned and hoisted
> > when possible.
> >
> >
> > I agree with you that I may be fighting the spirit of the IR.
> >
> >
> > I also agree with Daniel that the classic solution is to lower and
> > re-optimize.
> > Indeed, I tried it, sort of, by rewriting GEPs into a sequence of
> > adds and multiplies,
> > with bitcasts to gets the types right. This helps in some places, but
> > the
> > re-canonicalization defeats my efforts in others places.
> >
> >
> > So now I feel like I'm going to have to write my own LICM and VN
> > passes.
> > I can do it and it won't take that long, but I had imagined that I
> > could
> > pick and choose from the tools already available to achieve the
> > desired effect.
> > Seems not, and I'm surprised.
> >
>
> At what point in the pipeline do you intend to run these tools? We do have
> some LICM, CSE, etc. capabilities late in the pipeline (at the SDAG and MI
> level), and we already so some GEP splitting in CodeGenPrep just before
> instruction selection. Once GEPs are fully decomposed during SDAG
> construction these later optimizations should do the things you describe.
> That having been said, they have known limitations in this area, but
> ideally we should all work together on improving that infrastructure.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151210/ffca53a0/attachment.html>


More information about the llvm-dev mailing list