Bug 53416 - Wrong code when optimising loop involving _rdrand32_step
Summary: Wrong code when optimising loop involving _rdrand32_step
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.6.4
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-19 14:56 UTC by marcel.kyas
Modified: 2012-05-21 13:08 UTC (History)
3 users (show)

See Also:
Host:
Target: i?86-*-* x86_64-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-05-20 00:00:00


Attachments
Reduced test case (10.64 KB, application/octet-stream)
2012-05-19 14:56 UTC, marcel.kyas
Details

Note You need to log in before you can comment on or make changes to this bug.
Description marcel.kyas 2012-05-19 14:56:12 UTC
Created attachment 27440 [details]
Reduced test case

The attached file prints different output depending whether it is compiled with -O0, -O1 or -O2 on gcc-Version 4.7.0 20120507 (Red Hat 4.7.0-5) (GCC).

When the file is built with gcc -std=c99 -mrdrnd -O0 rngtest.i, it prints four different random numbers. If it is built with gcc -std=c99 -mrdrnd -O1 rngtest.i, it prints the same number four times. If it is built with gcc -std=c99 -mrdrnd -O2 rngtest.i, it prints the random number four times and prints the random number as the result of the call to _rdrand32_step. The last one is especially surprising, because _rdrand32_step should only return 0 or 1.
Comment 1 H.J. Lu 2012-05-20 17:05:40 UTC
A patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2012-05/msg01338.html
Comment 2 hjl@gcc.gnu.org 2012-05-21 12:32:04 UTC
Author: hjl
Date: Mon May 21 12:31:45 2012
New Revision: 187709

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187709
Log:
Use unspec_volatile on rdrand<mode>_1

gcc/

	PR target/53416
	* config/i386/i386.md (UNSPEC_RDRAND): Renamed to ...
	(UNSPECV_RDRAND): This.
	(rdrand<mode>_1): Updated.

gcc/testsuite/

	PR target/53416
	* gcc.target/i386/pr53416.c: New file.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr53416.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.md
    trunk/gcc/testsuite/ChangeLog
Comment 3 hjl@gcc.gnu.org 2012-05-21 12:59:58 UTC
Author: hjl
Date: Mon May 21 12:59:53 2012
New Revision: 187712

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187712
Log:
Use unspec_volatile on rdrand<mode>_1

gcc/

	Backport from mainline
	PR target/53416
	* config/i386/i386.md (UNSPEC_RDRAND): Renamed to ...
	(UNSPECV_RDRAND): This.
	(rdrand<mode>_1): Updated.


gcc/testsuite/

	Backport from mainline
	PR target/53416
	* gcc.target/i386/pr53416.c: New file.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/gcc.target/i386/pr53416.c
Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/config/i386/i386.md
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 4 hjl@gcc.gnu.org 2012-05-21 13:07:16 UTC
Author: hjl
Date: Mon May 21 13:07:11 2012
New Revision: 187713

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187713
Log:
Use unspec_volatile on rdrand<mode>_1

gcc/

	Backport from mainline
	PR target/53416
	* config/i386/i386.md (UNSPEC_RDRAND): Renamed to ...
	(UNSPECV_RDRAND): This.
	(rdrand<mode>_1): Updated.


gcc/testsuite/

	Backport from mainline
	PR target/53416
	* gcc.target/i386/pr53416.c: New file.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/i386/pr53416.c
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/config/i386/i386.md
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 5 H.J. Lu 2012-05-21 13:08:53 UTC
Fixed.