aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compile/internal/ssa/_gen/Wasm.rules1
-rw-r--r--src/cmd/compile/internal/ssa/rewriteWasm.go22
2 files changed, 23 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/Wasm.rules b/src/cmd/compile/internal/ssa/_gen/Wasm.rules
index bf48ed4348..8490fb39b8 100644
--- a/src/cmd/compile/internal/ssa/_gen/Wasm.rules
+++ b/src/cmd/compile/internal/ssa/_gen/Wasm.rules
@@ -374,6 +374,7 @@
// --- Optimizations ---
(I64Add (I64Const [x]) (I64Const [y])) => (I64Const [x + y])
+(I64Sub (I64Const [x]) (I64Const [y])) => (I64Const [x - y])
(I64Mul (I64Const [x]) (I64Const [y])) => (I64Const [x * y])
(I64And (I64Const [x]) (I64Const [y])) => (I64Const [x & y])
(I64Or (I64Const [x]) (I64Const [y])) => (I64Const [x | y])
diff --git a/src/cmd/compile/internal/ssa/rewriteWasm.go b/src/cmd/compile/internal/ssa/rewriteWasm.go
index 94535bfbc7..68a40f0c7f 100644
--- a/src/cmd/compile/internal/ssa/rewriteWasm.go
+++ b/src/cmd/compile/internal/ssa/rewriteWasm.go
@@ -656,6 +656,8 @@ func rewriteValueWasm(v *Value) bool {
return rewriteValueWasm_OpWasmI64Store32(v)
case OpWasmI64Store8:
return rewriteValueWasm_OpWasmI64Store8(v)
+ case OpWasmI64Sub:
+ return rewriteValueWasm_OpWasmI64Sub(v)
case OpWasmI64Xor:
return rewriteValueWasm_OpWasmI64Xor(v)
case OpXor16:
@@ -4746,6 +4748,26 @@ func rewriteValueWasm_OpWasmI64Store8(v *Value) bool {
}
return false
}
+func rewriteValueWasm_OpWasmI64Sub(v *Value) bool {
+ v_1 := v.Args[1]
+ v_0 := v.Args[0]
+ // match: (I64Sub (I64Const [x]) (I64Const [y]))
+ // result: (I64Const [x - y])
+ for {
+ if v_0.Op != OpWasmI64Const {
+ break
+ }
+ x := auxIntToInt64(v_0.AuxInt)
+ if v_1.Op != OpWasmI64Const {
+ break
+ }
+ y := auxIntToInt64(v_1.AuxInt)
+ v.reset(OpWasmI64Const)
+ v.AuxInt = int64ToAuxInt(x - y)
+ return true
+ }
+ return false
+}
func rewriteValueWasm_OpWasmI64Xor(v *Value) bool {
v_1 := v.Args[1]
v_0 := v.Args[0]