#1771 [PIC14]optimization problem?

Gál Zsolt

SDCC : pic16/pic14 3.0.1 #6287 (Mar 14 2011) (Linux)

If I see the assembly code of my test program, I realize that the most important lines are commented out and it cause malfunctions in the result. This snippet want to toggle one bit. You can find three lines which want put the result to PORTC. I have chosen this way, because I wasn't getting trouble by read-modify-write sequence. This is not working because the first line compiled wrong. If I put something between these lines, the program is working correctly. That is why I think the problem could be around the optimization.

Here is the problematic part ( I removed the less important lines ):

;; 1109 rIdx = r0x104B
MOVLW 0x00

;; 1109 rIdx = r0x104D
;;1 MOVWF r0x1005

;; 1109 rIdx = r0x104C
;;101 MOVF r0x1004,W
;;99 MOVWF r0x1006

So W got ZERO and this ZERO is moving to the PORTC not the requested result. The second and the third lines from the source code is compiled correctly and It nice to see how SDCC can optimize my code. It is great! I didn't think SDCC could make it.

I attached a very simple test file.


  • Gál Zsolt

    Gál Zsolt - 2011-03-14

    Test file for analyze the problem.

  • Raphael Neider

    Raphael Neider - 2011-03-14
    • labels: --> pic14 target
    • milestone: --> known_bugs
  • Raphael Neider

    Raphael Neider - 2011-03-14

    This is a known bug in the SDCC/pic14 code generator. It is not easy to fix but easy to circumvent:

    You can use
    sdcc -mpic14 -p16f<whatever> --no-pcode-opt <more opts> <filenames>
    to disable all of the known buggy optimizations for now. Unfortunately, these optimizations (when correct) do significantly improve code quality and (more importantly) reduce the code size ...

  • Philipp Klaus Krause

    • Category: --> PIC14

Log in to post a comment.