http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56027
Bug #: 56027 Summary: ldmxcsr permuted with asm Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: gli...@gcc.gnu.org Target: x86_64-linux-gnu Hello, up to now, I had the impression that the use of a function like "opaque" below was enough to prevent bad optimizations. However, in the following program, compiled with g++ -O1 -frounding-math, the assertion fails. sqrtsd and *mxcsr seem to get permuted (possibly in the loop2_* RTL passes). Defining macro V1 or V2 seems to fix it, but it is slower and I don't know if it is completely safe. Marking the asm volatile also works (and should have less impact on speed), but again I don't know how safe that is. #include <xmmintrin.h> #include <assert.h> #include <fenv.h> inline double opaque(double x){ #ifndef V1 asm("":"+xm"(x)); #else asm("":"+m"(x)); #endif return x; } inline double f(double x){ double ret = __builtin_sqrt(opaque(x)); return opaque(ret); } int main(){ double d=2; double l,h; for(int i=0;i<100;++i){ #ifndef V2 _MM_SET_ROUNDING_MODE(_MM_ROUND_DOWN); #else fesetround(FE_DOWNWARD); #endif l=f(d); #ifndef V2 _MM_SET_ROUNDING_MODE(_MM_ROUND_UP); #else fesetround(FE_UPWARD); #endif h=f(d); } assert(l!=h); }