Skip to content

Commit

Permalink
Merge pull request #6529 from UplinkCoder/fix_elshl
Browse files Browse the repository at this point in the history
fix Issue 17168 - refactor elshl
  • Loading branch information
MartinNowak authored Feb 11, 2017
2 parents 9c4e2bd + 480501e commit 7b48c5b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/backend/cgelem.c
Original file line number Diff line number Diff line change
Expand Up @@ -4571,15 +4571,19 @@ STATIC elem *elu64_d(elem *e, goal_t goal)

STATIC elem *elshl(elem *e, goal_t goal)
{
if (e->E1->Eoper == OPconst && !boolres(e->E1)) // if e1 is 0
{ e->E1->Ety = e->Ety;
tym_t ty = e->Ety;
elem *e1 = e->E1;
elem *e2 = e->E2;

if (e1->Eoper == OPconst && !boolres(e1)) // if e1 is 0
{ e1->Ety = ty;
e = el_selecte1(e); // (0 << e2) => 0
}
if (OPTIMIZER &&
e->E2->Eoper == OPconst &&
(e->E1->Eoper == OPshr || e->E1->Eoper == OPashr) &&
e->E1->E2->Eoper == OPconst &&
el_tolong(e->E2) == el_tolong(e->E1->E2))
else if (OPTIMIZER &&
e2->Eoper == OPconst &&
(e1->Eoper == OPshr || e1->Eoper == OPashr) &&
e1->E2->Eoper == OPconst &&
el_tolong(e2) == el_tolong(e1->E2))
{ /* Rewrite:
* (x >> c) << c)
* with:
Expand Down
4 changes: 4 additions & 0 deletions test/compilable/test17168.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// REQUIRED_ARGS: -O
// PERMUTE_ARGS:

void fn(uint x){uint a = 0 << x;}

0 comments on commit 7b48c5b

Please sign in to comment.