diff options
| author | Michael Matz <matz@suse.de> | 2016-09-19 18:38:12 +0200 |
|---|---|---|
| committer | Michael Matz <matz@suse.de> | 2016-12-15 17:47:12 +0100 |
| commit | 31c7ea0165882eaf09040ea7edfc37cc38f0a032 (patch) | |
| tree | d1dad07537700b756d612c68b414d243202a9529 /tests/tcctest.c | |
| parent | b303a00ce01876dfa2ba3fe532db04d200168b9d (diff) | |
| download | tinycc-31c7ea0165882eaf09040ea7edfc37cc38f0a032.tar.gz tinycc-31c7ea0165882eaf09040ea7edfc37cc38f0a032.tar.bz2 | |
opt: Start optimizing dead code a bit
If a condition is always zero/non-zero we can omit the
then or else code. This is complicated a bit by having to
deal with labels that might make such code reachable without
us yet knowing during parsing.
Diffstat (limited to 'tests/tcctest.c')
| -rw-r--r-- | tests/tcctest.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/tcctest.c b/tests/tcctest.c index d1f6c9b..8031af4 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -88,6 +88,7 @@ void struct_test(); void array_test(); void expr_ptr_test(); void bool_test(); +void optimize_out(); void expr2_test(); void constant_expr_test(); void expr_cmp_test(); @@ -695,6 +696,7 @@ int main(int argc, char **argv) array_test(); expr_ptr_test(); bool_test(); + optimize_out(); expr2_test(); constant_expr_test(); expr_cmp_test(); @@ -1165,6 +1167,31 @@ void bool_test() printf ("bits = 0x%x\n", calc_vm_flags (0x1)); } +extern int undefined_function(void); +extern int defined_function(void); + +void optimize_out(void) +{ + int i = 0 ? undefined_function() : defined_function(); + printf ("oo:%d\n", i); + int j = 1 ? defined_function() : undefined_function(); + printf ("oo:%d\n", j); + if (0) + printf("oo:%d\n", undefined_function()); + else + printf("oo:%d\n", defined_function()); + if (1) + printf("oo:%d\n", defined_function()); + else + printf("oo:%d\n", undefined_function()); +} + +int defined_function(void) +{ + static int i = 40; + return i++; +} + /* GCC accepts that */ static int tab_reinit[]; static int tab_reinit[10]; |
