-
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.
- Loading branch information
Showing
4 changed files
with
48 additions
and
31 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
44 changes: 44 additions & 0 deletions
44
tests/chapter_20/int_only/no_coalescing/unary_uses_operand.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,44 @@ | ||
/* Test that we recognize that a unary instruction uses its operand; | ||
* i.e. negl %a makes a live. Don't inspect assembly, just validate behavior. | ||
* NOTE: only works as intended after we've implemented register coalescing. | ||
* TODO consider using a common template for this and bin_uses_operand | ||
* */ | ||
|
||
#include "util.h" | ||
|
||
int glob = 1; | ||
|
||
int target(void) { | ||
int a = 0; | ||
|
||
// wrap this in an if statement so we can't copy prop temporary result of | ||
// id(100) into uses of a below | ||
if (id(1)) { | ||
a = id(100); | ||
} | ||
|
||
// wrap this in if statement so we can't copy prop temporary values | ||
// into check_one_int calls below | ||
if (id(1)) { | ||
// this addition becomes: | ||
// movl %a, %tmp | ||
// addl %glob, %tmp | ||
// movl %tmp, %glob | ||
// so we'll coalesce a & tmp unless we recognize that a is still live, | ||
// which requires us to realize that neg instruction below doesn't kill | ||
// it | ||
glob = a + glob; | ||
|
||
// First round of coalescing will coalesce a with temporary | ||
// variable holding result of negation, so this will be: | ||
// negl %a | ||
// so we need to recognize that this negl instruction uses a | ||
a = -a; | ||
} | ||
check_one_int(a, -100); | ||
check_one_int(glob, 101); | ||
} | ||
|
||
int main(void) { | ||
return target(); | ||
} |
30 changes: 0 additions & 30 deletions
30
tests/chapter_20/int_only/with_coalescing/unary_generates_dst.c
This file was deleted.
Oops, something went wrong.