public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tre at gmx dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/97276] New: A whole if-block is ignored by avr-gcc 9.3.0
Date: Sat, 03 Oct 2020 00:33:30 +0000	[thread overview]
Message-ID: <bug-97276-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97276

            Bug ID: 97276
           Summary: A whole if-block is ignored by avr-gcc 9.3.0
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tre at gmx dot de
  Target Milestone: ---

Created attachment 49304
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49304&action=edit
Identical example compiled with avr-gcc 7.5.0 and avr-gcc 9.3.0

Hi,

I have a weird avr-gcc bug that costed me some months to find as I couldn't
believe it's the compiler actually. So, I use the avr-gcc 9.3.0 on Mac OS
10.15.7 to compile a little function used for PWM fading of LEDs. The function
update_pwm_timeslots()
contains an if-block (ll.119-125):

                if (last_brightness < 181 && j >= 181) 
                {
                        /* middle interrupt: top 65k */
                        slot->top = 0xfe00;
                        slot->mask = ~mask;
                        ++slot;
                }

This block seems to be completely ignored by the compilers equal or newer than
avr-gcc 8.3.0, i.e. the block doesn't appear in the assembly. Here is the list
of compilers I tested:

avr-gcc 4.9.4 (working)
avr-gcc 5.5.0 (working)
avr-gcc 6.5.0 (working)
avr-gcc 7.5.0 (working)
avr-gcc 8.4.0 (broken)
avr-gcc 9.3.0 (broken)

The diff between the assemblies (pwm.s) perfectly reveals that the if-block is
skipped by avr-gcc 9.3.0:

277c274
< mov   r15, r31
---
> mov   r9, r31
278a276,305
>         j = scalevalue(j, global_pwm.dim);
> mov   r18, r22
> ldi   r19, 0x00       ; 0
> rjmp  .+0             ; 0x1b6 <update_pwm_timeslots+0x1b6>    1b4: R_AVR_13_PCREL     .text+0x222
>         if (j == 255) break;
> cpi   r23, 0xFF       ; 255
> brne  .+0             ; 0x1ba <update_pwm_timeslots+0x1ba>    1b8: R_AVR_7_PCREL      .text+0x1bc
> rjmp  .+0             ; 0x1bc <update_pwm_timeslots+0x1bc>    1ba: R_AVR_13_PCREL     .text+0x270
>               if (last_brightness < 181 && j >= 181) 
> ldi   r30, 0xB4       ; 180
> cp    r30, r11
> brcc  .+0             ; 0x1c2 <update_pwm_timeslots+0x1c2>    1c0: R_AVR_7_PCREL      .text+0x1c4
> rjmp  .+0             ; 0x1c4 <update_pwm_timeslots+0x1c4>    1c2: R_AVR_13_PCREL     .text+0x24c
> cpi   r23, 0xB5       ; 181
> brcc  .+0             ; 0x1c8 <update_pwm_timeslots+0x1c8>    1c6: R_AVR_7_PCREL      .text+0x1ca
> rjmp  .+0             ; 0x1ca <update_pwm_timeslots+0x1ca>    1c8: R_AVR_13_PCREL     .text+0x24c
>                       slot->top = 0xfe00;
> st    X+, r8
> st    X, r9
> sbiw  r26, 0x01       ; 1
>                       slot->mask = ~mask;
> movw  r30, r24
> com   r30
> com   r31
> adiw  r26, 0x02       ; 2
> st    X+, r30
> st    X, r31
> sbiw  r26, 0x03       ; 3
>                       ++slot;
> adiw  r26, 0x04       ; 4


I attached the example with a Makefile adapted to avr-gcc 7.5.0 and avr-gcc
9.3.0 and the corresponding assembly outputs (pwm.s) and all intermediate
files. The README.txt contains the individual log outputs.

             reply	other threads:[~2020-10-03  0:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-03  0:33 tre at gmx dot de [this message]
2020-10-03  0:34 ` [Bug c/97276] " tre at gmx dot de
2023-02-23 13:31 ` [Bug target/97276] " gjl at gcc dot gnu.org
2023-02-23 13:56 ` tre at gmx dot de
2023-02-23 15:44 ` gjl at gcc dot gnu.org
2023-02-23 16:02 ` gjl at gcc dot gnu.org
2024-02-20 15:27 ` gjl at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-97276-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).