forked from sampsyo/bril
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes Issue sampsyo#108. The optimization in prune_phis() is not sound. phi nodes that are "partially undefined" cannot be removed. It is only illegal to read from the result if the second to last executed label corresponds to an undefined argument. `to_ssa.py` generated incorrect code for the two tests added, before the fix. In most cases, these phi nodes aren't read from, and will be removed by DCE. However, in the case where the phi nodes are read, a correct optimization would be: 1. Detect partially undefined phi nodes whose value is always used. Let `undefined_labels` be the set of labels whose argument is undefined. 2. Leverage the undefined behavior to say that `undefined_labels` are in fact not predecessors to the basic block. `preds = preds - undefined_labels`. Though, I'm not sure how useful that optimization would be in practice.
- Loading branch information
Showing
8 changed files
with
72 additions
and
38 deletions.
There are no files selected for viewing
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,14 @@ | ||
@main() { | ||
cond: bool = const true; | ||
br cond .true .false; | ||
.true: | ||
a: int = const 0; | ||
jmp .zexit; | ||
.false: | ||
b: int = const 1; | ||
jmp .zexit; | ||
# zexit to trigger a bug in to_ssa.py that depends on | ||
# the order that basic blocks get renamed. | ||
.zexit: | ||
print a; | ||
} |
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,16 @@ | ||
@main { | ||
.b1: | ||
cond.0: bool = const true; | ||
br cond.0 .true .false; | ||
.true: | ||
a.0: int = const 0; | ||
jmp .zexit; | ||
.false: | ||
b.0: int = const 1; | ||
jmp .zexit; | ||
.zexit: | ||
b.1: int = phi b.0 b.0 .false .true; | ||
a.1: int = phi __undefined a.0 .false .true; | ||
print a.1; | ||
ret; | ||
} |
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,16 @@ | ||
@main(cond: bool) { | ||
.entry: | ||
a.1: int = const 47; | ||
br cond .left .right; | ||
.left: | ||
a.2: int = add a.1 a.1; | ||
jmp .zexit; | ||
.right: | ||
a.3: int = mul a.1 a.1; | ||
jmp .zexit; | ||
# zexit to trigger a bug in to_ssa.py that depends on | ||
# the order that basic blocks get renamed. | ||
.zexit: | ||
a.4: int = phi .left a.2 .right a.3; | ||
print a.4; | ||
} |
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 @@ | ||
@main(cond: bool) { | ||
.entry: | ||
a.1.0: int = const 47; | ||
br cond .left .right; | ||
.left: | ||
a.2.0: int = add a.1.0 a.1.0; | ||
jmp .zexit; | ||
.right: | ||
a.3.0: int = mul a.1.0 a.1.0; | ||
jmp .zexit; | ||
.zexit: | ||
a.3.1: int = phi __undefined a.3.0 .left .right; | ||
a.2.1: int = phi a.2.0 a.2.0 .left .right; | ||
a.4.0: int = phi a.2.1 a.3.1 .left .right; | ||
print a.4.0; | ||
ret; | ||
} |
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