mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 13:40:11 +03:00
Merge pull request #6895 from ibuclaw/pow-optimize
Always set the result type before returning from PowExp.optimize.
This commit is contained in:
commit
cb54f4c3b1
1 changed files with 6 additions and 2 deletions
|
@ -803,14 +803,16 @@ extern (C++) Expression Expression_optimize(Expression e, int result, bool keepL
|
||||||
if ((e.e1.op == TOKint64 && e.e1.toInteger() == 1) || (e.e1.op == TOKfloat64 && e.e1.toReal() == CTFloat.one))
|
if ((e.e1.op == TOKint64 && e.e1.toInteger() == 1) || (e.e1.op == TOKfloat64 && e.e1.toReal() == CTFloat.one))
|
||||||
{
|
{
|
||||||
ret = new CommaExp(e.loc, e.e2, e.e1);
|
ret = new CommaExp(e.loc, e.e2, e.e1);
|
||||||
|
ret.type = e.type;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Replace -1 ^^ x by (x&1) ? -1 : 1, where x is integral
|
// Replace -1 ^^ x by (x&1) ? -1 : 1, where x is integral
|
||||||
if (e.e2.type.isintegral() && e.e1.op == TOKint64 && cast(sinteger_t)e.e1.toInteger() == -1)
|
if (e.e2.type.isintegral() && e.e1.op == TOKint64 && cast(sinteger_t)e.e1.toInteger() == -1)
|
||||||
{
|
{
|
||||||
Type resultType = e.type;
|
|
||||||
ret = new AndExp(e.loc, e.e2, new IntegerExp(e.loc, 1, e.e2.type));
|
ret = new AndExp(e.loc, e.e2, new IntegerExp(e.loc, 1, e.e2.type));
|
||||||
ret = new CondExp(e.loc, ret, new IntegerExp(e.loc, -1, resultType), new IntegerExp(e.loc, 1, resultType));
|
ret.type = e.e2.type;
|
||||||
|
ret = new CondExp(e.loc, ret, new IntegerExp(e.loc, -1, e.type), new IntegerExp(e.loc, 1, e.type));
|
||||||
|
ret.type = e.type;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Replace x ^^ 0 or x^^0.0 by (x, 1)
|
// Replace x ^^ 0 or x^^0.0 by (x, 1)
|
||||||
|
@ -821,6 +823,7 @@ extern (C++) Expression Expression_optimize(Expression e, int result, bool keepL
|
||||||
else
|
else
|
||||||
ret = new RealExp(e.loc, CTFloat.one, e.e1.type);
|
ret = new RealExp(e.loc, CTFloat.one, e.e1.type);
|
||||||
ret = new CommaExp(e.loc, e.e1, ret);
|
ret = new CommaExp(e.loc, e.e1, ret);
|
||||||
|
ret.type = e.type;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Replace x ^^ 1 or x^^1.0 by (x)
|
// Replace x ^^ 1 or x^^1.0 by (x)
|
||||||
|
@ -833,6 +836,7 @@ extern (C++) Expression Expression_optimize(Expression e, int result, bool keepL
|
||||||
if (e.e2.op == TOKfloat64 && e.e2.toReal() == CTFloat.minusone)
|
if (e.e2.op == TOKfloat64 && e.e2.toReal() == CTFloat.minusone)
|
||||||
{
|
{
|
||||||
ret = new DivExp(e.loc, new RealExp(e.loc, CTFloat.one, e.e2.type), e.e1);
|
ret = new DivExp(e.loc, new RealExp(e.loc, CTFloat.one, e.e2.type), e.e1);
|
||||||
|
ret.type = e.type;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// All other negative integral powers are illegal
|
// All other negative integral powers are illegal
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue