-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Int-only dead store elimination tests
- Loading branch information
Showing
26 changed files
with
482 additions
and
170 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
To validate that dead stores were eliminated, the test script inspects the assembly for the `target` function. | ||
|
||
In most programs, dead store elimination should remove a `Copy` of the form `var = const`, so the test script just validates that that constant doesn't appear in the program. In a couple of cases (`simple.c`, `delete_arithmetic_ops.c` and `self`), dead store elimination combined with other optimizations should eliminate the whole function body except the `Return` instruction; these are validated the same way as the constant-folding tests. The test cases in the `dont_elim` directories cover cases where stores _shouldn't_ be eliminated. The test script doesn't inspect the assembly for these; it just validates that they behave correctly. |
31 changes: 22 additions & 9 deletions
31
tests/chapter_19/dead_store_elimination/int_only/dead_store_static_var.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
/* Test that we eliminate dead stores to static and global variables */ | ||
|
||
int i = 0; | ||
|
||
int target(int arg) { | ||
static int i; | ||
if (arg < 0) | ||
return i; | ||
i = 5; // this is dead | ||
i = arg; | ||
return i; | ||
i = 5; // dead store | ||
i = arg; | ||
return i + 1; | ||
} | ||
|
||
int main(void) { | ||
int result1 = target(2); | ||
int result2 = target(-1); | ||
return result1 == 2 && result2 == 2; | ||
int result1 = target(2); | ||
if (i != 2) { | ||
return 1; // fail | ||
} | ||
if (result1 != 3) { | ||
return 2; // fail | ||
} | ||
int result2 = target(-1); | ||
if (i != -1) { | ||
return 3; // fail | ||
} | ||
if (result2 != 0) { | ||
return 4; // fail | ||
} | ||
return 0; // success | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/chapter_19/dead_store_elimination/int_only/delete_arithmetic_ops.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* In most of our test cases, the dead store we remove is a Copy. | ||
* This test case validates that we can remove dead | ||
* Binary and Unary instructions too. | ||
* */ | ||
|
||
int a = 1; | ||
int b = 2; | ||
|
||
int target(void) { | ||
// everything except the Return instruction should be optimized away. | ||
int unused = a * -b; | ||
return 5; | ||
} | ||
|
||
int main(void) { | ||
return target(); | ||
} |
17 changes: 12 additions & 5 deletions
17
tests/chapter_19/dead_store_elimination/int_only/dont_elim/add_all_to_worklist.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
/* Make sure we add every basic block to the worklist | ||
* at the start of the iterative algorithm | ||
*/ | ||
int putchar(int c); | ||
|
||
int f(int arg) | ||
{ | ||
int f(int arg) { | ||
int x = 76; | ||
// no live variables going into this basic block, | ||
if (arg < 10) { | ||
// give x multiple values on different paths | ||
// so we can't propagate it | ||
x = 77; | ||
} | ||
// no live variables flow into this basic block from its successor, | ||
// bu we still need to process it to learn that x is live | ||
if (arg) | ||
putchar(x); | ||
return 0; | ||
} | ||
|
||
int main(void) | ||
{ | ||
int main(void) { | ||
f(0); | ||
f(1); | ||
f(11); | ||
return 0; | ||
} |
Oops, something went wrong.