Skip to content

Commit

Permalink
Merge pull request #2313 from WalterBright/fix-pull-2299
Browse files Browse the repository at this point in the history
fix & test for pull 2299 regression
  • Loading branch information
braddr committed Jul 8, 2013
2 parents d895e4e + fd99980 commit fac723b
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/backend/cgelem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2406,7 +2406,6 @@ STATIC bool optim_oror(elem **pe)
// Delete all the || nodes that are no longer referenced
el_opFree(e, OPoror);

unsigned tyc = array[first]->E1->Ety;
if (emax < 32) // if everything fits in a 32 bit register
emin = 0; // no need for bias

Expand All @@ -2427,12 +2426,19 @@ STATIC bool optim_oror(elem **pe)
//printf("n = %d, count = %d, min = %d, max = %d\n", (int)n, last - first + 1, (int)emin, (int)emax);
//printf("bits = x%llx\n", bits);

unsigned tyc = array[first]->E1->Ety;

elem *ex = el_bin(OPmin,tyc,array[first]->E1,el_long(tyc,emin));
ex = el_bin(OPle,TYbool,ex,el_long(touns(tyc),emax - emin));
elem *ey = el_bin(OPmin,tyc,array[first + 1]->E1,el_long(tyc,emin));
#if 1
ey = el_bin(OPbtst,TYbool,el_long(tyc,bits),ey);
#else

tym_t tybits = TYuint;
if ((emax - emin) >= 32)
{
assert(I64); // need 64 bit BT
tybits = TYullong;
}

// Shift count must be an int
switch (tysize(tyc))
{
Expand All @@ -2449,8 +2455,11 @@ STATIC bool optim_oror(elem **pe)
default:
assert(0);
}
ey = el_bin(OPshl,tyc,el_long(tyc,1),ey);
ey = el_bin(OPand,tyc,ey,el_long(tyc,bits));
#if 1
ey = el_bin(OPbtst,TYbool,el_long(tybits,bits),ey);
#else
ey = el_bin(OPshl,tybits,el_long(tybits,1),ey);
ey = el_bin(OPand,tybits,ey,el_long(tybits,bits));
#endif
ex = el_bin(OPandand,ty,ex,ey);

Expand Down
76 changes: 76 additions & 0 deletions test/runnable/mars1.d
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,80 @@ void testnegcom()
assert(com2(3) == -4);
}

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

int oror1(char c)
{
return ((((((((((cast(int) c <= 32 || cast(int) c == 46) || cast(int) c == 44)
|| cast(int) c == 58) || cast(int) c == 59) || cast(int) c == 60)
|| cast(int) c == 62) || cast(int) c == 34) || cast(int) c == 92)
|| cast(int) c == 39) != 0);
}

int oror2(char c)
{
return ((((((((((c <= 32 || c == 46) || c == 44)
|| c == 58) || c == 59) || c == 60)
|| c == 62) || c == 34) || c == 92)
|| c == 39) != 0);
}

void testoror()
{
assert(oror1(0) == 1);
assert(oror1(32) == 1);
assert(oror1(46) == 1);
assert(oror1(44) == 1);
assert(oror1(58) == 1);
assert(oror1(59) == 1);
assert(oror1(60) == 1);
assert(oror1(62) == 1);
assert(oror1(34) == 1);
assert(oror1(92) == 1);
assert(oror1(39) == 1);
assert(oror1(33) == 0);
assert(oror1(61) == 0);
assert(oror1(93) == 0);
assert(oror1(255) == 0);

assert(oror2(0) == 1);
assert(oror2(32) == 1);
assert(oror2(46) == 1);
assert(oror2(44) == 1);
assert(oror2(58) == 1);
assert(oror2(59) == 1);
assert(oror2(60) == 1);
assert(oror2(62) == 1);
assert(oror2(34) == 1);
assert(oror2(92) == 1);
assert(oror2(39) == 1);
assert(oror2(33) == 0);
assert(oror2(61) == 0);
assert(oror2(93) == 0);
assert(oror2(255) == 0);
}

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

bool bt1(int p, int a, int b)
{
return p && ((1 << b) & a);
}

bool bt2(int p, long a, long b)
{
return p && ((1L << b) & a);
}

void testbt()
{
assert(bt1(1,7,2) == 1);
assert(bt1(1,7,3) == 0);

assert(bt2(1,0x7_0000_0000,2+32) == 1);
assert(bt2(1,0x7_0000_0000,3+32) == 0);
}

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

int main()
Expand All @@ -775,6 +849,8 @@ int main()
testfastdiv();
testdocond();
testnegcom();
testoror();
testbt();
printf("Success\n");
return 0;
}

0 comments on commit fac723b

Please sign in to comment.