In my numerical simulation I have code similar to the following snippet
double x;
do {
x = /* some computation */;
} while (x <= 0.0);
/* some algorithm
In your question, you stated that using volatile will work but that there'll be a huge performance hit. What about using the volatile variable only during the comparison, allowing x to be held in a register?
double x; /* might have excess precision */
volatile double x_dbl; /* guaranteed to be double precision */
do {
x = /* some computation */;
x_dbl = x;
} while (x_dbl <= 0.0);
You should also check if you can speed up the comparison with the smallest subnormal value by using long double explicitly and cache this value, ie
const long double dbl_denorm_min = static_cast(std::numeric_limits::denorm_min());
and then compare
x < dbl_denorm_min
I'd assume that a decent compiler would do this automatically, but one never knows...