public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/43721] New: Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call
@ 2010-04-11 20:39 mans at mansr dot com
2010-04-12 3:54 ` [Bug rtl-optimization/43721] " astrange at ithinksw dot com
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: mans at mansr dot com @ 2010-04-11 20:39 UTC (permalink / raw)
To: gcc-bugs
Consider the following code:
int divmod(int a, int b)
{
int q = a / b;
int r = a % b;
return q + r;
}
For an ARM EABI target, this results in one __aeabi_idivmod() call and one
__aeabi_idiv() call even though the former already calculates the quotient.
--
Summary: Failure to optimise (a/b) and (a%b) into single
__aeabi_idivmod call
Product: gcc
Version: 4.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mans at mansr dot com
GCC build triplet: x86_64-pc-linux-gnu
GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: arm-unknown-linux-gnueabi
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43721
^ permalink raw reply [flat|nested] 7+ 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: Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call 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; 7+ 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] 7+ 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: Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call 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; 7+ 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] 7+ 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: Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call 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; 7+ 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] 7+ 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: Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call 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; 7+ 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] 7+ 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: Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call 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; 7+ 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] 7+ 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: Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call 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; 7+ 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] 7+ messages in thread
end of thread, other threads:[~2010-04-14 21:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-11 20:39 [Bug rtl-optimization/43721] New: Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call 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).