Skip to content

Commit

Permalink
optimization pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Aug 6, 2011
1 parent c75ccdd commit ffcae90
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
30 changes: 30 additions & 0 deletions src/backend/cgelem.c
Expand Up @@ -1398,6 +1398,36 @@ STATIC elem *elor(elem *e)
return elbitwise(e);
}

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

STATIC elem *elxor(elem *e)
{
if (OPTIMIZER)
{
elem *e1 = e->E1;
elem *e2 = e->E2;

/* Recognize:
* (a & c) ^ (b & c) => (a ^ b) & c
*/
if (e1->Eoper == OPand && e2->Eoper == OPand &&
el_match5(e1->E2, e2->E2) &&
(e2->E2->Eoper == OPconst || (!el_sideeffect(e2->E1) && !el_sideeffect(e2->E2))))
{
el_free(e1->E2);
e1->E2 = e2->E1;
e1->Eoper = OPxor;
e->Eoper = OPand;
e->E2 = e2->E2;
e2->E1 = NULL;
e2->E2 = NULL;
el_free(e2);
return optelem(e, TRUE);
}
}
return elbitwise(e);
}

/**************************
* Optimize nots.
Expand Down
8 changes: 4 additions & 4 deletions src/backend/optabgen.c
@@ -1,5 +1,5 @@
// Copyright (C) 1985-1998 by Symantec
// Copyright (C) 2000-2009 by Digital Mars
// Copyright (C) 2000-2011 by Digital Mars
// All Rights Reserved
// http://www.digitalmars.com
// Written by Walter Bright
Expand Down Expand Up @@ -428,7 +428,7 @@ void dotab()
case OPremquo: X("/%", elremquo, cdmul);
case OPdiv: X("/", eldiv, cdmul);
case OPmod: X("%", elmod, cdmul);
case OPxor: X("^", elbitwise,cdorth);
case OPxor: X("^", elxor, cdorth);
case OPvptrfptr: X("vptrfptr", elvptrfptr,cdcnvt);
case OPcvptrfptr: X("cvptrfptr", elvptrfptr,cdcnvt);
case OPstring: X("string", elstring,cderr);
Expand Down Expand Up @@ -805,7 +805,7 @@ void dotytab()
"wchar_t", TYwchar_t, TYwchar_t, TYint, SHORTSIZE, 0x85,0x71,
"unsigned short",TYushort, TYushort, TYint, SHORTSIZE, 0x85,0x21,

// These values are adjusted for 32 bit ints in cv_init() and util_set386()
// These values are adjusted for 32 bit ints in cv_init() and util_set32()
"enum", TYenum, TYuint, TYint, -1, 0x81,0x72,
"int", TYint, TYuint, TYint, 2, 0x81,0x72,
"unsigned", TYuint, TYuint, TYint, 2, 0x85,0x73,
Expand Down Expand Up @@ -1014,7 +1014,7 @@ void dotytab()
_tyequiv[i] = i;
_tyequiv[TYchar] = TYschar; /* chars are signed by default */

// These values are adjusted in util_set386() for 32 bit ints
// These values are adjusted in util_set32() for 32 bit ints
_tyequiv[TYint] = TYshort;
_tyequiv[TYuint] = TYushort;

Expand Down

0 comments on commit ffcae90

Please sign in to comment.