public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/61169] New: [4.6,4.7,4.8,4.9] unnecessarily honors bracket in mathematical statements
@ 2014-05-13 12:31 hannesroest at gmx dot ch
2014-05-13 13:11 ` [Bug tree-optimization/61169] " paolo.carlini at oracle dot com
2014-05-13 13:25 ` rguenth at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: hannesroest at gmx dot ch @ 2014-05-13 12:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61169
Bug ID: 61169
Summary: [4.6,4.7,4.8,4.9] unnecessarily honors bracket in
mathematical statements
Product: gcc
Version: 4.6.3
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hannesroest at gmx dot ch
I hope this is the right place to report this. During some code review of a C++
project, we have noticed that GCC seems to honor brackets added in mathematical
statements in the code unnecessarily and produce slightly suboptimal code under
some circumstances. I am not sure whether this is a feature or not but it can
lead to suboptimal code as we discovered in our codebase and I hoped that I
could get some answers here.
Specifically, the issue is how GCC treats an expression like (x*x) with
brackets vs an expression like x*x without the brackets and prevents
optimization in the first case. Specifically, one can see this in the
following example where gcc >= 4.6 uses 4 instructions for the second function
"test4ops" but only 3 instructions for the first function "test3ops".
Interestingly, gcc < 4.6 used 3 instructions for both functions:
$ cat test.C
int test3ops(int x, int c, int d) {
return c * x + d * x * x;
}
int test4ops(int x, int c, int d) {
return c * x + d * (x * x);
}
$ gcc -S -O3 test.C
$ cat test.s
.file "test.C"
.text
.p2align 4,,15
.globl _Z8test3opsiii
.type _Z8test3opsiii, @function
_Z8test3opsiii:
.LFB0:
.cfi_startproc
imull %edi, %edx
leal (%rdx,%rsi), %eax
imull %edi, %eax
ret
.cfi_endproc
.LFE0:
.size _Z8test3opsiii, .-_Z8test3opsiii
.p2align 4,,15
.globl _Z8test4opsiii
.type _Z8test4opsiii, @function
_Z8test4opsiii:
.LFB1:
.cfi_startproc
imull %edi, %esi
imull %edi, %edi
imull %edx, %edi
leal (%rsi,%rdi), %eax
ret
.cfi_endproc
.LFE1:
.size _Z8test4opsiii, .-_Z8test4opsiii
.ident "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
.section .note.GNU-stack,"",@progbits
$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/61169] [4.6,4.7,4.8,4.9] unnecessarily honors bracket in mathematical statements
2014-05-13 12:31 [Bug c++/61169] New: [4.6,4.7,4.8,4.9] unnecessarily honors bracket in mathematical statements hannesroest at gmx dot ch
@ 2014-05-13 13:11 ` paolo.carlini at oracle dot com
2014-05-13 13:25 ` rguenth at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-05-13 13:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61169
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |tree-optimization
--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Doesn't seem a C++ front-end issue to me.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/61169] [4.6,4.7,4.8,4.9] unnecessarily honors bracket in mathematical statements
2014-05-13 12:31 [Bug c++/61169] New: [4.6,4.7,4.8,4.9] unnecessarily honors bracket in mathematical statements hannesroest at gmx dot ch
2014-05-13 13:11 ` [Bug tree-optimization/61169] " paolo.carlini at oracle dot com
@ 2014-05-13 13:25 ` rguenth at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-05-13 13:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61169
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
You want -ffast-math, or more specificall -fassociative-math. Re-association
can change FP values which is not allowed and the first expression is
(d * x) * x.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-05-13 13:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-13 12:31 [Bug c++/61169] New: [4.6,4.7,4.8,4.9] unnecessarily honors bracket in mathematical statements hannesroest at gmx dot ch
2014-05-13 13:11 ` [Bug tree-optimization/61169] " paolo.carlini at oracle dot com
2014-05-13 13:25 ` rguenth 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).