From c6286ab558e64883199e9d16ffd2bc10fbb2cd20 Mon Sep 17 00:00:00 2001 From: Ben Jones Date: Wed, 1 May 2024 16:31:32 -0600 Subject: [PATCH] backend: use el_scancommas to skip over OPcomma chains --- compiler/src/dmd/backend/blockopt.d | 21 +++++---------------- compiler/src/dmd/backend/cg87.d | 9 +++------ compiler/src/dmd/backend/cgelem.d | 3 +-- compiler/src/dmd/backend/cod1.d | 3 +-- compiler/src/dmd/backend/elem.d | 10 ++++++---- compiler/src/dmd/backend/gother.d | 3 +-- compiler/src/dmd/e2ir.d | 5 +---- 7 files changed, 18 insertions(+), 36 deletions(-) diff --git a/compiler/src/dmd/backend/blockopt.d b/compiler/src/dmd/backend/blockopt.d index 696091d6cf..8ec7fc6c28 100644 --- a/compiler/src/dmd/backend/blockopt.d +++ b/compiler/src/dmd/backend/blockopt.d @@ -851,8 +851,7 @@ private void bropt() { elem **pn = &(b.Belem); if (OPTIMIZER && *pn) - while ((*pn).Eoper == OPcomma) - pn = &((*pn).EV.E2); + pn = el_scancommas(pn); elem *n = *pn; @@ -927,8 +926,7 @@ private void bropt() } else if (b.BC == BCswitch) { /* see we can evaluate this switch now */ - while (n.Eoper == OPcomma) - n = n.EV.E2; + n = *el_scancommas(&n); if (n.Eoper != OPconst) continue; assert(tyintegral(n.Ety)); @@ -1803,20 +1801,13 @@ private void brtailrecursion() if (el_anyframeptr(*pe)) // if any OPframeptr's return; - static elem** skipCommas(elem** pe) - { - while ((*pe).Eoper == OPcomma) - pe = &(*pe).EV.E2; - return pe; - } - - pe = skipCommas(pe); + pe = el_scancommas(pe); elem *e = *pe; static bool isCandidate(elem* e) { - e = *skipCommas(&e); + e = *el_scancommas(&e); if (e.Eoper == OPcond) return isCandidate(e.EV.E2.EV.E1) || isCandidate(e.EV.E2.EV.E2); @@ -1990,9 +1981,7 @@ private void emptyloops() continue; // Find einit - elem *einit; - for (einit = bpred.Belem; einit.Eoper == OPcomma; einit = einit.EV.E2) - { } + elem *einit = *el_scancommas(&(bpred.Belem)); if (einit.Eoper != OPeq || einit.EV.E2.Eoper != OPconst || einit.EV.E1.Eoper != OPvar) diff --git a/compiler/src/dmd/backend/cg87.d b/compiler/src/dmd/backend/cg87.d index cd8215ed1d..f70d5b2236 100644 --- a/compiler/src/dmd/backend/cg87.d +++ b/compiler/src/dmd/backend/cg87.d @@ -273,8 +273,7 @@ void note87(elem *e, uint offset, int i, int linnum) } assert(i < global87.stackused); - while (e.Eoper == OPcomma) - e = e.EV.E2; + e = *el_scancommas(&e); global87.stack[i].e = e; global87.stack[i].offset = offset; } @@ -310,8 +309,7 @@ private void makesure87(ref CodeBuilder cdb,elem *e,uint offset,int i,uint flag, { debug if (NDPP) printf("makesure87(e=%p, offset=%d, i=%d, flag=%d, line=%d)\n",e,offset,i,flag,linnum); - while (e.Eoper == OPcomma) - e = e.EV.E2; + e = *el_scancommas(&e); assert(e && i < 4); L1: if (global87.stack[i].e != e || global87.stack[i].offset != offset) @@ -2021,8 +2019,7 @@ void eq87(ref CodeBuilder cdb,elem *e,regm_t *pretregs) if (*pretregs & (mST0 | ALLREGS | mBP | XMMREGS)) // if want result on stack too { // Make sure it's still there elem *e2 = e.EV.E2; - while (e2.Eoper == OPcomma) - e2 = e2.EV.E2; + e2 = *el_scancommas(&e2); note87(e2,0,0); getlvalue87(cdb, cs, e.EV.E1, 0); makesure87(cdb,e2,0,0,1); diff --git a/compiler/src/dmd/backend/cgelem.d b/compiler/src/dmd/backend/cgelem.d index 8a228ad8cb..bc4ba3fc5e 100644 --- a/compiler/src/dmd/backend/cgelem.d +++ b/compiler/src/dmd/backend/cgelem.d @@ -3677,8 +3677,7 @@ elem * elstruct(elem *e, goal_t goal) pe2 = &e.EV.E1; else break; - while ((*pe2).Eoper == OPcomma) - pe2 = &(*pe2).EV.E2; + pe2 = el_scancommas(pe2); elem *e2 = *pe2; if (e2.Eoper == OPvar) diff --git a/compiler/src/dmd/backend/cod1.d b/compiler/src/dmd/backend/cod1.d index d072f54e0a..9d77e46f41 100644 --- a/compiler/src/dmd/backend/cod1.d +++ b/compiler/src/dmd/backend/cod1.d @@ -84,8 +84,7 @@ int isscaledindex(elem *e) targ_uns ss; assert(!I16); - while (e.Eoper == OPcomma) - e = e.EV.E2; + e = *el_scancommas(&e); if (!(e.Eoper == OPshl && !e.Ecount && e.EV.E2.Eoper == OPconst && (ss = e.EV.E2.EV.Vuns) <= 3 diff --git a/compiler/src/dmd/backend/elem.d b/compiler/src/dmd/backend/elem.d index 34eb2e0215..9dc429b3ee 100644 --- a/compiler/src/dmd/backend/elem.d +++ b/compiler/src/dmd/backend/elem.d @@ -1180,14 +1180,16 @@ bool el_returns(const(elem)* e) /******************************** * Scan down commas and return the controlling elem. + * Extra layer of indirection so we can update + * (*ret) */ @trusted -elem *el_scancommas(elem *e) +elem **el_scancommas(elem **pe) { - while (e.Eoper == OPcomma) - e = e.EV.E2; - return e; + while ((*pe).Eoper == OPcomma) + pe = &(*pe).EV.E2; + return pe; } /*************************** diff --git a/compiler/src/dmd/backend/gother.d b/compiler/src/dmd/backend/gother.d index 691c5c8ba3..953126e524 100644 --- a/compiler/src/dmd/backend/gother.d +++ b/compiler/src/dmd/backend/gother.d @@ -1910,8 +1910,7 @@ public void verybusyexp() pn = &(b.Belem); if (*pn) { - while ((*pn).Eoper == OPcomma) - pn = &((*pn).EV.E2); + pn = el_scancommas(pn); /* If last statement has side effects, */ /* don't do these VBEs. Potentially we */ /* could by assigning the result to */ diff --git a/compiler/src/dmd/e2ir.d b/compiler/src/dmd/e2ir.d index f77c73e4c3..1277260d25 100644 --- a/compiler/src/dmd/e2ir.d +++ b/compiler/src/dmd/e2ir.d @@ -420,10 +420,7 @@ elem *addressElem(elem *e, Type t, bool alwaysCopy = false) { //printf("addressElem()\n"); - elem **pe; - for (pe = &e; (*pe).Eoper == OPcomma; pe = &(*pe).EV.E2) - { - } + elem **pe = el_scancommas(&e); // For conditional operator, both branches need conversion. if ((*pe).Eoper == OPcond)