public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/41894]  New: wrong code with -fno-split-wide-types
@ 2009-10-31 21:44 frank at mynety dot net
  2009-10-31 23:02 ` [Bug target/41894] " hutchinsonandy at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: frank at mynety dot net @ 2009-10-31 21:44 UTC (permalink / raw)
  To: gcc-bugs

Commandline:
avr-gcc -S -mmcu=atmega128 -Os 
-fno-inline-small-functions -fno-split-wide-types bug.c

Sourcecode:

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;

typedef union
{
  struct {
    uint8_t sekunden;
    uint8_t minuten;
  } x;
  uint16_t sekmin;
} zeit_t;


void testmich2 (zeit_t tmp) {
  // just something that cannot be optimized out
  asm volatile("nop");
}

void testmich (zeit_t zeit) {

  zeit_t tmp;

  tmp.x = zeit.x;

  do {
    testmich2(tmp);

    if (tmp.x.sekunden)
      tmp.x.sekunden--;
    else {
      tmp.x.sekunden = 59;
      tmp.x.minuten--;
    }
  } while (tmp.x.sekunden || tmp.x.minuten);
}

int main (void) {
  zeit_t zeit;

  zeit.x.minuten = 1;
  zeit.x.sekunden = 2;

  testmich(zeit);

  return 0;
}


The statements

if (tmp.x.sekunden)
      tmp.x.sekunden--;

translate to:

        mov r18,r28
        subi r18,lo8(-(-1))
        movw r28,r18

which is wrong; r19 (used by movw) has a not defined value.


-- 
           Summary: wrong code with -fno-split-wide-types
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: frank at mynety dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41894


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

* [Bug target/41894] wrong code with -fno-split-wide-types
  2009-10-31 21:44 [Bug c/41894] New: wrong code with -fno-split-wide-types frank at mynety dot net
@ 2009-10-31 23:02 ` hutchinsonandy at gcc dot gnu dot org
  2009-10-31 23:10 ` j at uriah dot heep dot sax dot de
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hutchinsonandy at gcc dot gnu dot org @ 2009-10-31 23:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from hutchinsonandy at gcc dot gnu dot org  2009-10-31 23:02 -------
Please post entire assembler code.


-- 

hutchinsonandy at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hutchinsonandy at gcc dot
                   |                            |gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41894


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

* [Bug target/41894] wrong code with -fno-split-wide-types
  2009-10-31 21:44 [Bug c/41894] New: wrong code with -fno-split-wide-types frank at mynety dot net
  2009-10-31 23:02 ` [Bug target/41894] " hutchinsonandy at gcc dot gnu dot org
@ 2009-10-31 23:10 ` j at uriah dot heep dot sax dot de
  2009-10-31 23:12 ` j at uriah dot heep dot sax dot de
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: j at uriah dot heep dot sax dot de @ 2009-10-31 23:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from j at uriah dot heep dot sax dot de  2009-10-31 23:10 -------
Created an attachment (id=18944)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18944&action=view)
Full assembler code I get from GCC 4.3.2


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41894


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

* [Bug target/41894] wrong code with -fno-split-wide-types
  2009-10-31 21:44 [Bug c/41894] New: wrong code with -fno-split-wide-types frank at mynety dot net
  2009-10-31 23:02 ` [Bug target/41894] " hutchinsonandy at gcc dot gnu dot org
  2009-10-31 23:10 ` j at uriah dot heep dot sax dot de
@ 2009-10-31 23:12 ` j at uriah dot heep dot sax dot de
  2009-10-31 23:55 ` eric dot weddington at atmel dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: j at uriah dot heep dot sax dot de @ 2009-10-31 23:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from j at uriah dot heep dot sax dot de  2009-10-31 23:11 -------
The bug was originally reported in the (Germany-language) mikrocontroller.net
forum, and I confirmed the bug on my local GCC 4.3.2 setup before asking
Frank to submit it as an official bug report.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41894


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

* [Bug target/41894] wrong code with -fno-split-wide-types
  2009-10-31 21:44 [Bug c/41894] New: wrong code with -fno-split-wide-types frank at mynety dot net
                   ` (2 preceding siblings ...)
  2009-10-31 23:12 ` j at uriah dot heep dot sax dot de
@ 2009-10-31 23:55 ` eric dot weddington at atmel dot com
  2009-11-01 17:24 ` hutchinsonandy at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: eric dot weddington at atmel dot com @ 2009-10-31 23:55 UTC (permalink / raw)
  To: gcc-bugs



-- 

eric dot weddington at atmel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
      Known to fail|                            |4.3.2
   Last reconfirmed|0000-00-00 00:00:00         |2009-10-31 23:55:40
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41894


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

* [Bug target/41894] wrong code with -fno-split-wide-types
  2009-10-31 21:44 [Bug c/41894] New: wrong code with -fno-split-wide-types frank at mynety dot net
                   ` (3 preceding siblings ...)
  2009-10-31 23:55 ` eric dot weddington at atmel dot com
@ 2009-11-01 17:24 ` hutchinsonandy at gcc dot gnu dot org
  2009-11-01 17:27 ` hutchinsonandy at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hutchinsonandy at gcc dot gnu dot org @ 2009-11-01 17:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from hutchinsonandy at gcc dot gnu dot org  2009-11-01 17:24 -------
The problem is still present on 4.3.5 head
I cannot reproduce on 4.5 

It looks like reload issue with SUBREG. 

Instruction 18 gets reloaded. The output reload is HImode. I will post dump
files but here is extract that appears to highlight problem.

>From lreg dump file:

;; Pred edge  3 [50.0%]  (fallthru)
(note 16 15 17 4 [bb 4] NOTE_INSN_BASIC_BLOCK)

(note 17 16 18 4 NOTE_INSN_DELETED)

(insn 18 17 54 4 pr41894.c:29 (set (subreg:QI (reg/v:HI 43 [ tmp ]) 0)
        (plus:QI (reg:QI 42 [ D.1188 ])
            (const_int -1 [0xffffffff]))) 15 {addqi3} (expr_list:REG_DEAD
(reg:QI 42 [ D.1188 ])
        (nil)))

(jump_insn 54 18 55 4 (set (pc)
        (label_ref 26)) 101 {jump} (nil))
;; End of basic block 4 -> ( 6)
;; lr  out       28 [r28] 32 [__SP_L__] 34 [argL] 43
;; live  out     28 [r28] 32 [__SP_L__] 34 [argL] 43


from greg dump file:

Spilling for insn 18.
Using reg 18 for reload 0
Spilling for insn 18.
Using reg 18 for reload 0

Reloads for insn # 18
Reload 0: reload_in (QI) = (reg:QI 24 r24 [orig:42 D.1188 ] [42])
        reload_out (HI) = (reg/v:HI 28 r28 [orig:43 tmp ] [43])
        LD_REGS, RELOAD_OTHER (opnum = 0)
        reload_in_reg: (reg:QI 24 r24 [orig:42 D.1188 ] [42])
        reload_out_reg: (reg/v:HI 28 r28 [orig:43 tmp ] [43])
        reload_reg_rtx: (reg:HI 18 r18)
deleting insn with uid = 2.
;; Register dispositions:
42 in 24  43 in 28  44 in 24  

;; Hard regs used:  18 19 24 25 28 29 32


Giving


(insn 57 17 18 4 pr41894.c:29 (set (reg:QI 18 r18)
        (reg:QI 24 r24 [orig:42 D.1188 ] [42])) 4 {*movqi} (nil))

(insn 18 57 58 4 pr41894.c:29 (set (reg:QI 18 r18)
        (plus:QI (reg:QI 18 r18)
            (const_int -1 [0xffffffff]))) 15 {addqi3} (nil))

(insn 58 18 54 4 pr41894.c:29 (set (reg/v:HI 28 r28 [orig:43 tmp ] [43])
        (reg:HI 18 r18)) 8 {*movhi} (nil))

(jump_insn 54 58 55 4 (set (pc)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41894


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

* [Bug target/41894] wrong code with -fno-split-wide-types
  2009-10-31 21:44 [Bug c/41894] New: wrong code with -fno-split-wide-types frank at mynety dot net
                   ` (4 preceding siblings ...)
  2009-11-01 17:24 ` hutchinsonandy at gcc dot gnu dot org
@ 2009-11-01 17:27 ` hutchinsonandy at gcc dot gnu dot org
  2009-11-01 17:28 ` hutchinsonandy at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hutchinsonandy at gcc dot gnu dot org @ 2009-11-01 17:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from hutchinsonandy at gcc dot gnu dot org  2009-11-01 17:27 -------
Created an attachment (id=18945)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18945&action=view)
dump file


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41894


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

* [Bug target/41894] wrong code with -fno-split-wide-types
  2009-10-31 21:44 [Bug c/41894] New: wrong code with -fno-split-wide-types frank at mynety dot net
                   ` (5 preceding siblings ...)
  2009-11-01 17:27 ` hutchinsonandy at gcc dot gnu dot org
@ 2009-11-01 17:28 ` hutchinsonandy at gcc dot gnu dot org
  2009-11-01 17:45 ` eric dot weddington at atmel dot com
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hutchinsonandy at gcc dot gnu dot org @ 2009-11-01 17:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from hutchinsonandy at gcc dot gnu dot org  2009-11-01 17:27 -------
Created an attachment (id=18946)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18946&action=view)
dump file


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41894


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

* [Bug target/41894] wrong code with -fno-split-wide-types
  2009-10-31 21:44 [Bug c/41894] New: wrong code with -fno-split-wide-types frank at mynety dot net
                   ` (6 preceding siblings ...)
  2009-11-01 17:28 ` hutchinsonandy at gcc dot gnu dot org
@ 2009-11-01 17:45 ` eric dot weddington at atmel dot com
  2009-11-02  0:54 ` hutchinsonandy at gcc dot gnu dot org
  2010-09-20  3:03 ` eric dot weddington at atmel dot com
  9 siblings, 0 replies; 11+ messages in thread
From: eric dot weddington at atmel dot com @ 2009-11-01 17:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from eric dot weddington at atmel dot com  2009-11-01 17:44 -------
(In reply to comment #4)
> The problem is still present on 4.3.5 head
> I cannot reproduce on 4.5 

Can someone check this to see if bug exists on any 4.4.x?


-- 

eric dot weddington at atmel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41894


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

* [Bug target/41894] wrong code with -fno-split-wide-types
  2009-10-31 21:44 [Bug c/41894] New: wrong code with -fno-split-wide-types frank at mynety dot net
                   ` (7 preceding siblings ...)
  2009-11-01 17:45 ` eric dot weddington at atmel dot com
@ 2009-11-02  0:54 ` hutchinsonandy at gcc dot gnu dot org
  2010-09-20  3:03 ` eric dot weddington at atmel dot com
  9 siblings, 0 replies; 11+ messages in thread
From: hutchinsonandy at gcc dot gnu dot org @ 2009-11-02  0:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from hutchinsonandy at gcc dot gnu dot org  2009-11-02 00:54 -------
The problem seems related to use of R28+r29 - which is also frame pointer.

avr_hard_regno_mode_ok allows R28 in HIMODE but not any other mode. (This hack
was made to avoid reload problem where r29 was used as well as R28 frame
pointer)

It looks like the "not ok" QI subreg 28/29 of "ok" HImode r28 is not handled
well. 

The mode restriction is ignored for input reload. (Perhaps because reload
decides to use available frame pointer)

The output reload needed is 16bit HImode but must be accessible as two QImode 
subregs. Somehow the mode of output reload gets mangled so we get movw r28,r18


Originally ~2005 the rejection of other modes by avr_hard_regno_mode_ok for r28
was only applied when reload was in progress and frame_pointer_required.

So I reapplied this condition and the bug was solved. This function does not
need frame pointer so r28 and r29 are indeed freely available.

  /* Otherwise disallow all regno/mode combinations that span r28:r29.  */
  if (reload_in_progress && frame_pointer_needed && regno <= (REG_Y + 1) &&
(regno + GET_MODE_SIZE (mode)) >= (REG_Y + 1))
    return 0;


This also produces better code!

One concern is that the modes deemed ok or not are now not constant - and
perhaps is the reason why condition was removed.

In Gcc 4.5 the spill is exactly the same but it uses R16/r17 with the correct
output reload subreg - so seems to figure out that r28 is "not ok" - suggesting
problem is fixed.


This may take a while to resolve, with some further research and testing.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41894


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

* [Bug target/41894] wrong code with -fno-split-wide-types
  2009-10-31 21:44 [Bug c/41894] New: wrong code with -fno-split-wide-types frank at mynety dot net
                   ` (8 preceding siblings ...)
  2009-11-02  0:54 ` hutchinsonandy at gcc dot gnu dot org
@ 2010-09-20  3:03 ` eric dot weddington at atmel dot com
  9 siblings, 0 replies; 11+ messages in thread
From: eric dot weddington at atmel dot com @ 2010-09-20  3:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from eric dot weddington at atmel dot com  2010-09-20 03:03 -------
Closing as fixed in 4.5.0.


-- 

eric dot weddington at atmel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41894


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

end of thread, other threads:[~2010-09-20  3:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-31 21:44 [Bug c/41894] New: wrong code with -fno-split-wide-types frank at mynety dot net
2009-10-31 23:02 ` [Bug target/41894] " hutchinsonandy at gcc dot gnu dot org
2009-10-31 23:10 ` j at uriah dot heep dot sax dot de
2009-10-31 23:12 ` j at uriah dot heep dot sax dot de
2009-10-31 23:55 ` eric dot weddington at atmel dot com
2009-11-01 17:24 ` hutchinsonandy at gcc dot gnu dot org
2009-11-01 17:27 ` hutchinsonandy at gcc dot gnu dot org
2009-11-01 17:28 ` hutchinsonandy at gcc dot gnu dot org
2009-11-01 17:45 ` eric dot weddington at atmel dot com
2009-11-02  0:54 ` hutchinsonandy at gcc dot gnu dot org
2010-09-20  3:03 ` eric dot weddington at atmel dot com

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