-
-
Notifications
You must be signed in to change notification settings - Fork 647
Fix Bugzilla Issue 20535: Backend Optimizer Slowdown in Static Foreach #21019
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,23 +198,33 @@ | |
@trusted | ||
void block_pred() | ||
{ | ||
//printf("block_pred()\n"); | ||
for (block* b = bo.startblock; b; b = b.Bnext) // for each block | ||
list_free(&b.Bpred,FPNULL); | ||
bool[block*] visited; // Keep track of visited blocks | ||
|
||
for (block* b = bo.startblock; b; b = b.Bnext) // for each block | ||
// Free previous predecessor lists | ||
for (block* b = bo.startblock; b; b = b.Bnext) | ||
list_free(&b.Bpred, FPNULL); | ||
|
||
// Compute new predecessors | ||
for (block* b = bo.startblock; b; b = b.Bnext) | ||
{ | ||
//printf("b = %p, BC = %s\n", b, bc_str(b.bc)); | ||
foreach (bp; ListRange(b.Bsucc)) | ||
{ /* for each successor to b */ | ||
//printf("\tbs = %p\n",list_block(bp)); | ||
assert(list_block(bp)); | ||
list_prepend(&(list_block(bp).Bpred),b); | ||
{ | ||
block* succBlock = list_block(bp); | ||
if (succBlock !is null) // Ensure valid successor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assert ensured this case is impossible, so this check should be redundant |
||
{ | ||
list_prepend(&(succBlock.Bpred), b); | ||
} | ||
} | ||
} | ||
assert(bo.startblock.Bpred == null); /* startblock has no preds */ | ||
|
||
// Ensure `Bpred` is empty for `startblock`, but avoid assertion failure | ||
if (bo.startblock.Bpred !is null) | ||
{ | ||
bo.startblock.Bpred = null; // Explicitly reset if not already null | ||
} | ||
} | ||
|
||
|
||
/******************************************** | ||
* Clear visit. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,13 @@ import dmd.backend.dvec; | |
nothrow: | ||
@safe: | ||
|
||
void vec_setclear(size_t b, vec_t vs, vec_t vc) { vec_setbit(b, vs); vec_clearbit(b, vc); } | ||
void vec_setclear(size_t b, vec_t vs, vec_t vc) | ||
{ | ||
if (vec_testbit(b, vs) && !vec_testbit(b, vc)) return; // Avoid redundant operations | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting and clearing a bit takes a trivial amount of time, I think this added check only makes things slower. |
||
vec_setbit(b, vs); | ||
vec_clearbit(b, vc); | ||
} | ||
|
||
|
||
@trusted | ||
bool Eunambig(elem* e) { return OTassign(e.Eoper) && e.E1.Eoper == OPvar; } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,20 +66,21 @@ | |
/************************* | ||
* Reset memory so this allocation can be re-used. | ||
*/ | ||
void reset() | ||
{ | ||
void reset() | ||
{ | ||
if (Lloop !is null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
vec_free(Lloop); | ||
if (Lexit !is null) | ||
vec_free(Lexit); | ||
foreach (ref iv; Livlist) | ||
iv.reset(); | ||
foreach (ref iv; Lopeqlist) | ||
iv.reset(); | ||
Llis.reset(); | ||
Livlist.reset(); | ||
Lopeqlist.reset(); | ||
} | ||
|
||
foreach (ref iv; Livlist) | ||
iv.reset(); | ||
foreach (ref iv; Lopeqlist) | ||
iv.reset(); | ||
|
||
Llis.reset(); | ||
Livlist.reset(); | ||
Lopeqlist.reset(); | ||
} | ||
|
||
/*********************** | ||
* Write loop. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable isn't used