Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ perf-diff-latest format='md':
alias psh := perf-snapshot-historical
# collect historic gas usages from a snapshot test that has a `forc test` output
[linux]
[macos]
[group('performance')]
perf-snapshot-historical path revision_range='' format='csv' open='':
#!/usr/bin/env bash
Expand Down Expand Up @@ -175,4 +176,4 @@ generate-sway-lib-std:

[group('test')]
test-forc-fmt-check-panic:
cd ./scripts/formatter && ./forc-fmt-check-panic.sh
cd ./scripts/formatter && ./forc-fmt-check-panic.sh
4 changes: 4 additions & 0 deletions sway-ir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ sway-ir-macros.workspace = true
sway-types.workspace = true
sway-utils.workspace = true

[dev-dependencies]
insta.workspace = true
vte.workspace = true

[lints]
workspace = true
36 changes: 36 additions & 0 deletions sway-ir/tests/ccp/ccp1.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
fn test1(p: u64) -> u64 {
entry(p: u64):
v2v1 = const u64 100
v3v1 = cmp eq v2v1 p
cbr v3v1, get_0_block0(), get_0_block1()

get_0_block0():
v5v1 = const u64 1
- v6v1 = add v5v1, p
+ v6v1 = add v5v1, v2v1
ret u64 v6v1

get_0_block1():
v8v1 = const u64 111
v9v1 = add v8v1, p
ret u64 v9v1
}

fn must_not_optimize(p: u64) -> u64 {
entry(p: u64):
v12v1 = const u64 100
v13v1 = cmp eq v12v1 p
cbr v13v1, get_0_block0(), get_0_block0()

get_0_block0():
v15v1 = const u64 1
v16v1 = add v15v1, p
ret u64 v16v1
}
}
23 changes: 23 additions & 0 deletions sway-ir/tests/constants/cbr_cmp_fold.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
fn test1() -> u64 {
entry():
- v1v1 = const bool false
- v2v1 = const bool false
- v3v1 = cmp eq v1v1 v2v1
- cbr v3v1, get_0_block0(), get_0_block1()
+ br get_0_block0()

get_0_block0():
v5v1 = const u64 101
ret u64 v5v1

get_0_block1():
v7v1 = const u64 111
ret u64 v7v1
}
}
14 changes: 14 additions & 0 deletions sway-ir/tests/constants/u256_cmp.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
fn main() -> bool {
entry():
- v1v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000000
- v3v1 = cmp eq v1v1 v1v1
+ v3v1 = const bool true
ret bool v3v1
}
}
28 changes: 28 additions & 0 deletions sway-ir/tests/constants/u256_ops.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
fn main() -> u256 {
entry():
- v5v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000004
- v9v1 = const u64 2
- v10v1 = rsh v5v1, v9v1
- v3v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002
- v11v1 = lsh v3v1, v9v1
- v12v1 = add v10v1, v11v1
- v2v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001
- v13v1 = sub v12v1, v2v1
- v14v1 = mul v13v1, v3v1
- v15v1 = div v14v1, v5v1
- v16v1 = or v15v1, v3v1
- v17v1 = and v16v1, v5v1
- v18v1 = not v17v1
- v19v1 = not v18v1
- v7v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000006
- v20v1 = xor v19v1, v7v1
+ v20v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002
ret u256 v20v1
}
}
20 changes: 20 additions & 0 deletions sway-ir/tests/cse/cse1.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
fn main() -> bool {
entry():
v1v1 = const u64 11
v2v1 = const u64 0
v3v1 = add v1v1, v2v1
v4v1 = add v1v1, v2v1
v6v1 = add v2v1, v1v1
- v7v1 = cmp eq v3v1 v4v1
+ v7v1 = cmp eq v3v1 v3v1
v8v1 = cmp eq v6v1 v3v1
v9v1 = cmp eq v7v1 v8v1
ret bool v9v1
}
}
21 changes: 21 additions & 0 deletions sway-ir/tests/cse/cse2.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
fn main() -> bool {
entry():
v1v1 = const u64 11
v3v1 = const u64 0
v4v1 = add v1v1, v3v1
v5v1 = add v1v1, v3v1
v6v1 = sub v1v1, v4v1
v2v1 = const u64 11
- v7v1 = sub v2v1, v5v1
- v8v1 = cmp eq v6v1 v7v1
+ v7v1 = sub v2v1, v4v1
+ v8v1 = cmp eq v6v1 v6v1
ret bool v8v1
}
}
29 changes: 29 additions & 0 deletions sway-ir/tests/cse/cse3.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
entry fn main(a: u64, b: u64) -> () {
entry(a: u64, b: u64):
v5v1 = add a, b
v6v1 = const u64 0
br while(v6v1, v5v1)

while(v3v1: u64, v4v1: u64):
- v8v1 = cmp lt v3v1 v4v1
+ v8v1 = cmp lt v3v1 v5v1
cbr v8v1, while_body(), end_while()

while_body():
v10v1 = add a, b
v11v1 = const u64 1
v12v1 = add v3v1, v11v1
- br while(v12v1, v10v1)
+ br while(v12v1, v5v1)

end_while():
v14v1 = const unit ()
ret () v14v1
}
}
22 changes: 22 additions & 0 deletions sway-ir/tests/dce/copy_prop_1.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
entry fn main() -> u64 {
local { u64, u64, u64, u64 } __anon_0
- local { u64, u64, u64, u64 } __anon_468

entry():
v1v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_0
v2v1 = const u64 0
v3v1 = get_elem_ptr v1v1, __ptr u64, v2v1
- v4v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_468
- v5v1 = const u64 0
- v6v1 = get_elem_ptr v4v1, __ptr u64, v5v1
- mem_copy_val v6v1, v3v1
v8v1 = load v3v1
ret u64 v8v1
}
}
23 changes: 23 additions & 0 deletions sway-ir/tests/dce/copy_prop_2.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
entry fn main() -> u64 {
local { u64, u64, u64, u64 } __anon_0
- local { u64, u64, u64, u64 } __anon_468

entry():
- v1v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_0
- v2v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_468
- mem_copy_val v2v1, v1v1
+ v6v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_0
v4v1 = const u64 0
- v5v1 = get_elem_ptr v2v1, __ptr u64, v4v1
- v6v1 = get_local __ptr { u64, u64, u64, u64 }, __anon_0
v7v1 = get_elem_ptr v6v1, __ptr u64, v4v1
v8v1 = load v7v1
ret u64 v8v1
}
}
23 changes: 23 additions & 0 deletions sway-ir/tests/dce/copy_prop_3.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
entry fn main(v101: u64) -> u64 {
local [u64; 8] __anon_0
- local [u64; 8] __anon_468

entry(v101: u64):
- v2v1 = get_local __ptr [u64; 8], __anon_0
- v3v1 = get_local __ptr [u64; 8], __anon_468
- mem_copy_val v3v1, v2v1
v5v1 = const u64 1
v6v1 = add v101, v5v1
- v7v1 = get_elem_ptr v3v1, __ptr u64, v6v1
v8v1 = get_local __ptr [u64; 8], __anon_0
v9v1 = get_elem_ptr v8v1, __ptr u64, v6v1
v10v1 = load v9v1
ret u64 v10v1
}
}
18 changes: 18 additions & 0 deletions sway-ir/tests/dce/dce1.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
fn main() -> bool {
entry():
- v1v1 = const u64 11
- v2v1 = const u64 0
- v3v1 = cmp eq v1v1 v2v1
br block0()

block0():
v5v1 = const bool false
ret bool v5v1
}
}
14 changes: 14 additions & 0 deletions sway-ir/tests/dce/dce2.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
fn main() -> bool {
- local u64 i
-
entry():
v1v1 = const bool false
ret bool v1v1
}
}
41 changes: 41 additions & 0 deletions sway-ir/tests/dce/dce3.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
source: sway-ir/tests/tests.rs
---
Modified: true

script {
entry fn main() -> bool {
local mut u64 state

entry():
v1v1 = get_local __ptr u64, state
v2v1 = const u64 0
store v2v1 to v1v1
v4v1 = get_local __ptr u64, state
v5v1 = call function_0(v4v1)
v6v1 = get_local __ptr u64, state
v7v1 = load v6v1
v8v1 = const u64 42
v9v1 = cmp eq v7v1 v8v1
v10v1 = const bool false
v11v1 = cmp eq v9v1 v10v1
cbr v11v1, assert_1_block0(), assert_1_block1()

assert_1_block0():
v13v1 = const u64 18446744073709486084
revert v13v1

assert_1_block1():
v15v1 = const bool true
ret bool v15v1
}

fn function_0(state: __ptr u64) -> () {
entry(state: __ptr u64):
v18v1 = const u64 42
store v18v1 to state
- v21v1 = add v18v1, v18v1
v20v1 = const unit ()
ret () v20v1
}
}
Loading
Loading