-
Notifications
You must be signed in to change notification settings - Fork 11
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
12 changed files
with
268 additions
and
0 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,33 @@ | ||
# ARGS: 0 | ||
@main(n: int): int { | ||
zero: int = const 0; | ||
x: int = id zero; | ||
y: int = id zero; | ||
fivehundred: int = const 500; | ||
|
||
.pred: | ||
whilecond: bool = lt y fivehundred; | ||
br whilecond .loopbody .end; | ||
|
||
.loopbody: | ||
two: int = const 2; | ||
ifcond: bool = eq n zero; | ||
br ifcond .thn .els; | ||
|
||
.thn: | ||
x: int = mul y two; | ||
jmp .ifend; | ||
|
||
.els: | ||
three: int = const 3; | ||
x: int = mul y three; | ||
|
||
.ifend: | ||
one: int = const 1; | ||
y: int = add one y; | ||
|
||
jmp .pred; | ||
|
||
.end: | ||
ret x; | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/passing/peggy_comparison/conditional_constant_folding.bril
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,29 @@ | ||
# ARGS: 4 | ||
@main(x: int): int { | ||
five: int = const 5; | ||
four: int = const 4; | ||
twenty: int = const 20; | ||
cond: bool = eq x five; | ||
br cond .if .else_if_check; | ||
|
||
.if: | ||
res: int = mul four x; | ||
jmp .end; | ||
|
||
.else_if_check: | ||
cond: bool = eq x four; | ||
br cond .else_if .else; | ||
jmp .end; | ||
|
||
.else_if: | ||
res: int = mul five x; | ||
jmp .end; | ||
|
||
.else: | ||
res: int = id twenty; | ||
jmp .end; | ||
|
||
.end: | ||
print res; | ||
ret res; | ||
} |
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,20 @@ | ||
@main(): int { | ||
j: int = const 3; | ||
i: int = const 0; | ||
forty: int = const 40; | ||
one: int = const 1; | ||
|
||
.loop_test: | ||
cond: bool = lt i forty; | ||
br cond .loop_body .loop_end; | ||
|
||
.loop_body: | ||
j: int = add j one; | ||
i: int = add i one; | ||
jmp .loop_test; | ||
|
||
.loop_end: | ||
j: int = const 2; | ||
|
||
ret j; | ||
} |
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,12 @@ | ||
@main(x: int): int { | ||
cond: bool = const true; | ||
br cond .thn .els; | ||
|
||
.thn: | ||
ret x; | ||
|
||
.els: | ||
one: int = const 1; | ||
res: int = sub x one; | ||
ret res; | ||
} |
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: int { | ||
five: int = const 5; | ||
one: int = const 1; | ||
j: int = const 0; | ||
i: int = id five; | ||
|
||
.loop_test: | ||
cond: bool = eq i five; | ||
br cond .loop_body .loop_end; | ||
|
||
.loop_body: | ||
j: int = add one j; | ||
jmp .loop_test; | ||
|
||
.loop_end: | ||
ret j; | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/passing/peggy_comparison/loop_based_code_motion.bril
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,19 @@ | ||
@main: int { | ||
x: int = const 0; | ||
three: int = const 3; | ||
|
||
.loop_test: | ||
cond: bool = lt x three; | ||
br cond .loop_body .loop_end; | ||
|
||
.loop_body: | ||
one: int = const 1; | ||
x: int = add x one; | ||
jmp .loop_test; | ||
|
||
.loop_end: | ||
five: int = const 5; | ||
x: int = mul x five; | ||
|
||
ret x; | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/passing/peggy_comparison/loop_invariant_code_motion.bril
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,25 @@ | ||
@main(n: int, m: int) { | ||
i: int = const 0; | ||
twenty: int = const 20; | ||
one: int = const 1; | ||
|
||
.loop_test: | ||
cond: bool = lt i twenty; | ||
br cond .loop_body .loop_end; | ||
|
||
.loop_body: | ||
j: int = mul n twenty; | ||
if_cond: bool = lt j m; | ||
br if_cond .thn .end_if; | ||
|
||
.thn: | ||
j: int = add j one; | ||
|
||
.end_if: | ||
output: int = mul i j; | ||
print output; | ||
i: int = add i one; | ||
jmp .loop_test; | ||
|
||
.loop_end: | ||
} |
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,18 @@ | ||
@main(n: int): int { | ||
x: int = const 0; | ||
i: int = const 0; | ||
|
||
.loop_test: | ||
cond: bool = lt i n; | ||
br cond .loop_body .loop_end; | ||
|
||
.loop_body: | ||
five: int = const 5; | ||
one: int = const 1; | ||
x: int = add x five; | ||
i: int = add i one; | ||
jmp .loop_test; | ||
|
||
.loop_end: | ||
ret x; | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/passing/peggy_comparison/loop_strength_reduction.bril
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,21 @@ | ||
@main { | ||
i: int = const 0; | ||
d: int = const 0; | ||
three_hundred: int = const 300; | ||
five: int = const 5; | ||
one: int = const 1; | ||
|
||
.loop_test: | ||
cond: bool = lt d three_hundred; | ||
br cond .loop_body .loop_end; | ||
|
||
.loop_body: | ||
out: int = mul i five; | ||
print out; | ||
|
||
i: int = add i one; | ||
d: int = add d one; | ||
jmp .loop_test; | ||
|
||
.loop_end: | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/passing/peggy_comparison/loop_strength_reduction_modified.bril
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,31 @@ | ||
@main { | ||
i: int = const 0; | ||
d: int = const 0; | ||
three_hundred: int = const 300; | ||
three: int = const 3; | ||
five: int = const 5; | ||
one: int = const 1; | ||
one_hundred_fifty: int = const 150; | ||
|
||
.loop_test: | ||
cond: bool = lt d three_hundred; | ||
br cond .loop_body .loop_end; | ||
|
||
.loop_body: | ||
out: int = mul i five; | ||
print out; | ||
|
||
i: int = add i one; | ||
if_cond: bool = eq d one_hundred_fifty; | ||
br if_cond .if_then .end_if; | ||
|
||
.if_then: | ||
i: int = add i three; | ||
|
||
.end_if: | ||
d: int = add d one; | ||
|
||
jmp .loop_test; | ||
|
||
.loop_end: | ||
} |
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,15 @@ | ||
@main: int { | ||
i: int = const 0; | ||
one: int = const 1; | ||
|
||
.loop_test: | ||
cond: bool = lt i one; | ||
br cond .loop_body .loop_end; | ||
|
||
.loop_body: | ||
i: int = add one i; | ||
jmp .loop_test; | ||
|
||
.loop_end: | ||
ret i; | ||
} |
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,28 @@ | ||
# ARGS: 40 | ||
@main(n: int): int { | ||
one: int = const 1; | ||
zero: int = const 0; | ||
i: int = id zero; | ||
j: int = id zero; | ||
|
||
.loop_test: | ||
cond: bool = lt i n; | ||
br cond .loop_body .loop_end; | ||
|
||
.loop_body: | ||
print i; | ||
|
||
cond: bool = lt n zero; | ||
br cond .thn .ifend; | ||
|
||
.thn: | ||
j: int = const 2; | ||
|
||
.ifend: | ||
j: int = add one j; | ||
i: int = add one i; | ||
jmp .loop_test; | ||
|
||
.loop_end: | ||
ret j; | ||
} |