From 5b38857e7fe74d31af8ac0ae515ec27355800226 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Wed, 15 Jul 2020 13:46:25 +0300 Subject: [PATCH 1/5] add bnot to peepmatic + transform rule --- cranelift/codegen/src/peepmatic.rs | 6 ++++++ cranelift/codegen/src/preopt.peepmatic | 1 + cranelift/codegen/src/preopt.serialized | Bin 5613 -> 5657 bytes .../peepmatic/crates/runtime/src/operator.rs | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/cranelift/codegen/src/peepmatic.rs b/cranelift/codegen/src/peepmatic.rs index 1e22019407..2c6c2d1e01 100644 --- a/cranelift/codegen/src/peepmatic.rs +++ b/cranelift/codegen/src/peepmatic.rs @@ -237,6 +237,7 @@ impl Opcode { BandImm, Bconst, Bint, + Bnot, Bor, BorImm, Brnz, @@ -549,6 +550,11 @@ unsafe impl<'a, 'b> InstructionSet<'b> for &'a dyn TargetIsa { let val = pos.ins().bint(ty, a); pos.func.dfg.value_def(val).unwrap_inst().into() } + Operator::Bnot => { + let a = part_to_value(pos, root, a).unwrap(); + let val = pos.ins().bnot(a); + pos.func.dfg.value_def(val).unwrap_inst().into() + } Operator::Brnz => { let a = part_to_value(pos, root, a).unwrap(); diff --git a/cranelift/codegen/src/preopt.peepmatic b/cranelift/codegen/src/preopt.peepmatic index cd988ff7d9..8f2651fc21 100644 --- a/cranelift/codegen/src/preopt.peepmatic +++ b/cranelift/codegen/src/preopt.peepmatic @@ -112,6 +112,7 @@ ;; Replace with negative 1. (=> (bor_imm -1 $x) -1) +(=> (bxor_imm -1 $x) (bnot $x)) ;; Transform `[(x << N) >> N]` into a (un)signed-extending move. ;; diff --git a/cranelift/codegen/src/preopt.serialized b/cranelift/codegen/src/preopt.serialized index 1bb11b24ad37aacd868cb3aee8c1ad33109707d7..896c3ac8d7f3c3976ae46fff75bfa9b14a5a30dc 100644 GIT binary patch literal 5657 zcmcJT33J>w427ljk)-K;-*M73ZPWX{XZrvDREtlK&wSGE(q7LLGg^=U9teO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x28mqfdW7?epY*DTfo!lk{1P{e0!wsb^%I&V2i3ZqHXQTDt3dTh*fn zw=vyr)U_(LX8~x%)*G|4c-n5p{%AsEmWer@vTENL>#bifSJl$7#ED;O=~-l)S;2kw ztOF^ZoYkzQJC`DO#-9T2#9nnT4Ciaehd5@rr_l3f_di2IJmYbnGGZ z+hoF>S@zgVW7SB>0(u3E*zjv-%2ge>#hkf?M4S62S=ecrA$R=+E z^_9K?K`dMGc5|P)Sz1}^S>KR+`~7O`$1uJ<9Z6*UwZZfwBoFs_NQBCr2!D@96^da* z*v|Ur>`x$t{5>Ea;+SNVvXX{*%8>jO&(bMOME=cgtnX~RU#}Y-d&nu=XCJ{%#Cx{a zjsF%qnDS?=8i=FQxLQ^TSu*1%`cjob6_l8)lCOB(DmnI$D($n+h_wHj4Z{z0IK}%W z=6;gL^3A8Js1D3u8lTRGtzHk@;C+CzYk;7TLFEg^!X?R`&U5P^M<}sdLyF!-st0= zH}7-hy9o^O?Ph-#QYzqkoNwr?&U)J8O;}XY9 Date: Wed, 15 Jul 2020 14:16:56 +0300 Subject: [PATCH 2/5] add tests --- .../filetests/filetests/peepmatic/simplify64.clif | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cranelift/filetests/filetests/peepmatic/simplify64.clif b/cranelift/filetests/filetests/peepmatic/simplify64.clif index 93c289ccdd..dd61fbbe73 100644 --- a/cranelift/filetests/filetests/peepmatic/simplify64.clif +++ b/cranelift/filetests/filetests/peepmatic/simplify64.clif @@ -324,3 +324,17 @@ block0(v0: i32): ; nextln: v1 = iadd_imm v0, 42 ; nextln: nop ; nextln: return v2 + +function %bxor_imm_32(i32) -> i32 { +block0(v0: i32): + v1 = bxor_imm v0, -1 + ; check: bnot v0 + return v1 +} + +function %bxor_imm_64(i64) -> i64 { +block0(v0: i64): + v1 = bxor_imm v0, -1 + ; check: bnot v0 + return v1 +} \ No newline at end of file From d04d06d48a9480a48c6f67cbb0350ae8c783fc4e Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Wed, 15 Jul 2020 14:19:08 +0300 Subject: [PATCH 3/5] trailling nl --- cranelift/filetests/filetests/peepmatic/simplify64.clif | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cranelift/filetests/filetests/peepmatic/simplify64.clif b/cranelift/filetests/filetests/peepmatic/simplify64.clif index dd61fbbe73..72b4893c70 100644 --- a/cranelift/filetests/filetests/peepmatic/simplify64.clif +++ b/cranelift/filetests/filetests/peepmatic/simplify64.clif @@ -337,4 +337,4 @@ block0(v0: i64): v1 = bxor_imm v0, -1 ; check: bnot v0 return v1 -} \ No newline at end of file +} From 67b785d24146b65d8619cfc75c05c914fdcf87f5 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Wed, 15 Jul 2020 17:11:27 +0300 Subject: [PATCH 4/5] refactor: use different sections for this rule --- cranelift/codegen/src/preopt.peepmatic | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cranelift/codegen/src/preopt.peepmatic b/cranelift/codegen/src/preopt.peepmatic index 8f2651fc21..0833206450 100644 --- a/cranelift/codegen/src/preopt.peepmatic +++ b/cranelift/codegen/src/preopt.peepmatic @@ -112,6 +112,8 @@ ;; Replace with negative 1. (=> (bor_imm -1 $x) -1) + +;; Other replacments (=> (bxor_imm -1 $x) (bnot $x)) ;; Transform `[(x << N) >> N]` into a (un)signed-extending move. From 657aea528689b9ca00bbeff5e32ca58ec7a2e6e1 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 16 Jul 2020 14:56:11 +0300 Subject: [PATCH 5/5] remove rule and tests --- cranelift/codegen/src/preopt.peepmatic | 3 --- cranelift/codegen/src/preopt.serialized | Bin 5657 -> 5613 bytes .../filetests/peepmatic/simplify64.clif | 14 -------------- 3 files changed, 17 deletions(-) diff --git a/cranelift/codegen/src/preopt.peepmatic b/cranelift/codegen/src/preopt.peepmatic index 0833206450..cd988ff7d9 100644 --- a/cranelift/codegen/src/preopt.peepmatic +++ b/cranelift/codegen/src/preopt.peepmatic @@ -113,9 +113,6 @@ ;; Replace with negative 1. (=> (bor_imm -1 $x) -1) -;; Other replacments -(=> (bxor_imm -1 $x) (bnot $x)) - ;; Transform `[(x << N) >> N]` into a (un)signed-extending move. ;; ;; i16 -> i8 -> i16 diff --git a/cranelift/codegen/src/preopt.serialized b/cranelift/codegen/src/preopt.serialized index 896c3ac8d7f3c3976ae46fff75bfa9b14a5a30dc..1319882a51b346e3caf54241aeed5740b81d38b3 100644 GIT binary patch delta 20 ccmbQK^HzI9KF{QzY&?^zdBisF<%!`009pzMxBvhE delta 56 tcmaE>JyT~xKF?%ME}6;xEL@ZS@^Q#BF(3dF0~>+^WC3}bC-B5_0sue}2t@z@ diff --git a/cranelift/filetests/filetests/peepmatic/simplify64.clif b/cranelift/filetests/filetests/peepmatic/simplify64.clif index 72b4893c70..93c289ccdd 100644 --- a/cranelift/filetests/filetests/peepmatic/simplify64.clif +++ b/cranelift/filetests/filetests/peepmatic/simplify64.clif @@ -324,17 +324,3 @@ block0(v0: i32): ; nextln: v1 = iadd_imm v0, 42 ; nextln: nop ; nextln: return v2 - -function %bxor_imm_32(i32) -> i32 { -block0(v0: i32): - v1 = bxor_imm v0, -1 - ; check: bnot v0 - return v1 -} - -function %bxor_imm_64(i64) -> i64 { -block0(v0: i64): - v1 = bxor_imm v0, -1 - ; check: bnot v0 - return v1 -}