Hi! When the return value of a builtin is ignored, it is being expanded with target const0_rtx and VOIDmode, but deeper in the builtin expansion routines the const0_rtx target is actually transformed into NULL target (if it is figured out that the builtin just can't be optimized away completely). ix86_expand_builtin for target == NULL creates a pseudo with mode to store the result to though, which is fine for const/pure builtins because they won't make it through without the return value being actually used (tested say __builtin_nanq () and others), but for non-const/pure builtins it results in ICEs. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.8?
2013-06-27 Jakub Jelinek <ja...@redhat.com> PR target/57736 * config/i386/i386.c (ix86_expand_builtin): If target == NULL and mode is VOIDmode, don't create a VOIDmode pseudo to copy result into. * gcc.target/i386/pr57736.c: New test. --- gcc/config/i386/i386.c.jj 2013-06-23 20:43:36.000000000 +0200 +++ gcc/config/i386/i386.c 2013-06-27 21:01:16.464580253 +0200 @@ -32222,7 +32222,13 @@ ix86_expand_builtin (tree exp, rtx targe } if (target == 0) - target = gen_reg_rtx (mode); + { + /* mode is VOIDmode if __builtin_rd* has been called + without lhs. */ + if (mode == VOIDmode) + return target; + target = gen_reg_rtx (mode); + } if (TARGET_64BIT) { --- gcc/testsuite/gcc.target/i386/pr57736.c.jj 2013-06-27 21:14:26.448580682 +0200 +++ gcc/testsuite/gcc.target/i386/pr57736.c 2013-06-27 21:15:52.575039737 +0200 @@ -0,0 +1,41 @@ +/* PR target/57736 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +#include <x86intrin.h> + +unsigned long long +f1 (void) +{ + return __rdtsc (); +} + +unsigned long long +f2 (unsigned int *x) +{ + return __rdtscp (x); +} + +unsigned long long +f3 (unsigned int x) +{ + return __rdpmc (x); +} + +void +f4 (void) +{ + __rdtsc (); +} + +void +f5 (unsigned int *x) +{ + __rdtscp (x); +} + +void +f6 (unsigned int x) +{ + __rdpmc (x); +} Jakub