Hi,

I believe I have a fix for all issues you reported:
- useless MOVFF x,x removed (in this particular situation -- there may be
more situations like this)
- missing BANKSEL added (incorrect removal was caused by the useless MOVFF,
because it used an operand that -- if we had a BANKSEL for it -- would have
made the missing one obsolete. For MOVFF operands, we have no BANKSEL, so
this was a bug)
- MOVF a, W; MOVWF a turned to MOVFF (this can be better, if a is not used
before/afterwards and if a is not known to be already in W; it can be worse
if a is used again (copied somewhere else) or if it's already in W)

Patch attached. If anyone wants to review it -- you are welcome. Esp. the
SPIL_LOC && IS_TEMP is something I do not really understand -- it works for
our situation, but I am not sure how correct / generally applicable that is
:-(.

I'll try to dig into this again tonight and check it in around 23:00 CEST
today.

Good night,
Raphael


2016-08-29 15:33 GMT+02:00 Kustaa Nyholm <kustaa.nyh...@planmeca.com>:

> Here is a minimal self contained test case that produces the problem:
>
>
> //------------------------------------------
> typedef struct {
>         char member;
> } test_type;
>
> extern test_type g_test1[];
> extern test_type g_test2;
>
> void foobar() {
>         g_test2.member = g_test1[0].member;
>         g_test2.member = g_test1[0].member;
> }
> //------------------------------------------
>
>
> generated code:
>
>
> //------------------------------------------
>                       01008 S_main__foobar  code
> 000000                01009 _foobar:
>                       01010 ;       .line   66; main.c      g_test2.member
> = g_test1[0].member;
> 000000 CFD9 FFE5      01011         MOVFF   FSR2L, POSTDEC1
> 000004 CFE1 FFD9      01012         MOVFF   FSR1L, FSR2L
>                       01013 ;       .line   67; main.c      }
> 000008 C??? F???      01014         MOVFF   _g_test1, _g_test1
> 00000C ????           01015         BANKSEL _g_test1
> 00000E 51??           01016         MOVF    _g_test1, W, B
> 000010 ????           01017         BANKSEL _g_test2
> 000012 6F??           01018         MOVWF   _g_test2, B
>                       01019 ;       .line   68; main.c
> 000014 C??? F???      01020         MOVFF   _g_test1, _g_test1
> 000018 51??           01021         MOVF    _g_test1, W, B
>                       01022 ; removed redundant BANKSEL
> 00001A 6F??           01023         MOVWF   _g_test2, B
> 00001C CFE4 FFD9      01024         MOVFF   PREINC1, FSR2L
> 000020 0012           01025         RETURN
> //------------------------------------------
>
>
>
> compiled with:
>
> //------------------------------------------
> /Users/nyholku/sdcc-3.6.0/bin/sdcc --no-crt --ivt-loc=0x800 -V -L
> /Users/nyholku/sdcc-3.4.0/share/sdcc/non-free/lib/pic16 -Wa,-S,0
> -Wl,-m,-s18f45k50.lkr -mpic16 -p18f45k50 --disable-warning 85 --std-sdcc99
> --obanksel=3 --use-non-free main.c
> //------------------------------------------
>
> Thinking this through while the code would work with without the BANKSEL
> optimisation,
> it would of course be preferable if the assignment would be optimised to a
> single MOVFF instruction.
> And I think (without knowing the details of code generation or peephole
> optimisation)
> that this should be easy to do because the compiler at that point knows
> both the source
> and destination absolute (even if symbolic) addresses.
>
> wbr Kusti
>
>
>
>
>
>
>
>
> This e-mail may contain confidential or privileged information. If you are
> not the intended recipient (or have received this e-mail in error) please
> notify the sender immediately and destroy this e-mail. Any unauthorized
> copying, disclosure or distribution of the material in this e-mail is
> strictly forbidden. We will not be liable for direct, indirect, special or
> consequential damages arising from alteration of the contents of this
> message by a third party or as a result of any virus being passed on or as
> of transmission of this e-mail in general.
> ------------------------------------------------------------
> ------------------
> _______________________________________________
> Sdcc-user mailing list
> Sdcc-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sdcc-user
>

Attachment: fixes.patch
Description: Binary data

------------------------------------------------------------------------------
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to