Skip to content

Commit ab9729b

Browse files
committed
Repro for variable names affecting CSE
1 parent 93ea888 commit ab9729b

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
main(0, 0)
3+
4+
function main(a, b) {
5+
for {} 1 {}
6+
{
7+
if iszero(a) { break }
8+
9+
let mid := avg(a, a)
10+
switch a
11+
case 0 {
12+
a := mid
13+
}
14+
default {
15+
sstore(0, mid)
16+
}
17+
}
18+
}
19+
20+
function avg(x, y) -> var {
21+
// NOTE: Variable names should not affect CSE.
22+
// This should not be optimized differently than name_dependent_cse_bug_part_2.yul.
23+
// `let mid := var` should be present in both or missing in both.
24+
let _1 := add(x, y)
25+
var := add(_1, _1)
26+
}
27+
}
28+
// ====
29+
// EVMVersion: >=shanghai
30+
// ----
31+
// step: fullSuite
32+
//
33+
// {
34+
// {
35+
// let a := 0
36+
// for { } a { }
37+
// {
38+
// let _1 := add(a, a)
39+
// let var := add(_1, _1)
40+
// let mid := var
41+
// switch a
42+
// case 0 { a := var }
43+
// default { sstore(0, mid) }
44+
// }
45+
// }
46+
// }
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
main(0, 0)
3+
4+
function main(a, b) {
5+
for {} 1 {}
6+
{
7+
if iszero(a) { break }
8+
9+
let mid := avg(a, a)
10+
switch a
11+
case 0 {
12+
a := mid
13+
}
14+
default {
15+
sstore(0, mid)
16+
}
17+
}
18+
}
19+
20+
function avg(x, y) -> var {
21+
// NOTE: Variable names should not affect CSE.
22+
// This should not be optimized differently than name_dependent_cse_bug_part_2_pre_shanghai.yul.
23+
// `let mid := var` should be present in both or missing in both.
24+
let _1 := add(x, y)
25+
var := add(_1, _1)
26+
}
27+
}
28+
// ====
29+
// EVMVersion: <shanghai
30+
// ----
31+
// step: fullSuite
32+
//
33+
// {
34+
// {
35+
// let a := 0
36+
// let a_1 := 0
37+
// for { } a_1 { }
38+
// {
39+
// let _1 := add(a_1, a_1)
40+
// let var := add(_1, _1)
41+
// let mid := var
42+
// switch a_1
43+
// case 0 { a_1 := var }
44+
// default { sstore(a, mid) }
45+
// }
46+
// }
47+
// }
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
main(0, 0)
3+
4+
function main(a, b) {
5+
for {} 1 {}
6+
{
7+
if iszero(a) { break }
8+
9+
let mid := avg(a, a)
10+
switch a
11+
case 0 {
12+
a := mid
13+
}
14+
default {
15+
sstore(0, mid)
16+
}
17+
}
18+
}
19+
20+
function avg(x, y) -> var {
21+
// NOTE: Variable names should not affect CSE.
22+
// This should not be optimized differently than name_dependent_cse_bug_part_1.yul.
23+
// `let mid := var` should be present in both or missing in both.
24+
let _2 := add(x, y)
25+
var := add(_2, _2)
26+
}
27+
}
28+
// ====
29+
// EVMVersion: >=shanghai
30+
// ----
31+
// step: fullSuite
32+
//
33+
// {
34+
// {
35+
// let a := 0
36+
// for { } a { }
37+
// {
38+
// let _1 := add(a, a)
39+
// let var := add(_1, _1)
40+
// switch a
41+
// case 0 { a := var }
42+
// default { sstore(0, var) }
43+
// }
44+
// }
45+
// }
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
main(0, 0)
3+
4+
function main(a, b) {
5+
for {} 1 {}
6+
{
7+
if iszero(a) { break }
8+
9+
let mid := avg(a, a)
10+
switch a
11+
case 0 {
12+
a := mid
13+
}
14+
default {
15+
sstore(0, mid)
16+
}
17+
}
18+
}
19+
20+
function avg(x, y) -> var {
21+
// NOTE: Variable names should not affect CSE.
22+
// This should not be optimized differently than name_dependent_cse_bug_part_1_pre_shanghai.yul.
23+
// `let mid := var` should be present in both or missing in both.
24+
let _2 := add(x, y)
25+
var := add(_2, _2)
26+
}
27+
}
28+
// ====
29+
// EVMVersion: <shanghai
30+
// ----
31+
// step: fullSuite
32+
//
33+
// {
34+
// {
35+
// let a := 0
36+
// let a_1 := 0
37+
// for { } a_1 { }
38+
// {
39+
// let _1 := add(a_1, a_1)
40+
// let var := add(_1, _1)
41+
// switch a_1
42+
// case 0 { a_1 := var }
43+
// default { sstore(a, var) }
44+
// }
45+
// }
46+
// }

0 commit comments

Comments
 (0)