Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
8 changes: 4 additions & 4 deletions sway-ir/src/optimize/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ mod tests {
use crate::{optimize::tests::*, CONST_FOLDING_NAME};

fn assert_operator(t: &str, opcode: &str, l: &str, r: Option<&str>, result: Option<&str>) {
let expected = result.map(|result| format!("v0 = const {t} {result}"));
let expected = result.map(|result| format!("const {t} {result}"));
let expected = expected.as_ref().map(|x| vec![x.as_str()]);
let body = format!(
"
Expand Down Expand Up @@ -495,9 +495,9 @@ mod tests {
ret u64 result6, !0
}",
Some([
"v0 = get_local __ptr u64, LOCAL",
"v1 = load v0",
"ret u64 v1",
"v3v1 = get_local __ptr u64, LOCAL",
"v4v1 = load v3v1",
"ret u64 v4v1",
]),
);
}
Expand Down
3 changes: 2 additions & 1 deletion sway-ir/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use std::collections::{BTreeMap, HashMap};

use slotmap::Key;
use sway_types::SourceEngine;

use crate::{
Expand Down Expand Up @@ -1401,7 +1402,7 @@ impl Namer {

fn default_name(&mut self, value: &Value) -> String {
self.names.get(value).cloned().unwrap_or_else(|| {
let new_name = format!("v{}", self.next_value_idx);
let new_name = format!("v{:?}", value.0.data());
self.next_value_idx += 1;
self.names.insert(*value, new_name.clone());
new_name
Expand Down
4 changes: 3 additions & 1 deletion sway-ir/tests/constants/u256_cmp.ir
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// regex: ID=[[:alpha:]_0-9]+

script {
fn main() -> bool {
entry():
v0 = const u256 0x0000000000000000000000000000000000000000000000000000000000000000
v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001

v10 = cmp eq v0 v0
//check: v0 = const bool true
//check: $ID = const bool true
ret bool v10
}
}
7 changes: 6 additions & 1 deletion sway-ir/tests/constants/u256_ops.ir
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// regex: ID=[[:alpha:]_0-9]+

script {
fn main() -> u256 {
entry():
Expand All @@ -22,7 +24,10 @@ script {
v18 = not v17
v19 = not v18
v20 = xor v19, v6
//check: v0 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002
// check: entry
// nextln: $ID = const u256 0x0000000000000000000000000000000000000000000000000000000000000002
// check-not: const
// check: ret
ret u256 v20
}
}
2 changes: 1 addition & 1 deletion sway-ir/tests/cse/cse1.ir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// regex: ID=[[:alpha:]0-9]+
// regex: VAR=v\d+
// regex: VAR=v\d+v\d+

script {
fn main() -> bool {
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/cse/cse2.ir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// regex: ID=[[:alpha:]0-9]+
// regex: VAR=v\d+
// regex: VAR=v\d+v\d+

script {
fn main() -> bool {
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/cse/cse3.ir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// regex: ID=[[:alpha:]0-9]+
// regex: VAR=v\d+
// regex: VAR=v\d+v\d+

script {
entry fn main(a: u64, b: u64) -> () {
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/dce/copy_prop_1.ir
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ script {
}
}

// regex: VAL=v\d+
// regex: VAL=v\d+v\d+

// not: mem_copy_val $VAL, $VAL
2 changes: 1 addition & 1 deletion sway-ir/tests/dce/copy_prop_2.ir
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ script {
}
}

// regex: VAL=v\d+
// regex: VAL=v\d+v\d+

// not: mem_copy_val $VAL, $VAL
2 changes: 1 addition & 1 deletion sway-ir/tests/dce/copy_prop_3.ir
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ script {
}
}

// regex: VAL=v\d+
// regex: VAL=v\d+v\d+

// not: mem_copy_val $VAL, $VAL
2 changes: 1 addition & 1 deletion sway-ir/tests/dce/dce_dead_asm_block.ir
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// let f = asm(arg: function()) { arg };
// }

// regex: VAL=v\d+
// regex: VAL=v\d+v\d+

script {
entry fn main() -> () {
Expand Down
8 changes: 5 additions & 3 deletions sway-ir/tests/dce/dce_dead_config_assignment.ir
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ contract {
}
}

// regex: VAL=v\d+v\d+

// check: pub entry fn assign_config_call_pass_config
// nextln: entry():
// nextln: v0 = get_config __ptr u64, CONFIG
// nextln: v1 = load v0
// nextln: v2 = call poke_0(v1)
// nextln: $(v0=$VAL) = get_config __ptr u64, CONFIG
// nextln: $(v1=$VAL) = load $v0
// nextln: $(v2=$VAL) = call poke_0($v1)
// not: store
// check: ret ()
6 changes: 4 additions & 2 deletions sway-ir/tests/dce/dce_dead_constant_assignment.ir
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ script {
}
}

// regex: VAL=v\d+v\d+

// check: entry fn main() -> () {
// nextln: entry():
// nextln: v0 = const unit ()
// nextln: ret () v0
// nextln: $(v0=$VAL) = const unit ()
// nextln: ret () $v0
// nextln: }
2 changes: 1 addition & 1 deletion sway-ir/tests/demote_misc/demote_asm_block_arg.ir
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ script {
}
}

// regex: VAL=v\d+
// regex: VAL=v\d+v\d+
// regex: ID=[[:alpha:]0-9_]+

// check: $(arg_0=$VAL) = get_local __ptr b256, $ID
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/demote_misc/demote_asm_block_ret.ir
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ script {
}
}

// regex: VAL=v\d+
// regex: VAL=v\d+v\d+
// regex: ID=[[:alpha:]0-9_]+

// check: $(tmp_ptr=$VAL) = get_local __ptr b256, $ID
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/demote_misc/demote_log.ir
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ script {
}
}

// regex: VAL=v\d+
// regex: VAL=v\d+v\d+
// regex: ID=[[:alpha:]0-9_]+

// check: local b256 $(loc_name=$ID)
Expand Down
20 changes: 10 additions & 10 deletions sway-ir/tests/demote_misc/demote_wide_binary_ops_constants.ir
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ script {
}
}

// regex: ID=[[:alpha:]0-9_]+
// regex: VAL=v\d+v\d+

// check: v0 = get_local __ptr u256, __wide_lhs
// check: v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001
// check: store v1 to v0
// check: v2 = get_local __ptr u256, __wide_rhs
// check: v3 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002
// check: store v3 to v2
// check: v4 = get_local __ptr u256, __wide_result
// check: wide add v0, v2 to v4
// check: v5 = load v4
// check: $(v0=$VAL) = get_local __ptr u256, __wide_lhs
// check: $(v1=$VAL) = const u256 0x0000000000000000000000000000000000000000000000000000000000000001
// check: store $v1 to $v0
// check: $(v2=$VAL) = get_local __ptr u256, __wide_rhs
// check: $(v3=$VAL) = const u256 0x0000000000000000000000000000000000000000000000000000000000000002
// check: store $v3 to $v2
// check: $(v4=$VAL) = get_local __ptr u256, __wide_result
// check: wide add $v0, $v2 to $v4
// check: $(v5=$VAL) = load $v4
26 changes: 13 additions & 13 deletions sway-ir/tests/demote_misc/demote_wide_binary_ops_loads.ir
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ script {
}
}

// regex: ID=[[:alpha:]0-9_]+
// regex: VAL=v\d+v\d+

// check: local u256 __wide_lhs
// check: local mut u256 __wide_result
// check: local u256 __wide_rhs
// check: local u256 lhs
// check: local u256 rhs
// check: entry():
// check: v0 = get_local __ptr u256, lhs
// check: v1 = load v0
// check: v2 = get_local __ptr u256, rhs
// check: v3 = load v2
// check: v4 = get_local __ptr u256, __wide_lhs
// check: store v1 to v4
// check: v5 = get_local __ptr u256, __wide_rhs
// check: store v3 to v5
// check: v6 = get_local __ptr u256, __wide_result
// check: wide add v4, v5 to v6
// check: v7 = load v6
// check: ret u256 v7
// check: $(v0=$VAL) = get_local __ptr u256, lhs
// check: $(v1=$VAL) = load $v0
// check: $(v2=$VAL) = get_local __ptr u256, rhs
// check: $(v3=$VAL) = load $v2
// check: $(v4=$VAL) = get_local __ptr u256, __wide_lhs
// check: store $v1 to $v4
// check: $(v5=$VAL) = get_local __ptr u256, __wide_rhs
// check: store $v3 to $v5
// check: $(v6=$VAL) = get_local __ptr u256, __wide_result
// check: wide add $v4, $v5 to $v6
// check: $(v7=$VAL) = load $v6
// check: ret u256 $v7
16 changes: 8 additions & 8 deletions sway-ir/tests/demote_misc/demote_wide_cmp_constants.ir
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ script {
}
}

// regex: ID=[[:alpha:]0-9_]+
// regex: VAL=v\d+v\d+

// check: v0 = get_local __ptr u256, __wide_lhs
// check: v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001
// check: store v1 to v0
// check: v2 = get_local __ptr u256, __wide_rhs
// check: v3 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002
// check: store v3 to v2
// check: v4 = wide cmp eq v0 v2
// check: $(v0=$VAL) = get_local __ptr u256, __wide_lhs
// check: $(v1=$VAL) = const u256 0x0000000000000000000000000000000000000000000000000000000000000001
// check: store $v1 to $v0
// check: $(v2=$VAL) = get_local __ptr u256, __wide_rhs
// check: $(v3=$VAL) = const u256 0x0000000000000000000000000000000000000000000000000000000000000002
// check: store $v3 to $v2
// check: $(v4=$VAL) = wide cmp eq $v0 $v2
28 changes: 14 additions & 14 deletions sway-ir/tests/demote_misc/demote_wide_mod_constants.ir
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ script {
}
}

// regex: ID=[[:alpha:]0-9_]+
// regex: VAL=v\d+v\d+

// check: local u256 __wide_lhs
// check: local mut u256 __wide_result
// check: local u256 __wide_rhs
// check: local u256 lhs
// check: local u256 rhs
// check: entry():
// check: v0 = get_local __ptr u256, lhs
// check: v1 = load v0
// check: v2 = get_local __ptr u256, rhs
// check: v3 = load v2
// check: v4 = get_local __ptr u256, __wide_lhs
// check: store v1 to v4
// check: v5 = get_local __ptr u256, __wide_zero
// check: v6 = get_local __ptr u256, __wide_rhs
// check: store v3 to v6
// check: v7 = get_local __ptr u256, __wide_result
// check: wide mod v4, v5, v6 to v7
// check: v8 = load v7
// check: ret u256 v8
// check: $(v0=$VAL) = get_local __ptr u256, lhs
// check: $(v1=$VAL) = load $v0
// check: $(v2=$VAL) = get_local __ptr u256, rhs
// check: $(v3=$VAL) = load $v2
// check: $(v4=$VAL) = get_local __ptr u256, __wide_lhs
// check: store $v1 to $v4
// check: $(v5=$VAL) = get_local __ptr u256, __wide_zero
// check: $(v6=$VAL) = get_local __ptr u256, __wide_rhs
// check: store $v3 to $v6
// check: $(v7=$VAL) = get_local __ptr u256, __wide_result
// check: wide mod $v4, $v5, $v6 to $v7
// check: $(v8=$VAL) = load $v7
// check: ret u256 $v8
12 changes: 6 additions & 6 deletions sway-ir/tests/demote_misc/demote_wide_not_constants.ir
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ script {
}
}

// regex: ID=[[:alpha:]0-9_]+
// regex: VAL=v\d+v\d+

// check: v0 = get_local __ptr u256, __wide_lhs
// check: v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001
// check: store v1 to v0
// check: v2 = get_local __ptr u256, __wide_result
// check: wide not v0 to v2
// check: $(v0=$VAL) = get_local __ptr u256, __wide_lhs
// check: $(v1=$VAL) = const u256 0x0000000000000000000000000000000000000000000000000000000000000001
// check: store $v1 to $v0
// check: $(v2=$VAL) = get_local __ptr u256, __wide_result
// check: wide not $v0 to $v2
2 changes: 1 addition & 1 deletion sway-ir/tests/inline/bigger.ir
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// x
// }

// regex: VAR=v\d+
// regex: VAR=v\d+v\d+
// regex: ID=[[:alpha:]0-9_]+

script {
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/inline/fiddly.ir
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// regex: ID=[[:alpha:]0-9_]+
// regex: LABEL=[[:alpha:]0-9_]+\(.*\):
// regex: VAR=v\d+
// regex: VAR=v\d+v\d+

script {
fn not(v: bool) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/inline/int_to_ptr.ir
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// all
//
// regex: VAR=v\d+
// regex: VAR=v\d+v\d+
// regex: LABEL=[[:alpha:]0-9_]+

script {
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/inline/recursive-1.ir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// regex: VAR=v\d+
// regex: VAR=v\d+v\d+
// regex: LABEL=[[:alpha:]0-9_]+
// regex: PING=(ping|id_from_ping)
// regex: PONG=(pong|id_from_pong)
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/inline/simple.ir
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// a(22)
// }

// regex: VAR=v\d+
// regex: VAR=v\d+v\d+
// regex: LABEL=[[:alpha:]0-9_]+

script {
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/mem2reg/global_simple.ir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// regex: VAR=v\d+
// regex: VAR=v\d+v\d+
// regex: ID=[[:alpha:]0-9_]+

script {
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/mem2reg/is_prime.ir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// regex: VAR=v\d+
// regex: VAR=v\d+v\d+
// regex: ID=[[:alpha:]0-9_]+

script {
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/mem2reg/while_loops.ir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// regex: VAR=v\d+
// regex: VAR=v\d+v\d+
// regex: ID=[[:alpha:]0-9_]+

script {
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/tests/memcpyopt/copy_prop_1.ir
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ script {
}
}

// regex: VAL=v\d+
// regex: VAL=v\d+v\d+

// check: mem_copy_val $(mem_cpy_dest=$VAL), $(mem_cpy_src=$VAL)
// The optimization should replace the load's source to be the memcpy's source.
Expand Down
Loading
Loading