Skip to content

Commit 250f4d3

Browse files
committed
merge cgelem.d improvements
1 parent 4fda137 commit 250f4d3

1 file changed

Lines changed: 79 additions & 22 deletions

File tree

dm/src/dmc/cgelem.d

Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,7 @@ private elem * elnot(elem *e, goal_t goal)
20982098
case OPu16_d:
20992099
case OPu32_d:
21002100
case OPf_d:
2101+
case OPd_ld:
21012102
case OPs16_32:
21022103
case OPu16_32:
21032104
case OPu8_16:
@@ -2110,18 +2111,6 @@ private elem * elnot(elem *e, goal_t goal)
21102111
e1.Eoper = e.Eoper;
21112112
e = optelem(el_selecte1(e), goal);
21122113
break;
2113-
2114-
case OPcomma:
2115-
/* !(a,b) => (a,!b) */
2116-
e.Eoper = OPcomma;
2117-
e.EV.E1 = e1.EV.E1; // a
2118-
e.EV.E2 = e1; // !
2119-
e1.Eoper = OPnot;
2120-
e1.Ety = e.Ety;
2121-
e1.EV.E1 = e1.EV.E2; // b
2122-
e1.EV.E2 = null;
2123-
e = optelem(e, goal);
2124-
break;
21252114
}
21262115
return e;
21272116
}
@@ -4474,6 +4463,30 @@ private elem * elcmp(elem *e, goal_t goal)
44744463
}
44754464
}
44764465

4466+
if (e1.Eoper == OPf_d && tysize(e1.Ety) == 8 && cast(targ_float)e2.EV.Vdouble == e2.EV.Vdouble)
4467+
{
4468+
/* Remove unnecessary OPf_d operator
4469+
*/
4470+
e.EV.E1 = e1.EV.E1;
4471+
e1.EV.E1 = null;
4472+
el_free(e1);
4473+
e2.Ety = e.EV.E1.Ety;
4474+
e2.EV.Vfloat = cast(targ_float)e2.EV.Vdouble;
4475+
return optelem(e,GOALvalue);
4476+
}
4477+
4478+
if (e1.Eoper == OPd_ld && tysize(e1.Ety) == tysize(TYldouble) && cast(targ_double)e2.EV.Vldouble == e2.EV.Vldouble)
4479+
{
4480+
/* Remove unnecessary OPd_ld operator
4481+
*/
4482+
e.EV.E1 = e1.EV.E1;
4483+
e1.EV.E1 = null;
4484+
el_free(e1);
4485+
e2.Ety = e.EV.E1.Ety;
4486+
e2.EV.Vdouble = cast(targ_double)e2.EV.Vldouble;
4487+
return optelem(e,GOALvalue);
4488+
}
4489+
44774490
/* Convert (ulong > uint.max) to (msw(ulong) != 0)
44784491
*/
44794492
if (OPTIMIZER && I32 && e.Eoper == OPgt && sz == LLONGSIZE && e2.EV.Vullong == 0xFFFFFFFF)
@@ -4617,18 +4630,45 @@ ret:
46174630
private elem * elbool(elem *e, goal_t goal)
46184631
{
46194632
//printf("elbool()\n");
4620-
if (OTlogical(e.EV.E1.Eoper) ||
4633+
elem* e1 = e.EV.E1;
4634+
const op = e1.Eoper;
4635+
4636+
if (OTlogical(op) ||
46214637
// bool bool => bool
4622-
(tybasic(e.EV.E1.Ety) == TYbool && tysize(e.Ety) == 1)
4638+
(tybasic(e1.Ety) == TYbool && tysize(e.Ety) == 1)
46234639
)
46244640
return el_selecte1(e);
46254641

4642+
switch (op)
4643+
{
4644+
case OPs32_d:
4645+
case OPs16_d:
4646+
case OPu16_d:
4647+
case OPu32_d:
4648+
case OPf_d:
4649+
case OPd_ld:
4650+
case OPs16_32:
4651+
case OPu16_32:
4652+
case OPu8_16:
4653+
case OPs8_16:
4654+
case OPu32_64:
4655+
case OPs32_64:
4656+
case OPvp_fp:
4657+
case OPcvp_fp:
4658+
case OPnp_fp:
4659+
e1.Eoper = e.Eoper;
4660+
return optelem(el_selecte1(e), goal);
4661+
4662+
default:
4663+
break;
4664+
}
4665+
46264666
if (OPTIMIZER)
46274667
{
46284668
int shift;
46294669

46304670
// Replace bool(x,1) with (x,1),1
4631-
elem *e1 = elscancommas(e.EV.E1);
4671+
e1 = elscancommas(e1);
46324672
if (cnst(e1) || e1.Eoper == OPrelconst)
46334673
{
46344674
int i = boolres(e1) != 0;
@@ -5642,7 +5682,7 @@ private elem * optelem(elem *e, goal_t goal)
56425682
beg:
56435683
//__gshared uint count;
56445684
//printf("count: %u\n", ++count);
5645-
//{ printf("xoptelem: %p ",e); WROP(e.Eoper); print(" goal x%x\n", goal); }
5685+
//{ printf("xoptelem: %p ",e); WROP(e.Eoper); printf(" goal x%x\n", goal); }
56465686
assert(e);
56475687
elem_debug(e);
56485688
assert(e.Ecount == 0); // no CSEs
@@ -6073,24 +6113,41 @@ beg:
60736113
}
60746114
else /* unary operator */
60756115
{
6116+
elem* e1 = e.EV.E1;
6117+
6118+
/* op(a,b) => a,(op b)
6119+
*/
6120+
if (e1.Eoper == OPcomma && op != OPstrpar && op != OPddtor)
6121+
{
6122+
e.Eoper = e1.Eoper;
6123+
e.EV.E1 = e1.EV.E1;
6124+
e.EV.E2 = e1;
6125+
e1.Eoper = op;
6126+
e1.Ety = e.Ety;
6127+
e1.ET = e.ET;
6128+
e1.EV.E1 = e1.EV.E2;
6129+
e1.EV.E2 = null;
6130+
return optelem(e, goal);
6131+
}
6132+
60766133
assert(!e.EV.E2 || op == OPinfo || op == OPddtor);
60776134
if (!goal && !OTsideff(op) && !(e.Ety & (mTYvolatile | mTYshared)))
60786135
{
6079-
tym_t tym = e.EV.E1.Ety;
6136+
tym_t tym = e1.Ety;
60806137

60816138
e = el_selecte1(e);
60826139
e.Ety = tym;
60836140
return optelem(e,GOALnone);
60846141
}
60856142

6086-
if ((op == OPd_f || op == OPd_ld) && e.EV.E1.Eoper == OPu64_d)
6143+
if ((op == OPd_f || op == OPd_ld) && e1.Eoper == OPu64_d)
60876144
{
60886145
return elu64_d(e, goal);
60896146
}
60906147

6091-
elem *e1 = e.EV.E1 = optelem(e.EV.E1, (op == OPddtor)
6092-
? GOALnone
6093-
: (op == OPbool || op == OPnot) ? GOALflags : GOALvalue);
6148+
e1 = e.EV.E1 = optelem(e1, (op == OPddtor)
6149+
? GOALnone
6150+
: (op == OPbool || op == OPnot) ? GOALflags : GOALvalue);
60946151
if (!e1)
60956152
goto retnull;
60966153
if (e1.Eoper == OPconst)
@@ -6153,7 +6210,7 @@ elem *doptelem(elem *e, goal_t goal)
61536210
if (goal & GOALstruct && e && (tybasic(e.Ety) == TYstruct || tybasic(e.Ety) == TYarray))
61546211
e = elstruct(e, goal);
61556212

6156-
if (topair)
6213+
if (topair && e)
61576214
e = elToPair(e);
61586215

61596216
return e;

0 commit comments

Comments
 (0)