<div dir="ltr"><div dir="ltr"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 19, 2019 at 10:36 PM Florian Klaempfl <<a href="mailto:florian@freepascal.org">florian@freepascal.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Am 19.08.2019 um 22:20 schrieb Christo Crause:<br>
> I'm interested in trying to improve the code generated for shift<br>
> operations (in particular involving a compile time constant shift) for<br>
> the AVR target.<br>
For me the idea looks good, actually, I planned once to do the same, but<br>
got stuck for time reasons with the beginnings you discovered.<br>
</blockquote><div><br></div><div>Attached a patch that optimizes SHL and SHR for constant right value for comment. Note that I haven't implemented support for SAR, ROL or ROR, these operations should fall through to the current code path. A heuristic to decide when loop unrolling is favoured is also included, taking into account -Os. Some of the details behind the optimizations are discussed here: <a href="https://github.com/ccrause/freepascal/wiki/Optimizing-code-generation-for-shift-with-compile-time-constant">https://github.com/ccrause/freepascal/wiki/Optimizing-code-generation-for-shift-with-compile-time-constant</a></div><div><br></div><div>One remaining optimization I would like to implement is to eliminate loading part of a variable to a register if it is eliminated by the shift amount. The loading of the variable and saving of the result from/to memory happens before tcgavr.a_op_const_reg_reg gets called. Is there a way to remove such a redundant load instruction from tcgavr.a_op_const_reg_reg? Or at least mark it for removal at a later stage ( peephole optimizer)?</div><div><br></div><div>I assume it would make sense to also include SAR support in this patch, since it could be generated by div?</div><div><br></div><div>best wishes,</div><div>Christo<br></div></div></div>