public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/97276] New: A whole if-block is ignored by avr-gcc 9.3.0
@ 2020-10-03  0:33 tre at gmx dot de
  2020-10-03  0:34 ` [Bug c/97276] " tre at gmx dot de
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: tre at gmx dot de @ 2020-10-03  0:33 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/97276] A whole if-block is ignored by avr-gcc 9.3.0
  2020-10-03  0:33 [Bug c/97276] New: A whole if-block is ignored by avr-gcc 9.3.0 tre at gmx dot de
@ 2020-10-03  0:34 ` tre at gmx dot de
  2023-02-23 13:31 ` [Bug target/97276] " gjl at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: tre at gmx dot de @ 2020-10-03  0:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from David Weese <tre at gmx dot de> ---
The README.txt also contains the steps to reproduce the pwm.s assemblies.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/97276] A whole if-block is ignored by avr-gcc 9.3.0
  2020-10-03  0:33 [Bug c/97276] New: A whole if-block is ignored by avr-gcc 9.3.0 tre at gmx dot de
  2020-10-03  0:34 ` [Bug c/97276] " tre at gmx dot de
@ 2023-02-23 13:31 ` gjl at gcc dot gnu.org
  2023-02-23 13:56 ` tre at gmx dot de
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: gjl at gcc dot gnu.org @ 2023-02-23 13:31 UTC (permalink / raw)
  To: gcc-bugs

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

Georg-Johann Lay <gjl at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|atxmega32a4                 |avr

--- Comment #2 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
Can you provide the pre-compiled source pwm.i?  Just add -save-temps to the
compile options.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/97276] A whole if-block is ignored by avr-gcc 9.3.0
  2020-10-03  0:33 [Bug c/97276] New: A whole if-block is ignored by avr-gcc 9.3.0 tre at gmx dot de
  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
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: tre at gmx dot de @ 2023-02-23 13:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from David Weese <tre at gmx dot de> ---
Have you seen the attachment? It's all in there.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/97276] A whole if-block is ignored by avr-gcc 9.3.0
  2020-10-03  0:33 [Bug c/97276] New: A whole if-block is ignored by avr-gcc 9.3.0 tre at gmx dot de
                   ` (2 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: gjl at gcc dot gnu.org @ 2023-02-23 15:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
Created attachment 54518
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54518&action=edit
pwn-i.c pre-compiled test case

Ok, I found it and attached a cleaned-up version.

IIUC correctly, the relevant options you are using to compile are: -O1
-mmcu=atxmega32a4 -g -ggdb -std=gnu99

With these options (and with -fverbose-asm to easier navigate in asm) I could
not reproduce the problem with avr-gcc v8.5.  The respective part of .s reads
(I dropped -g for legibility, but with -g it's same):

 ;  pwm-i.c:287:         if (last_brightness < 181 && j >= 181)
        ldi r30,lo8(-76)         ; ,     ;  320 [c=4 l=1]  movqi_insn/1
        cp r30,r11               ; , last_brightness     ;  193 [c=4 l=1] 
cmpqi3/1
        brsh .+2         ;       ;  194 [c=16 l=2]  branch
        rjmp .L16        ; 
 ;  pwm-i.c:287:         if (last_brightness < 181 && j >= 181)
        cpi r22,lo8(-75)         ;  iftmp.3_5,   ;  196 [c=4 l=1]  cmpqi3/2
        brsh .+2         ;       ;  197 [c=16 l=2]  branch
        rjmp .L16        ; 
 ;  pwm-i.c:289:             slot->top = 0xfe00;
        st X+,r8         ;  tmp226       ;  200 [c=4 l=3]  *movhi/3
        st X,r9  ;  tmp226
        sbiw r26,1
 ;  pwm-i.c:290:             slot->mask = ~mask;
        movw r30,r24     ;  tmp200, mask         ;  321 [c=4 l=1]  *movhi/0
        com r30  ;  tmp200       ;  201 [c=8 l=2]  one_cmplhi2
        com r31  ;  tmp200
 ;  pwm-i.c:290:             slot->mask = ~mask;
        adiw r26,2       ;  slot_172->mask       ;  202 [c=4 l=4]  *movhi/3
        st X+,r30        ;  tmp200
        st X,r31         ;  tmp200
        sbiw r26,2+1     ;  slot_172->mask
 ;  pwm-i.c:291:             ++slot;
        adiw r26,4       ;  slot,        ;  203 [c=4 l=1]  addhi3_clobber/0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/97276] A whole if-block is ignored by avr-gcc 9.3.0
  2020-10-03  0:33 [Bug c/97276] New: A whole if-block is ignored by avr-gcc 9.3.0 tre at gmx dot de
                   ` (3 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: gjl at gcc dot gnu.org @ 2023-02-23 16:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
... also tried v9.2 via

https://godbolt.org/z/9r3vMj1e3

and just like with v8.5, the respective block is around asm line 350.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/97276] A whole if-block is ignored by avr-gcc 9.3.0
  2020-10-03  0:33 [Bug c/97276] New: A whole if-block is ignored by avr-gcc 9.3.0 tre at gmx dot de
                   ` (4 preceding siblings ...)
  2023-02-23 16:02 ` gjl at gcc dot gnu.org
@ 2024-02-20 15:27 ` gjl at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: gjl at gcc dot gnu.org @ 2024-02-20 15:27 UTC (permalink / raw)
  To: gcc-bugs

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

Georg-Johann Lay <gjl at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-02-20
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-20 15:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-03  0:33 [Bug c/97276] New: A whole if-block is ignored by avr-gcc 9.3.0 tre at gmx dot de
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

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).