public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "wvangulik at xs4all dot nl" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/33970] Missed optimization using unsigned char loop variable
Date: Mon, 05 Nov 2007 22:48:00 -0000	[thread overview]
Message-ID: <20071105224852.21079.qmail@sourceware.org> (raw)
In-Reply-To: <bug-33970-15294@http.gcc.gnu.org/bugzilla/>



------- Comment #8 from wvangulik at xs4all dot nl  2007-11-05 22:48 -------
(In reply to comment #7)
> With Mike's description in comment #6, confirmed on 4.1.2 and 4.2.2. AVR GCC
> 4.2.2 is worse than 4.1.2, in that even if sub2 is called with (x+1), the
> variable is still 16 bits.
> 

There is something more going on, this is the assembler output when sub2 is not
in the same file, and calling sub2(x), i.e not x+1:
===================================================================

        push r17
        push r28
        push r29
        in r28,__SP_L__
        in r29,__SP_H__
        sbiw r28,1
        in __tmp_reg__,__SREG__
        cli
        out __SP_H__,r29
        out __SREG__,__tmp_reg__
        out __SP_L__,r28
/* prologue end (size=11) */
.L3:
        sts x.1261,__zero_reg__
        ldi r24,lo8(0)
.L4:
        ldd r17,Y+1
        call sub2
        add r17,r24
        std Y+1,r17
        lds r24,x.1261
        subi r24,lo8(-(1))
        sts x.1261,r24
        sbrs r24,7
        rjmp .L4
        rjmp .L3
===========================================================

Note that x is now living in memory (as one would expect when it's static in a
function). However it's not when looking at the original report. Is this ok?
The original post assembler places x in r14,r15.  Does this still adhere the
static keyword? I don't know, since it's value is always set at the start
what's the point of being static? Unless main is called twice? But then x may
not be in r14/r15!

So it seems to me this is some inline optimation problem.

Note that moving the sub2 function above main also gives other results?!? Is
this standard behaviour?

Also note that when making sub2 static will completely remove it but also
remove x as static, is this allowed?

Tested against avr-gcc 4.1.2


-- 

wvangulik at xs4all dot nl changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wvangulik at xs4all dot nl


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


  parent reply	other threads:[~2007-11-05 22:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-01 13:44 [Bug c/33970] New: " henning dot m at insightbb dot com
2007-11-01 14:10 ` [Bug c/33970] " rguenth at gcc dot gnu dot org
2007-11-01 17:09 ` [Bug middle-end/33970] " pinskia at gcc dot gnu dot org
2007-11-01 17:28 ` eweddington at cso dot atmel dot com
2007-11-01 17:45 ` eweddington at cso dot atmel dot com
2007-11-01 17:47 ` eweddington at cso dot atmel dot com
2007-11-01 21:26 ` henning dot m at insightbb dot com
2007-11-04 23:28 ` eweddington at cso dot atmel dot com
2007-11-04 23:28 ` eweddington at cso dot atmel dot com
2007-11-05 22:48 ` wvangulik at xs4all dot nl [this message]
2007-11-06 12:37 ` henning dot m at insightbb dot com
2007-11-06 19:35 ` wvangulik at xs4all dot nl
2007-11-06 21:01 ` wvangulik at xs4all dot nl
2010-09-13 12:09 ` abnikant dot singh at atmel dot com
     [not found] <bug-33970-4@http.gcc.gnu.org/bugzilla/>
2011-07-20 17:48 ` 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=20071105224852.21079.qmail@sourceware.org \
    --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).