Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize s=s where s is a struct #20580

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/src/dmd/backend/cgelem.d
Original file line number Diff line number Diff line change
Expand Up @@ -3521,6 +3521,13 @@ elem * elstruct(elem *e, Goal goal)
return optelem(e, goal);
}

// Replace (e = e) with (e, e)
if (e.Eoper == OPstreq && el_match(e.E1, e.E2))
{
e.Eoper = OPcomma;
return optelem(e, goal);
}

if (!e.ET)
return e;
//printf("\tnumbytes = %d\n", cast(int)type_size(e.ET));
Expand Down
21 changes: 21 additions & 0 deletions compiler/test/runnable/mars1.d
Original file line number Diff line number Diff line change
Expand Up @@ -2507,6 +2507,26 @@ void test20574()

////////////////////////////////////////////////////////////////////////

struct S8
{
int x,y,z;
}

int test8x(S8 s)
{
s = s;
return s.y;
}

void test8()
{
S8 s;
s.y = 2;
assert(test8x(s) == 2);
}

////////////////////////////////////////////////////////////////////////

int main()
{
// All the various integer divide tests
Expand Down Expand Up @@ -2607,6 +2627,7 @@ int main()
test21835();
testDoWhileContinue();
test20574();
test8();

printf("Success\n");
return 0;
Expand Down
Loading