Skip to content

Commit

Permalink
refactor cgelem.eleq() for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Dec 19, 2024
1 parent b7a3a19 commit 2e9c280
Showing 1 changed file with 40 additions and 49 deletions.
89 changes: 40 additions & 49 deletions compiler/src/dmd/backend/cgelem.d
Original file line number Diff line number Diff line change
Expand Up @@ -3809,7 +3809,6 @@ static if (0) // Doesn't work too well, removed
if (el_match(e1,e2))
{
e.Eoper = OPcomma;
L1:
return optelem(e, Goal.value);
}

Expand All @@ -3820,58 +3819,53 @@ static if (0) // Doesn't work too well, removed
e.E2 = e2.E2;
e2.E2 = e;
e = e2;
goto L1;
return optelem(e, Goal.value);
}

if (OTop(op2) && !el_sideeffect(e1)
&& op2 != OPdiv && op2 != OPmod
)
{
tym_t ty;

enum side = false; // don't allow side effects in e2.E2 because of
// D order-of-evaluation rules

// Replace (e1 = e1 op e) with (e1 op= e)
if (el_match(e1,e2.E1) &&
(side || !el_sideeffect(e2.E2)))
{
ty = e2.E2.Ety;
const ty = e2.E2.Ety;
e.E2 = el_selecte2(e2);
L2:
e.E2.Ety = ty;
e.Eoper = cast(ubyte)optoopeq(op2);
goto L1;
return optelem(e, Goal.value);
}
if (OTcommut(op2))

/* Replace (e1 = e op e1) with (e1 op= e) */
if (OTcommut(op2) && el_match(e1,e2.E2))
{
/* Replace (e1 = e op e1) with (e1 op= e) */
if (el_match(e1,e2.E2))
{ ty = e2.E1.Ety;
e.E2 = el_selecte1(e2);
goto L2;
}
const ty = e2.E1.Ety;
e.E2 = el_selecte1(e2);
e.E2.Ety = ty;
e.Eoper = cast(ubyte)optoopeq(op2);
return optelem(e, Goal.value);
}

static if (0)
{
// Note that this optimization is undone in elcomma(), this results in an
// infinite loop. This optimization is preferable if e1 winds up a register
// variable, the inverse in elcomma() is preferable if e1 winds up in memory.
// Disabled because this optimization is undone in elcomma(), this results in an
// infinite loop. This optimization is preferable if e1 winds up a register
// variable, the inverse in elcomma() is preferable if e1 winds up in memory.
// Replace (e1 = (e1 op3 ea) op2 eb) with (e1 op3= ea),(e1 op2= eb)
int op3 = e2.E1.Eoper;
if (OTop(op3) && el_match(e1,e2.E1.E1) && !el_depends(e1,e2.E2))
if (0 && OTop(op3) && el_match(e1,e2.E1.E1) && !el_depends(e1,e2.E2))
{
e.Eoper = OPcomma;
e.E1 = e2.E1;
e.E1.Eoper = optoopeq(op3);
e.E1.Eoper = cast(ubyte)optoopeq(op3);

Check warning on line 3862 in compiler/src/dmd/backend/cgelem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/cgelem.d#L3862

Added line #L3862 was not covered by tests
e2.E1 = e1;
e1.Ety = e.E1.Ety;
e2.Eoper = optoopeq(op2);
e2.Eoper = cast(ubyte)optoopeq(op2);

Check warning on line 3865 in compiler/src/dmd/backend/cgelem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/cgelem.d#L3865

Added line #L3865 was not covered by tests
e2.Ety = e.Ety;
goto L1;
return optelem(e, Goal.value);

Check warning on line 3867 in compiler/src/dmd/backend/cgelem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/cgelem.d#L3867

Added line #L3867 was not covered by tests
}
}
}

if (op2 == OPneg && el_match(e1,e2.E1) && !el_sideeffect(e1))
Expand Down Expand Up @@ -3927,38 +3921,35 @@ static if (0)
!config.fpxmmregs)
{
tym_t ty;

elem *es = el_calloc();
es.Eoper = OPconst;
switch (tysize(e2.Ety))
{
case FLOATSIZE:
ty = TYlong;
es.Vlong = 0x80000000;
break;
goto L8;

Check warning on line 3928 in compiler/src/dmd/backend/cgelem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/cgelem.d#L3928

Added line #L3928 was not covered by tests

case DOUBLESIZE:
if (I32)
{
ty = TYllong;
es.Vllong = 0x8000000000000000L;
if (!I32)

Check warning on line 3931 in compiler/src/dmd/backend/cgelem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/cgelem.d#L3931

Added line #L3931 was not covered by tests
break;
}
goto default;

ty = TYllong;

Check warning on line 3934 in compiler/src/dmd/backend/cgelem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/cgelem.d#L3934

Added line #L3934 was not covered by tests
L8:
elem* es = el_calloc();
if (ty == TYlong)
es.Vlong = 0x8000_0000;

Check warning on line 3938 in compiler/src/dmd/backend/cgelem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/cgelem.d#L3936-L3938

Added lines #L3936 - L3938 were not covered by tests
else
es.Vllong = 0x8000_0000_0000_0000L;
es.Eoper = OPconst;
es.Ety = ty;
e1.Ety = ty;
e2.Ety = ty;
e2.E1.Ety = ty;
e2.E2 = es;
e2.Eoper = OPxor;
return optelem(e, Goal.value);

Check warning on line 3948 in compiler/src/dmd/backend/cgelem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/cgelem.d#L3940-L3948

Added lines #L3940 - L3948 were not covered by tests

default:
el_free(es);
goto L8;
break;

Check warning on line 3951 in compiler/src/dmd/backend/cgelem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/cgelem.d#L3951

Added line #L3951 was not covered by tests
}
es.Ety = ty;
e1.Ety = ty;
e2.Ety = ty;
e2.E1.Ety = ty;
e2.E2 = es;
e2.Eoper = OPxor;
return optelem(e, Goal.value);

L8:
}

// Replace (a=(r1 pair r2)) with (a1=r1), (a2=r2)
Expand Down Expand Up @@ -4029,11 +4020,11 @@ static if (0)
}
}

if (e1.Eoper == OPcomma)
if (e1.Eoper == OPcomma)
return cgel_lvalue(e);
if (e1.Eoper != OPbit)
if (e1.Eoper != OPbit)
return e;
if (e1.E1.Eoper == OPcomma || OTassign(e1.E1.Eoper))
if (e1.E1.Eoper == OPcomma || OTassign(e1.E1.Eoper))
return cgel_lvalue(e);

uint t = e.Ety;
Expand Down

0 comments on commit 2e9c280

Please sign in to comment.