Skip to content

Commit

Permalink
unary_uses_operand test case
Browse files Browse the repository at this point in the history
  • Loading branch information
nlsandler committed Mar 28, 2024
1 parent 97375e2 commit d089a24
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion expected_results.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions test_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@
"chapter_20/int_only/no_coalescing/unary_interference.c": [
"chapter_20/libraries/util.c"
],
"chapter_20/int_only/no_coalescing/unary_uses_operand.c": [
"chapter_20/libraries/util.c"
],
"chapter_20/all_types/no_coalescing/track_dbl_arg_registers.c": [
"chapter_20/libraries/track_dbl_arg_registers_lib.c"
],
Expand Down
44 changes: 44 additions & 0 deletions tests/chapter_20/int_only/no_coalescing/unary_uses_operand.c
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 tests/chapter_20/int_only/with_coalescing/unary_generates_dst.c

This file was deleted.

0 comments on commit d089a24

Please sign in to comment.