Skip to content

Commit

Permalink
Merge pull request #646 from egraphs-good/peggy-benchmark
Browse files Browse the repository at this point in the history
Add brils for peggy comparison
  • Loading branch information
yihozhang authored Oct 31, 2024
2 parents ebff12b + ccdd0bb commit 284ac93
Show file tree
Hide file tree
Showing 34 changed files with 1,242 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/failing/peggy_comparison/infinite_loop.bril
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;
}
33 changes: 33 additions & 0 deletions tests/passing/small/peggy_comparison/branch_hoisting.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ARGS: 0
@main(n: 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:
print x;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ARGS: 4
@main(x: 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;
}
20 changes: 20 additions & 0 deletions tests/passing/small/peggy_comparison/dead_loop_deletion.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@main {
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;

print j;
}
13 changes: 13 additions & 0 deletions tests/passing/small/peggy_comparison/if_true.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ARGS: 20
@main(x: int) {
cond: bool = const true;
br cond .thn .els;

.thn:
print x;

.els:
one: int = const 1;
res: int = sub x one;
print res;
}
19 changes: 19 additions & 0 deletions tests/passing/small/peggy_comparison/loop_based_code_motion.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@main {
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;

print x;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ARGS: 30 10
@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:
}
19 changes: 19 additions & 0 deletions tests/passing/small/peggy_comparison/loop_peeling.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ARGS: 5
@main(n: 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:
print x;
}
21 changes: 21 additions & 0 deletions tests/passing/small/peggy_comparison/loop_strength_reduction.bril
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:
}
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:
}
15 changes: 15 additions & 0 deletions tests/passing/small/peggy_comparison/loop_unroll.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@main {
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:
print i;
}
28 changes: 28 additions & 0 deletions tests/passing/small/peggy_comparison/simple_loop_unswitch.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ARGS: 40
@main(n: 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:
print j;
}
64 changes: 64 additions & 0 deletions tests/snapshots/files__branch_hoisting-optimize-sequential.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
source: tests/files.rs
expression: visualization.result
---
# ARGS: 0
@main(v0: int) {
.b1_:
c2_: int = const 0;
c3_: int = const 500;
v4_: int = id c2_;
v5_: int = id c2_;
v6_: int = id v0;
v7_: int = id c2_;
v8_: int = id c3_;
.b9_:
v10_: bool = lt v5_ v8_;
v11_: int = id v4_;
v12_: int = id v5_;
v13_: int = id v6_;
v14_: int = id v7_;
v15_: int = id v8_;
br v10_ .b16_ .b17_;
.b16_:
v18_: bool = eq v6_ v7_;
c19_: int = const 2;
br v18_ .b20_ .b21_;
.b20_:
v22_: int = mul c19_ v5_;
v23_: int = id v22_;
v24_: int = id v5_;
v25_: int = id v6_;
v26_: int = id v6_;
v27_: int = id v8_;
.b28_:
c29_: int = const 1;
v30_: int = add c29_ v5_;
v11_: int = id v23_;
v12_: int = id v30_;
v13_: int = id v6_;
v14_: int = id v7_;
v15_: int = id v8_;
v4_: int = id v11_;
v5_: int = id v12_;
v6_: int = id v13_;
v7_: int = id v14_;
v8_: int = id v15_;
jmp .b9_;
.b21_:
c31_: int = const 3;
v32_: int = mul c31_ v5_;
v23_: int = id v32_;
v24_: int = id v5_;
v25_: int = id v6_;
v26_: int = id v7_;
v27_: int = id v8_;
jmp .b28_;
.b17_:
v4_: int = id v11_;
v5_: int = id v12_;
v6_: int = id v13_;
v7_: int = id v14_;
v8_: int = id v15_;
print v4_;
}
Loading

0 comments on commit 284ac93

Please sign in to comment.