public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/54330] New: Wrong optimization for code from fixed-bit.c
@ 2012-08-20 14:08 gjl at gcc dot gnu.org
  2012-08-20 14:11 ` [Bug other/54330] " gjl at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gjl at gcc dot gnu.org @ 2012-08-20 14:08 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54330
           Summary: Wrong optimization for code from fixed-bit.c
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: other
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: gjl@gcc.gnu.org
              Host: i686-pc-linux-gnu
            Target: avr
             Build: i686-pc-linux-gnu


Created attachment 28056
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28056
fixed-bit-bug.c: preprocessed bit for fixed.bit.c::__satfractudadq

This is a wrong code bug seen while implementing the ISO/IED TR18037
fixed-point support for AVR.

== compile ==

$ avr-gcc fixed-bit-bug.c -mmcu=atmega128 -Os -S -fdump-rtl-expand-details

== configure ==

$ ../../gcc.gnu.org/trunk/configure --target=avr
--prefix=/local/gnu/install/gcc-4.8 --disable-nls --with-dwarf2
--enable-target-optspace=yes --enable-languages=c,c++

== Bug ==

The .expand dump contains a wrong insn, a GTU branch instead of a LEU branch:

The code tests if the high bit of a shift result is set by comparing >
0x7fffffffffffffff. If the value is less-or-equal, the saturation against 0
must be skipped (goto #76), but the GTU leads to a reversal of the condition. 
The block that saturates is BB6:

(insn 104 103 105 5 (parallel [
            (set (cc0)
                (compare (reg:DI 18 r18)
                    (const_double -1 [0xffffffff] 2147483647 [0x7fffffff] 0 [0]
0 [0] 0 [0] 0 [0])))
            (clobber (scratch:QI))
        ]) fixed-bit-bug.c:56 -1
     (nil))
(jump_insn 105 104 132 5 (set (pc)
        (if_then_else (gtu (cc0)
                (const_int 0 [0]))
            (label_ref 76)
            (pc))) fixed-bit-bug.c:56 -1
     (expr_list:REG_BR_PROB (const_int 6100 [0x17d4])
        (nil))
 -> 76)
(note 132 105 29 6 [bb 6] NOTE_INSN_BASIC_BLOCK)
(insn 29 132 21 6 (clobber (reg/v:DI 42 [ low ])) fixed-bit-bug.c:56 -1
     (nil))
(insn 21 29 22 6 (set (subreg:QI (reg/v:DI 42 [ low ]) 0)
        (const_int 0 [0])) fixed-bit-bug.c:56 -1
     (nil))


All of the following changes lead to correct code, u.e. LEU instead of GTU:

* -O1 instead of -O0

* -fno-builtin-memcpy

* Using DI mode instead of DQ resp. DA mode, see the respective #define in the
attaches test case.

Correct code will look like that:

(jump_insn 91 90 132 4 (set (pc)
        (if_then_else (leu (cc0)
                (const_int 0 [0]))
            (label_ref:HI 102)
            (pc))) 444 {difficult_branch}
     (expr_list:REG_BR_PROB (const_int 5000 [0x1388])
        (nil))
 -> 102)
(note 132 91 100 5 [bb 5] NOTE_INSN_BASIC_BLOCK)
(insn 100 132 92 5 (clobber (reg/v:DI 42 [ low ])) -1
     (nil))
(insn 92 100 93 5 (set (subreg:QI (reg/v:DI 42 [ low ]) 0)
        (const_int -1 [0xffffffff])) -1
     (nil))


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

* [Bug other/54330] Wrong optimization for code from fixed-bit.c
  2012-08-20 14:08 [Bug other/54330] New: Wrong optimization for code from fixed-bit.c gjl at gcc dot gnu.org
@ 2012-08-20 14:11 ` gjl at gcc dot gnu.org
  2012-08-20 14:16 ` gjl at gcc dot gnu.org
  2012-08-20 14:23 ` gjl at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: gjl at gcc dot gnu.org @ 2012-08-20 14:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2012-08-20 14:11:30 UTC ---
Created attachment 28057
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28057
fixed-bit-bug.c.150r.expand: Correct code if DI used instead of DQ/DA


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

* [Bug other/54330] Wrong optimization for code from fixed-bit.c
  2012-08-20 14:08 [Bug other/54330] New: Wrong optimization for code from fixed-bit.c gjl at gcc dot gnu.org
  2012-08-20 14:11 ` [Bug other/54330] " gjl at gcc dot gnu.org
@ 2012-08-20 14:16 ` gjl at gcc dot gnu.org
  2012-08-20 14:23 ` gjl at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: gjl at gcc dot gnu.org @ 2012-08-20 14:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2012-08-20 14:15:51 UTC ---
Created attachment 28058
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28058
fixed-bit-bug.c.150r.expand: Wrong code


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

* [Bug other/54330] Wrong optimization for code from fixed-bit.c
  2012-08-20 14:08 [Bug other/54330] New: Wrong optimization for code from fixed-bit.c gjl at gcc dot gnu.org
  2012-08-20 14:11 ` [Bug other/54330] " gjl at gcc dot gnu.org
  2012-08-20 14:16 ` gjl at gcc dot gnu.org
@ 2012-08-20 14:23 ` gjl at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: gjl at gcc dot gnu.org @ 2012-08-20 14:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2012-08-20 14:22:46 UTC ---
FYI, there is the fixed-point configuration output from

... -E -dM | egrep '(DQ)|(DA)|([^L]LACC)|(LLFRA)' | sort

DImode (long long) is 64 bits

#define __DA_FBIT__ 32
#define __DA_IBIT__ 31
#define __DQ_FBIT__ 63
#define __DQ_IBIT__ 0
#define __LACCUM_EPSILON__ 0x1P-32LK
#define __LACCUM_FBIT__ 32
#define __LACCUM_IBIT__ 31
#define __LACCUM_MAX__ 0X7FFFFFFFFFFFFFFFP-32LK
#define __LACCUM_MIN__ (-0X1P30LK-0X1P30LK)
#define __LLFRACT_EPSILON__ 0x1P-63LLR
#define __LLFRACT_FBIT__ 63
#define __LLFRACT_IBIT__ 0
#define __LLFRACT_MAX__ 0X7FFFFFFFFFFFFFFFP-63LLR
#define __LLFRACT_MIN__ (-0.5LLR-0.5LLR)
#define __UDA_FBIT__ 32
#define __UDA_IBIT__ 32
#define __UDQ_FBIT__ 64
#define __UDQ_IBIT__ 0
#define __ULACCUM_EPSILON__ 0x1P-32ULK
#define __ULACCUM_FBIT__ 32
#define __ULACCUM_IBIT__ 32
#define __ULACCUM_MAX__ 0XFFFFFFFFFFFFFFFFP-32ULK
#define __ULACCUM_MIN__ 0.0ULK
#define __ULLFRACT_EPSILON__ 0x1P-64ULLR
#define __ULLFRACT_FBIT__ 64
#define __ULLFRACT_IBIT__ 0
#define __ULLFRACT_MAX__ 0XFFFFFFFFFFFFFFFFP-64ULLR
#define __ULLFRACT_MIN__ 0.0ULLR


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

end of thread, other threads:[~2012-08-20 14:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-20 14:08 [Bug other/54330] New: Wrong optimization for code from fixed-bit.c gjl at gcc dot gnu.org
2012-08-20 14:11 ` [Bug other/54330] " gjl at gcc dot gnu.org
2012-08-20 14:16 ` gjl at gcc dot gnu.org
2012-08-20 14:23 ` 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).