public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/43721] Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call
       [not found] <bug-43721-4@http.gcc.gnu.org/bugzilla/>
@ 2010-10-20 16:53 ` ams at gcc dot gnu.org
  2011-02-17 15:54 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 8+ messages in thread
From: ams at gcc dot gnu.org @ 2010-10-20 16:53 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Stubbs <ams at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ams at gcc dot gnu.org

--- Comment #6 from Andrew Stubbs <ams at gcc dot gnu.org> 2010-10-20 16:53:13 UTC ---
Here's the problem: expand_divmod always prefers the straight "div" library
call over the "divmod" library call, no exceptions.

Yes, "divmodsi4" in a .md is indeed preferred over "divsi4", so the
optimization works fine on targets that have those, but ARM doesn't, so those
rules are irrelevant.

ARM does not provide a separate library function for "mod", so expand_divmod
does use "divmod" for mod operations, but never for div operations.

The reason for the apparent opposite rules appears to be that the divmodsi4
rule can be coded to auto-detect the most optimal kind of underlying operation
to use, whereas the library call is fixed, once chosen.

I see two possible ways to fix this:
 1. Teach CSE (or somewhere) that div and divmod library calls have some
overlap.
 2. Always prefer divmod, and find some other way to convert it to div, where
appropriate.

I don't see any way to generate the RTL with the right call, so I'm pretty sure
it does have to be fixed up after the fact.

Or, I could be way off. :)


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

* [Bug rtl-optimization/43721] Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call
       [not found] <bug-43721-4@http.gcc.gnu.org/bugzilla/>
  2010-10-20 16:53 ` [Bug rtl-optimization/43721] Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call ams at gcc dot gnu.org
@ 2011-02-17 15:54 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-02-17 15:54 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |carrot at google dot com

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-02-17 15:50:30 UTC ---
*** Bug 47777 has been marked as a duplicate of this bug. ***


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

* [Bug rtl-optimization/43721] Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call
  2010-04-11 20:39 [Bug rtl-optimization/43721] New: " mans at mansr dot com
                   ` (4 preceding siblings ...)
  2010-04-14 21:38 ` rearnsha at gcc dot gnu dot org
@ 2010-04-14 21:39 ` rearnsha at gcc dot gnu dot org
  5 siblings, 0 replies; 8+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2010-04-14 21:39 UTC (permalink / raw)
  To: gcc-bugs



-- 

rearnsha at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |missed-optimization


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


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

* [Bug rtl-optimization/43721] Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call
  2010-04-11 20:39 [Bug rtl-optimization/43721] New: " mans at mansr dot com
                   ` (3 preceding siblings ...)
  2010-04-14 21:34 ` mans at mansr dot com
@ 2010-04-14 21:38 ` rearnsha at gcc dot gnu dot org
  2010-04-14 21:39 ` rearnsha at gcc dot gnu dot org
  5 siblings, 0 replies; 8+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2010-04-14 21:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rearnsha at gcc dot gnu dot org  2010-04-14 21:38 -------
I think that's enough evidence to confirm.


-- 

rearnsha at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-04-14 21:38:25
               date|                            |


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


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

* [Bug rtl-optimization/43721] Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call
  2010-04-11 20:39 [Bug rtl-optimization/43721] New: " mans at mansr dot com
                   ` (2 preceding siblings ...)
  2010-04-14 21:31 ` rguenth at gcc dot gnu dot org
@ 2010-04-14 21:34 ` mans at mansr dot com
  2010-04-14 21:38 ` rearnsha at gcc dot gnu dot org
  2010-04-14 21:39 ` rearnsha at gcc dot gnu dot org
  5 siblings, 0 replies; 8+ messages in thread
From: mans at mansr dot com @ 2010-04-14 21:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from mans at mansr dot com  2010-04-14 21:34 -------
The C99 standard says this about division by zero:

  The result of the / operator is the quotient from the division
  of the first operand by the second; the result of the % operator
  is the remainder. In both operations, if the value of the second
  operand is zero, the behavior is undefined.

The ARM ABI states the following about the __aeabi_div0() function:

  The *div0 functions:
  - Return the value passed to them as a parameter.
  - Or, return a fixed value defined by the execution environment (such as 0).
  - Or, raise a signal (often SIGFPE) or throw an exception, and do not return.
  [...]
  The *div and *divmod functions may be inlined by a tool chain. It is
  Q-o-I whether an inlined version calls *div0 out of line or returns the
  values that would have been returned by a particular value-returning
  version of *div0.

I interpret these as saying the application may make no assumptions about
the behaviour after a division (or modulus) by zero.


-- 


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


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

* [Bug rtl-optimization/43721] Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call
  2010-04-11 20:39 [Bug rtl-optimization/43721] New: " mans at mansr dot com
  2010-04-12  3:54 ` [Bug rtl-optimization/43721] " astrange at ithinksw dot com
  2010-04-14 20:50 ` rearnsha at gcc dot gnu dot org
@ 2010-04-14 21:31 ` rguenth at gcc dot gnu dot org
  2010-04-14 21:34 ` mans at mansr dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-04-14 21:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2010-04-14 21:30 -------
The policy has been AFAIR that we can collapse multiple traps into a single
one,
but not remove traps completely (or of course not introduce new ones).


-- 


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


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

* [Bug rtl-optimization/43721] Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call
  2010-04-11 20:39 [Bug rtl-optimization/43721] New: " mans at mansr dot com
  2010-04-12  3:54 ` [Bug rtl-optimization/43721] " astrange at ithinksw dot com
@ 2010-04-14 20:50 ` rearnsha at gcc dot gnu dot org
  2010-04-14 21:31 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2010-04-14 20:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rearnsha at gcc dot gnu dot org  2010-04-14 20:50 -------
Before confirming this bug, we need to determine if the following program has
well defined behaviour:

int count_div0 = 0;

int __aeabi_div0()
{
  count_div0++;
  return 0;
}

int divmod(int a, int b)
{
    int q = a / b;
    int r = a % b;
    return q + r;
}

int main()
{
  divmod(33, 0);
  printf("%d", count_div0);
  return 0;
}

If the above program should always print "2", then the compiler is correct and
this report is invalid.  If it may print any value, then the compiler is wrong
and should be fixed to optimize this case.  Note that __aeabi_div0 will be
called if either __aeabi_idiv or __aeabi_idivmod are called with 0 as the
second parameter.



-- 

rearnsha at gcc dot gnu dot org changed:

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


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


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

* [Bug rtl-optimization/43721] Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call
  2010-04-11 20:39 [Bug rtl-optimization/43721] New: " mans at mansr dot com
@ 2010-04-12  3:54 ` astrange at ithinksw dot com
  2010-04-14 20:50 ` rearnsha at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: astrange at ithinksw dot com @ 2010-04-12  3:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from astrange at ithinksw dot com  2010-04-12 03:54 -------
Still the case with 4.5.

> arm-none-linux-gnueabi-gcc -Os -S divmod.c
> cat divmod.s
        .cpu arm10tdmi
        .fpu softvfp
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 2
        .eabi_attribute 30, 4
        .eabi_attribute 18, 4
        .file   "divmod.c"
        .global __aeabi_idivmod
        .global __aeabi_idiv
        .text
        .align  2
        .global divmod
        .type   divmod, %function
divmod:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        stmfd   sp!, {r4, r5, r6, lr}
        mov     r6, r0
        mov     r5, r1
        bl      __aeabi_idivmod
        mov     r0, r6
        mov     r4, r1
        mov     r1, r5
        bl      __aeabi_idiv
        add     r0, r4, r0
        ldmfd   sp!, {r4, r5, r6, pc}
        .size   divmod, .-divmod
        .ident  "GCC: (GNU) 4.5.0 20100325 (experimental)"
        .section        .note.GNU-stack,"",%progbits


-- 

astrange at ithinksw dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |astrange at ithinksw dot com


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


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

end of thread, other threads:[~2011-02-17 15:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-43721-4@http.gcc.gnu.org/bugzilla/>
2010-10-20 16:53 ` [Bug rtl-optimization/43721] Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call ams at gcc dot gnu.org
2011-02-17 15:54 ` pinskia at gcc dot gnu.org
2010-04-11 20:39 [Bug rtl-optimization/43721] New: " mans at mansr dot com
2010-04-12  3:54 ` [Bug rtl-optimization/43721] " astrange at ithinksw dot com
2010-04-14 20:50 ` rearnsha at gcc dot gnu dot org
2010-04-14 21:31 ` rguenth at gcc dot gnu dot org
2010-04-14 21:34 ` mans at mansr dot com
2010-04-14 21:38 ` rearnsha at gcc dot gnu dot org
2010-04-14 21:39 ` rearnsha at gcc dot gnu dot 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).