[PATCH][AArch64] Enable sign check optimization by CSE

Jiangning Liu liujiangning1 at gmail.com
Mon Aug 11 03:05:38 PDT 2014


Hi Sergey,

Thanks for working out this new pass to solve the problem.

2014-08-11 2:25 GMT+08:00 Sergey Dmitrouk <sdmitrouk at accesssoftek.com>:

> Hi Jiangning,
>
> Please find attached patch that adds new pass.  It analyzes branches and
> adjusts comparisons and conditions to make compare instructions look the
> same, so that CSE pass could remove them.  The patch is big, but half of
> it is test file (tried to make it simpler, but it leads to generating
> different assembly) and another half is the new pass, which is hard to
> break into smaller patches.  I think it demonstrates general
> idea (comments in test has comments in C): for code like
>
>     if ((a > 5 && b == c) || (a >= 5 && b == d)) {
>
> a is compared with 5 only once with the patch.
>

I think the solution is fine with me, and statically checking 179.art and
256.bzip2, I don't see regressions any longer, although it seems there are
still some redundant compare instructions not captured by machine CSE for
256.bzip2.


> Currently only SUBS and ADDS followed by b.?? are supported.  If this
> patch is accepted, it should be possible to additionally:
>  * cover TBNZ/TBZ, which are now used for checks like (x < 0) and
>    doesn't let my patch optimize this case; does it make sense to use
>    one CMP instruction instead of TBNZ followed by CMP?
>

After Chad committed his patch r214518, more opportunities around tbnz/tbz
could be exposed, I think it might be worth a try, but I'm not sure how it
could benefit benchmarks.


>  * handle other conditional instructions (e.g. CSET).
>
> Comments are welcome, not sure I did it all correctly.  Maybe need to
> add command-line option for the pass, TODO comments, debug output,
> statistics or rewrite some parts completely.
>

For your code, it is clear and looks good to me, but it would better Tim
can have a look at it as well.

I'm running benchmarks, and will let you know if I see any abnormal
regressions.

Thanks,
-Jiangning


>
> Cheers,
> Sergey
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140811/5ec739cf/attachment.html>


More information about the llvm-commits mailing list