History

Improve constant propagation with "&&" and "||".

Edmund Grimley Evans committed 10 years ago

Commit 3ff77a11 parent c7067ae3 files · +58 −52Browse files

Unified · Split

3 files
  1. TODO +0 −1
  2. tccgen.c +53 −50
  3. tests/tests2/78_vla_label.c +5 −1
TODO+0−1
@@ -68,7 +68,6 @@ Not critical: · 67 unmodified lines
68 to suppress VT_LOCAL and use a base register instead).68 to suppress VT_LOCAL and use a base register instead).
69- interactive mode / integrated debugger69- interactive mode / integrated debugger
70- fix preprocessor symbol redefinition70- fix preprocessor symbol redefinition
71- better constant opt (&&, ||, ?:)
72- add portable byte code generator and interpreter for other71- add portable byte code generator and interpreter for other
73 unsupported architectures.72 unsupported architectures.
74- C++: variable declaration in for, minimal 'class' support.73- C++: variable declaration in for, minimal 'class' support.
tccgen.c+53−50
@@ -4453,80 +4453,83 @@ static void expr_or(void) · 4452 unmodified lines
4453 }4453 }
4454}4454}
4455 4455
4456/* XXX: fix this mess */
4457static void expr_land_const(void)
4458{
4459 expr_or();
4460 while (tok == TOK_LAND) {
4461 next();
4462 expr_or();
4463 gen_op(TOK_LAND);
4464 }
4465}
4466
4467/* XXX: fix this mess */
4468static void expr_lor_const(void)
4469{
4470 expr_land_const();
4471 while (tok == TOK_LOR) {
4472 next();
4473 expr_land_const();
4474 gen_op(TOK_LOR);
4475 }
4476}
4477
4478/* only used if non constant */
4479static void expr_land(void)4456static void expr_land(void)
4480{4457{
4481 int t;
4482
4483 expr_or();4458 expr_or();
4484 if (tok == TOK_LAND) {4459 if (tok == TOK_LAND) {
4485 t = 0;4460 if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
4486 save_regs(1);4461 CType ctb, cti;
4487 for(;;) {4462 ctb.t = VT_BOOL;
4488 t = gvtst(1, t);4463 cti.t = VT_INT;
4489 if (tok != TOK_LAND) {
4490 vseti(VT_JMPI, t);
4491 break;
4492 }
4493 next();4464 next();
4494 expr_or();4465 gen_cast(&ctb);
4466 if (vtop->c.i) {
4467 vpop();
4468 expr_land();
4469 gen_cast(&ctb);
4470 } else {
4471 expr_land();
4472 vpop();
4473 }
4474 gen_cast(&cti);
4475 } else {
4476 int t = 0;
4477 save_regs(1);
4478 for(;;) {
4479 t = gvtst(1, t);
4480 if (tok != TOK_LAND) {
4481 vseti(VT_JMPI, t);
4482 break;
4483 }
4484 next();
4485 expr_or();
4486 }
4495 }4487 }
4496 }4488 }
4497}4489}
4498 4490
4499static void expr_lor(void)4491static void expr_lor(void)
4500{4492{
4501 int t;
4502
4503 expr_land();4493 expr_land();
4504 if (tok == TOK_LOR) {4494 if (tok == TOK_LOR) {
4505 t = 0;4495 if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
4506 save_regs(1);4496 CType ctb, cti;
4507 for(;;) {4497 ctb.t = VT_BOOL;
4508 t = gvtst(0, t);4498 cti.t = VT_INT;
4509 if (tok != TOK_LOR) {
4510 vseti(VT_JMP, t);
4511 break;
4512 }
4513 next();4499 next();
4514 expr_land();4500 gen_cast(&ctb);
4501 if (vtop->c.i) {
4502 expr_lor();
4503 vpop();
4504 } else {
4505 vpop();
4506 expr_lor();
4507 gen_cast(&ctb);
4508 }
4509 gen_cast(&cti);
4510 } else {
4511 int t = 0;
4512 save_regs(1);
4513 for(;;) {
4514 t = gvtst(0, t);
4515 if (tok != TOK_LOR) {
4516 vseti(VT_JMP, t);
4517 break;
4518 }
4519 next();
4520 expr_land();
4521 }
4515 }4522 }
4516 }4523 }
4517}4524}
4518 4525
4519/* XXX: better constant handling */
4520static void expr_cond(void)4526static void expr_cond(void)
4521{4527{
4522 int tt, u, r1, r2, rc, t1, t2, bt1, bt2;4528 int tt, u, r1, r2, rc, t1, t2, bt1, bt2;
4523 SValue sv;4529 SValue sv;
4524 CType type, type1, type2;4530 CType type, type1, type2;
4525 4531
4526 if (const_wanted)4532 expr_lor();
4527 expr_lor_const();
4528 else
4529 expr_lor();
4530 if (tok == '?') {4533 if (tok == '?') {
4531 next();4534 next();
4532 if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {4535 if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
tests/tests2/78_vla_label.c+5−1
@@ -17,9 +17,13 @@ void f2(void) · 16 unmodified lines
17{17{
18 goto start;18 goto start;
19 {19 {
20 int a[1 ? 1 : 1]; /* not a variable-length array */20 int a[1 && 1]; /* not a variable-length array */
21 int b[1 || 1]; /* not a variable-length array */
22 int c[1 ? 1 : 1]; /* not a variable-length array */
21 start:23 start:
22 a[0] = 0;24 a[0] = 0;
25 b[0] = 0;
26 c[0] = 0;
23 }27 }
24}28}
25 29

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t