public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/56546] New: Using the divide operator on unsigned int produces incorrect code on AVR
@ 2013-03-05 22:12 kpet at free dot fr
  2013-03-07 22:21 ` [Bug target/56546] " gjl at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: kpet at free dot fr @ 2013-03-05 22:12 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56546
           Summary: Using the divide operator on unsigned int produces
                    incorrect code on AVR
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kpet@free.fr


Created attachment 29592
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29592
Sample code to reproduce the issue

Using the divide integer on unsigned int variables on an AVR target leads to
wrong code being generated. The generated code uses the __umulhisi3 routine
from libgcc which is a multiplication routine and the result is always zero.

As I'm willing to increase my knowledge about the inner workings of gcc, I
tried to start debugging it myself. I found (using -fdump-rtl-all) that the
issue was occurring in the RTL part of the compiler where the udiv was at
several point transformed into a mult. I tried disabling the first pass that
did the transformation (-fdisable-rtl-fwprop1) and the udiv was propagated a
little further in the process until the ira pass.

I then tried to disable the ira pass using -fdisable-rtl-ira, made gcc crash
and discovered it was a really stupid thing to do
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56514).

So here I am again but his time leaving compiler debugging to the compiler guys
:-)

I've come up with a very simple source file that allows to reproduce the issue.

By the way I couldn't think of any case where transforming a udiv into a mult
operating on integers would make sense and would be glad if someone could give
me some hints on this.

Here's the command line I used:

avr-gcc -O0 -g -Wall -Wextra -save-temps -mmcu=atmega8 -o main.elf main.c

And the version of the toolchain components:

binutils: efb7cff2df30eb792d30e8afc384aa88c193932b
gcc: ef11013858b41453c4953ca8d4c25e3b1668e536
avr-libc: 2ac01d285e23894ef3bcc65c75b39da8157b9fd9

gcc-4.7.2, binutils 2.23.1 and avr-libc 1.8.0 give the same result.


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

end of thread, other threads:[~2013-03-11 11:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-05 22:12 [Bug target/56546] New: Using the divide operator on unsigned int produces incorrect code on AVR kpet at free dot fr
2013-03-07 22:21 ` [Bug target/56546] " gjl at gcc dot gnu.org
2013-03-10 17:24 ` kpet at free dot fr
2013-03-11 11:50 ` 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).