Skip to content

Commit

Permalink
gsroa: allow anything that fits in a slice to be a slice
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Feb 6, 2019
1 parent 1f85d7f commit 68c1a14
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/dmd/backend/cg87.d
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ void fixresult87(ref CodeBuilder cdb,elem *e,regm_t retregs,regm_t *pretregs)
/* if retregs needs to be transferred into the 8087 */
if (*pretregs & mST0 && retregs & (mBP | ALLREGS))
{
if (sz > DOUBLESIZE) elem_print(e);
assert(sz <= DOUBLESIZE);
if (!I16)
{
Expand Down
46 changes: 35 additions & 11 deletions src/dmd/backend/gsroa.d
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ extern (D) private void sliceStructs_Gather(const symtab_t* symtab, SymInfo[] si
assert(si < symtab.top);
const n = nthSlice(e);
const sz = tysize(e.Ety);
if (sz == 2 * SLICESIZE && !tyfv(e.Ety))
if (sz == 2 * SLICESIZE && !tyfv(e.Ety) &&
tybasic(e.Ety) != TYldouble && tybasic(e.Ety) != TYildouble)
{
// Rewritten as OPpair later
}
Expand All @@ -88,9 +89,22 @@ extern (D) private void sliceStructs_Gather(const symtab_t* symtab, SymInfo[] si
*/
foreach (ref ty; sia[si].ty)
ty = TYnptr;

const s = e.EV.Vsym;
const t = s.Stype;
if (tybasic(t.Tty) == TYstruct)
{
if (const targ1 = t.Ttag.Sstruct.Sarg1type)
if (const targ2 = t.Ttag.Sstruct.Sarg2type)
{
sia[si].ty[0] = targ1.Tty;
sia[si].ty[1] = targ2.Tty;
}
}
}
sia[si].accessSlice = true;
sia[si].ty[n] = tybasic(e.Ety);
if (sz == SLICESIZE)
sia[si].ty[n] = tybasic(e.Ety);
}
else
{
Expand Down Expand Up @@ -214,7 +228,7 @@ extern (D) private void sliceStructs_Replace(symtab_t* symtab, const SymInfo[] s
else // the nth slice
{
e.EV.Vsym = symtab.tab[sia[si].si0 + n];
e.EV.Voffset = 0;
e.EV.Voffset -= n * SLICESIZE;
//printf("replaced with:\n");
//elem_print(e);
}
Expand All @@ -241,7 +255,7 @@ extern (D) private void sliceStructs_Replace(symtab_t* symtab, const SymInfo[] s

void sliceStructs(symtab_t* symtab, block* startblock)
{
if (debugc) printf("sliceStructs()\n");
if (debugc) printf("sliceStructs() %s\n", funcsym_p.Sident.ptr);
const sia_length = symtab.top;
/* 3 is because it is used for two arrays, sia[] and sia2[].
* sia2[] can grow to twice the size of sia[], as symbols can get split into two.
Expand All @@ -262,6 +276,12 @@ void sliceStructs(symtab_t* symtab, block* startblock)
SymInfo[] sia = sip[0 .. sia_length];
SymInfo[] sia2 = sip[sia_length .. sia_length * 3];

if (0) foreach (si; 0 .. symtab.top)
{
Symbol *s = symtab.tab[si];
printf("[%d]: %p %d %s\n", si, s, cast(int)type_size(s.Stype), s.Sident.ptr);
}

bool anySlice = false;
foreach (si; 0 .. symtab.top)
{
Expand Down Expand Up @@ -409,13 +429,17 @@ enum NOTSLICE = -1;
int nthSlice(const(elem)* e)
{
const sz = tysize(e.Ety);
if (sz == SLICESIZE)
{
if (e.EV.Voffset == 0)
return 0;
if (e.EV.Voffset == SLICESIZE)
return 1;
}
const sliceSize = SLICESIZE;

/* See if e fits in a slice
*/
const lwr = e.EV.Voffset;
const upr = lwr + sz;
if (0 <= lwr && upr <= sliceSize)
return 0;
if (sliceSize <= lwr && upr <= sliceSize * 2)
return 1;

return NOTSLICE;
}

Expand Down
7 changes: 5 additions & 2 deletions test/runnable/test42.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import std.stdio;
import core.stdc.stdio;
import std.string;
import core.memory;
import core.vararg;

/***************************************************/

Expand Down Expand Up @@ -52,7 +53,7 @@ void test3()
{
auto i = mixin("__LINE__");
writefln("%d", i);
assert(i == 53);
assert(i == 54);
}

/***************************************************/
Expand Down Expand Up @@ -3281,7 +3282,6 @@ void test201() {
/***************************************************/
// This was the original varargs example in std.vararg

import core.vararg;

void foo202(int x, ...) {
printf("%d arguments\n", _arguments.length);
Expand Down Expand Up @@ -4508,6 +4508,7 @@ void test6997()
auto x = S6997().foo();
}


/***************************************************/

ubyte foo7026(uint n) {
Expand Down Expand Up @@ -5540,6 +5541,7 @@ void test14682b()
{ auto x = [[[[]]]] ~ a3; static assert(is(typeof(x) == typeof(a3)[])); assert(x == r4b); } // fix
}


/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=9739

Expand Down Expand Up @@ -6157,6 +6159,7 @@ void test11472()
assert(x11472 == 10);
}


/***************************************************/

int main()
Expand Down

0 comments on commit 68c1a14

Please sign in to comment.