-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathoptimizable.edge
More file actions
41 lines (36 loc) · 1.01 KB
/
Copy pathoptimizable.edge
File metadata and controls
41 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// optimizable.edge — Contract with clear optimization opportunities
//
// This contract deliberately includes patterns that the egglog optimizer
// should simplify:
// - x + 0, x * 1, x * 0 (identity/zero folding)
// - Constant arithmetic (constant folding)
// - Redundant operations (double negation)
abi IOptimizable {
fn get() -> (u256);
fn compute(x: u256) -> (u256);
fn zero(x: u256) -> (u256);
}
contract Optimizable {
let value: &s u256;
// Return the storage value (baseline, no optimization opportunity)
pub fn get() -> (u256) {
return value;
}
// Compute with several optimizable patterns:
// (x + 0) * 1 + (2 + 3)
// Should simplify to: x + 5
pub fn compute(x: u256) -> (u256) {
let a: u256;
let b: u256;
let c: u256;
a = x + 0;
b = a * 1;
c = b + 2 + 3;
return c;
}
// x * 0 should fold to 0
pub fn zero(x: u256) -> (u256) {
let r: u256 = x * 0;
return r;
}
}