Repro for variable names affecting CSE

This commit is contained in:
Kamil Śliwak 2023-09-25 18:07:39 +02:00
parent fe1f9c640e
commit 059adba0a1
4 changed files with 184 additions and 0 deletions

View File

@ -0,0 +1,46 @@
{
main(0, 0)
function main(a, b) {
for {} 1 {}
{
if iszero(a) { break }
let mid := avg(a, a)
switch a
case 0 {
a := mid
}
default {
sstore(0, mid)
}
}
}
function avg(x, y) -> var {
// NOTE: Variable names should not affect CSE.
// This should not be optimized differently than name_dependent_cse_bug_part_2.yul.
// `let mid := var` should be present in both or missing in both.
let _1 := add(x, y)
var := add(_1, _1)
}
}
// ====
// EVMVersion: >=shanghai
// ----
// step: fullSuite
//
// {
// {
// let a := 0
// for { } a { }
// {
// let _1 := add(a, a)
// let var := add(_1, _1)
// let mid := var
// switch a
// case 0 { a := var }
// default { sstore(0, mid) }
// }
// }
// }

View File

@ -0,0 +1,47 @@
{
main(0, 0)
function main(a, b) {
for {} 1 {}
{
if iszero(a) { break }
let mid := avg(a, a)
switch a
case 0 {
a := mid
}
default {
sstore(0, mid)
}
}
}
function avg(x, y) -> var {
// NOTE: Variable names should not affect CSE.
// This should not be optimized differently than name_dependent_cse_bug_part_2_pre_shanghai.yul.
// `let mid := var` should be present in both or missing in both.
let _1 := add(x, y)
var := add(_1, _1)
}
}
// ====
// EVMVersion: <shanghai
// ----
// step: fullSuite
//
// {
// {
// let a := 0
// let a_1 := 0
// for { } a_1 { }
// {
// let _1 := add(a_1, a_1)
// let var := add(_1, _1)
// let mid := var
// switch a_1
// case 0 { a_1 := var }
// default { sstore(a, mid) }
// }
// }
// }

View File

@ -0,0 +1,45 @@
{
main(0, 0)
function main(a, b) {
for {} 1 {}
{
if iszero(a) { break }
let mid := avg(a, a)
switch a
case 0 {
a := mid
}
default {
sstore(0, mid)
}
}
}
function avg(x, y) -> var {
// NOTE: Variable names should not affect CSE.
// This should not be optimized differently than name_dependent_cse_bug_part_1.yul.
// `let mid := var` should be present in both or missing in both.
let _2 := add(x, y)
var := add(_2, _2)
}
}
// ====
// EVMVersion: >=shanghai
// ----
// step: fullSuite
//
// {
// {
// let a := 0
// for { } a { }
// {
// let _1 := add(a, a)
// let var := add(_1, _1)
// switch a
// case 0 { a := var }
// default { sstore(0, var) }
// }
// }
// }

View File

@ -0,0 +1,46 @@
{
main(0, 0)
function main(a, b) {
for {} 1 {}
{
if iszero(a) { break }
let mid := avg(a, a)
switch a
case 0 {
a := mid
}
default {
sstore(0, mid)
}
}
}
function avg(x, y) -> var {
// NOTE: Variable names should not affect CSE.
// This should not be optimized differently than name_dependent_cse_bug_part_1_pre_shanghai.yul.
// `let mid := var` should be present in both or missing in both.
let _2 := add(x, y)
var := add(_2, _2)
}
}
// ====
// EVMVersion: <shanghai
// ----
// step: fullSuite
//
// {
// {
// let a := 0
// let a_1 := 0
// for { } a_1 { }
// {
// let _1 := add(a_1, a_1)
// let var := add(_1, _1)
// switch a_1
// case 0 { a_1 := var }
// default { sstore(a, var) }
// }
// }
// }