[Issue 9387] Compiler switch -O changes behavior of correct code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jan 29 15:13:54 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9387
Don <clugdbug at yahoo.com.au> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
--- Comment #12 from Don <clugdbug at yahoo.com.au> 2013-01-29 15:13:51 PST ---
Here is a more reduced test case (still enormous):
Without -O, it returns on the first pass through the loop. With -O, one of two
things happen:
(a) it hits the assert(0) on the first pass through the loop; or
(b) it generates an alignment hardware exception.
It looks as though it is a issue with misalignment of SSE registers.
Removing the assert(0) causes an ICE.
---
import std.math : abs;
void minimize()
{
double a,b,d=0.0,etemp,fu,fv,fw,fx;
double p;
double q,r,tol1,tol2,u,v,w,x,xm;
double e=0.0;
double ax,bx,cx,fa,fb,fc;
double tol;
ax = 2.8541;
bx = 3;
cx = 3.0458;
fa = 0.145898;
fb = 0;
fc = 0.381966;
tol = 3.0e-8;
a= ax;
b= cx;
v = bx;
w = bx;
x = bx;
fx = 0;
fv = fx;
fw = fx;
a = 2.97871347812973974456; b = 3.0458; v =2.9442711606; w =2.9787134781;
x = 3; fx= 0; fv = 0.00310570354087098691;
fw = 0.00045311601333306815;
e =-0.0557288394;
d = -0.0212865219;
for (int iter=0;iter<1;iter++) {
xm=0.5*(a+b);
tol1=tol*abs(x);
tol2=2.0*(tol1);
if (abs(x-xm) <= (tol2-0.5*(b-a))) {
return;
}
if (abs(e) > tol1) {
r=(x-w)*(fx-fv);
q=(x-v)*(fx-fw);
p=(x-v)*q-(x-w)*r;
q=2.0*(q-r);
if (q > 0.0) p = -p;
q=abs(q);
etemp=e;
e=d;
if (abs(p) >= abs(0.5*q*etemp) || q < p) {
d= b-x;
}
else {
d=p/q;
u=x+d;
if (u-a < tol2 || b-u < tol2)
d = xm - x;
}
}
else { d= (e=(x >= xm ? a-x : b-x)); }
u= (abs(d) >= tol1) ? x+d : x+3.0e-8;
if (u < 3.01) return;
else
assert(0); // FAILS HERE
fu = (u-3.0)*(u-3.0);
if (fu <= fx) {
assert(0);
}
}
}
void main() {
minimize();
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list