[llvm-dev] Question about canonicalizing cmp+select

Sanjay Patel via llvm-dev llvm-dev at lists.llvm.org
Tue Jul 3 11:22:21 PDT 2018


Do you run DAGCombiner? And are you overriding
TLI.convertSelectOfConstantsToMath(VT) for your target?

For the stated example (true val and false val constants in the select
differ by 1), that should already be converted.


On Tue, Jul 3, 2018 at 12:13 PM, Roman Lebedev <lebedev.ri at gmail.com> wrote:

> On Tue, Jul 3, 2018 at 9:06 PM, Yuan Lin via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
> > Hi, Sanjay/all,
> >
> >   I noticed in rL331486 that some compare-select optimizations are
> disabled
> > in favor of providing canonicalized cmp+select to the backend.
> >
> >   I am currently working on a private backend target, and the target has
> a
> > small code size limit.  With this change, some of the apps went over the
> > codesize limit.  As an example,
> >
> > C code:
> >   b = (a > -1) ? 4 : 5;
> >
> > ll code:
> > Before rL331486:
> >   %0 = lshr i16 %a.0.a.0., 15
> >   %1 = or i16 %0, 4
> >
> > After rL331486:
> >   %cmp = icmp sgt i16 %a.0.a.0., -1
> >   %cond = select i1 %cmp, i16 4, i16 5
> >
> >   With the various encoding restrictions of my particular target, the
> > cmp/select generated slightly larger code size.  However, because the
> apps
> > were very close to the code size limit, this slight change pushed them
> over
> > the limit.
> >
> >   If I still prefer to have this optimization performed, then is my best
> > strategy moving forward to implement this optimization as a peephole opt
> in
> > my backend?
> I personally think it should probably be a DAGCombine transform,
> driven by a Target Transform Info hook (e.g. like hasAndNot()).
>
> > Thanks,
> > --Yuan
> Roman.
>
> > _______________________________________________
> > LLVM Developers mailing list
> > llvm-dev at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180703/91644269/attachment.html>


More information about the llvm-dev mailing list