* [Bug c/47617] SSE rounding mode works -g, not -O3
2011-02-05 22:27 [Bug c/47617] New: SSE rounding mode works -g, not -O3 cck0011 at yahoo dot com
@ 2011-02-06 2:13 ` pinskia at gcc dot gnu.org
2011-02-06 16:44 ` cck0011 at yahoo dot com
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-02-06 2:13 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47617
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-02-06 02:13:37 UTC ---
I think you need to use -frounding-math. GCC assumes by default the rounding
mode is round-to-nearest. See
http://gcc.gnu.org/onlinedocs/gcc-4.5.2/gcc/Optimize-Options.html#index-frounding_002dmath-819
.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/47617] SSE rounding mode works -g, not -O3
2011-02-05 22:27 [Bug c/47617] New: SSE rounding mode works -g, not -O3 cck0011 at yahoo dot com
2011-02-06 2:13 ` [Bug c/47617] " pinskia at gcc dot gnu.org
@ 2011-02-06 16:44 ` cck0011 at yahoo dot com
2011-02-07 11:54 ` [Bug target/47617] " rguenth at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cck0011 at yahoo dot com @ 2011-02-06 16:44 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47617
--- Comment #2 from cck0011 at yahoo dot com 2011-02-06 16:25:55 UTC ---
(In reply to comment #1)
> I think you need to use -frounding-math. GCC assumes by default the rounding
> mode is round-to-nearest. See
> http://gcc.gnu.org/onlinedocs/gcc-4.5.2/gcc/Optimize-Options.html#index-frounding_002dmath-819
> .
Hi Andrew,
thanks for writing. I tried -frounding-math and the result is still the same.
Adding/removing -mfpmath=sse doesn't change it either. Is there any additional
information I can provide?
Thanks!
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug target/47617] SSE rounding mode works -g, not -O3
2011-02-05 22:27 [Bug c/47617] New: SSE rounding mode works -g, not -O3 cck0011 at yahoo dot com
2011-02-06 2:13 ` [Bug c/47617] " pinskia at gcc dot gnu.org
2011-02-06 16:44 ` cck0011 at yahoo dot com
@ 2011-02-07 11:54 ` rguenth at gcc dot gnu.org
2011-02-08 1:46 ` cck0011 at yahoo dot com
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-02-07 11:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47617
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target| |i?86-*-linux
Status|UNCONFIRMED |WAITING
Last reconfirmed| |2011.02.07 11:52:28
Component|c |target
Ever Confirmed|0 |1
--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-02-07 11:52:28 UTC ---
Can you provide non-preprocessed source? I have difficulties in compiling with
newer releases.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug target/47617] SSE rounding mode works -g, not -O3
2011-02-05 22:27 [Bug c/47617] New: SSE rounding mode works -g, not -O3 cck0011 at yahoo dot com
` (2 preceding siblings ...)
2011-02-07 11:54 ` [Bug target/47617] " rguenth at gcc dot gnu.org
@ 2011-02-08 1:46 ` cck0011 at yahoo dot com
2011-02-08 1:58 ` cck0011 at yahoo dot com
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cck0011 at yahoo dot com @ 2011-02-08 1:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47617
--- Comment #4 from cck0011 at yahoo dot com 2011-02-08 01:37:58 UTC ---
Created attachment 23273
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23273
source file
Here's the source code. Rename to round.c.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug target/47617] SSE rounding mode works -g, not -O3
2011-02-05 22:27 [Bug c/47617] New: SSE rounding mode works -g, not -O3 cck0011 at yahoo dot com
` (3 preceding siblings ...)
2011-02-08 1:46 ` cck0011 at yahoo dot com
@ 2011-02-08 1:58 ` cck0011 at yahoo dot com
2011-02-08 1:59 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cck0011 at yahoo dot com @ 2011-02-08 1:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47617
--- Comment #5 from cck0011 at yahoo dot com 2011-02-08 01:46:18 UTC ---
(In reply to comment #4)
> Created attachment 23273 [details]
> source file
>
> Here's the source code. Rename to round.c.
Hi Richard,
here's the source code. Rename to round.c.
I think I must be doing something wrong here. Someone would have noticed that
results from _mm_cvtps_pi16 weren't changing when _MM_SET_ROUNDING_MODE() was
called. -) I'm puzzled by it working with -g, but not with -O3.
Any additional information I can provide?
Thanks!
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug target/47617] SSE rounding mode works -g, not -O3
2011-02-05 22:27 [Bug c/47617] New: SSE rounding mode works -g, not -O3 cck0011 at yahoo dot com
` (4 preceding siblings ...)
2011-02-08 1:58 ` cck0011 at yahoo dot com
@ 2011-02-08 1:59 ` pinskia at gcc dot gnu.org
2011-02-08 11:36 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-02-08 1:59 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47617
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution| |DUPLICATE
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-02-08 01:58:40 UTC ---
The problem is the same as recorded as PR 34678. We are optimizing all the
_mm_cvtps_pi16 to one of them because we don't see the rounding mode has
changed. To get the correct values each time do the following:
void test_rounding(void)
{
__m128 source = {-1.1, 0.0, 1.1, 1.5};
__m64 dest;
unsigned int initial_mode;
initial_mode = _MM_GET_ROUNDING_MODE();
print_rounding_mode("initial rounding mode", initial_mode);
/* now set the rounding mode to each value to see the result */
asm("":"+X"(source)); // force source to be different but the same
_MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST);
dest = _mm_cvtps_pi16(source);
_mm_empty();
print_round_results("with _MM_ROUND_NEAREST ", source, dest);
asm("":"+X"(source)); // force source to be different but the same
_MM_SET_ROUNDING_MODE(_MM_ROUND_DOWN);
dest = _mm_cvtps_pi16(source);
_mm_empty();
print_round_results("with _MM_ROUND_DOWN ", source, dest);
asm("":"+X"(source)); // force source to be different but the same
_MM_SET_ROUNDING_MODE(_MM_ROUND_UP);
dest = _mm_cvtps_pi16(source);
_mm_empty();
print_round_results("with _MM_ROUND_UP ", source, dest);
asm("":"+X"(source)); // force source to be different but the same
_MM_SET_ROUNDING_MODE(_MM_ROUND_TOWARD_ZERO);
dest = _mm_cvtps_pi16(source);
_mm_empty();
print_round_results("with _MM_ROUND_TOWARD_ZERO ", source, dest);
/* restore initial rounding mode */
_MM_SET_ROUNDING_MODE(initial_mode);
}
*** This bug has been marked as a duplicate of bug 34678 ***
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug target/47617] SSE rounding mode works -g, not -O3
2011-02-05 22:27 [Bug c/47617] New: SSE rounding mode works -g, not -O3 cck0011 at yahoo dot com
` (5 preceding siblings ...)
2011-02-08 1:59 ` pinskia at gcc dot gnu.org
@ 2011-02-08 11:36 ` rguenth at gcc dot gnu.org
2011-02-09 2:50 ` cck0011 at yahoo dot com
2011-02-12 18:32 ` cck0011 at yahoo dot com
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-02-08 11:36 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47617
--- Comment #7 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-02-08 11:35:32 UTC ---
Well, this case is slightly different as we simply have const/pure builtins
that do not only depend on their arguments (but the FP state). Thus we'd need
to trop the attributes from these functions for -frounding-math. Not that
it would help a lot, given PR34678 ...
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug target/47617] SSE rounding mode works -g, not -O3
2011-02-05 22:27 [Bug c/47617] New: SSE rounding mode works -g, not -O3 cck0011 at yahoo dot com
` (6 preceding siblings ...)
2011-02-08 11:36 ` rguenth at gcc dot gnu.org
@ 2011-02-09 2:50 ` cck0011 at yahoo dot com
2011-02-12 18:32 ` cck0011 at yahoo dot com
8 siblings, 0 replies; 10+ messages in thread
From: cck0011 at yahoo dot com @ 2011-02-09 2:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47617
--- Comment #8 from cck0011 at yahoo dot com 2011-02-09 02:08:23 UTC ---
Hi folks,
First, thanks for working on this.
Second, I read the link and I _think_ I understand it. Let me paraphrase it
back to you and you can tell me if I've got the point:
There is an optimizer that extracts common expressions and evaluates them
once instead of every time they occur. (What's the name of that so I can call
it by the right name?) In my code it finds the expression:
dest = _mm_cvtps_pi16(source);
Several times. Since it doesn't see source changing, this expression only
gets evaluated once. Now, the change to rounding mode that happens with
_MM_SET_ROUNDING_MODE(...) isn't detected as something that would change the
value of the _mm_cvtps_pi16(...) expression, so the optimization is not
removed. Recognizing that change to rounding mode and reacting to it is what's
at the heart of bug 34678, and that's why this is a duplicate.
The work-arounds are:
1)insert 'asm("":"+X"(source));' before changing rounding mode to make the
compiler re-evaluate expressions that use source.
2) do _MM_SET_ROUNDING_MODE(...) before any divisions or integer conversions
that might get optimized out. The scope of the optimization is a function body
and any inlined code. So do _MM_SET_ROUNDING_MODE early within that scope.
Is my understanding correct?
A few more questions:
Will this bug exist on non-X86 processors?
What does the 'asm("":"+X"(source));' expression do ?
Will this syntax work for non-X86 processors?
To be correct, should I compile with -frounding-math ?
Thanks!
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug target/47617] SSE rounding mode works -g, not -O3
2011-02-05 22:27 [Bug c/47617] New: SSE rounding mode works -g, not -O3 cck0011 at yahoo dot com
` (7 preceding siblings ...)
2011-02-09 2:50 ` cck0011 at yahoo dot com
@ 2011-02-12 18:32 ` cck0011 at yahoo dot com
8 siblings, 0 replies; 10+ messages in thread
From: cck0011 at yahoo dot com @ 2011-02-12 18:32 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47617
--- Comment #9 from cck0011 at yahoo dot com 2011-02-12 18:20:03 UTC ---
Hi folks,
I tried the asm("":"+X"(source)); as shown. I get an error: inconsistent
operand constraints in an ‘asm’.
The info pages make it look like this should work, but the Inline Assembly
Howto doesn't mention the X constraint. If the compiler should agree with the
info pages, I'm doing something wrong. What am I missing?
thanks
^ permalink raw reply [flat|nested] 10+ messages in thread