summaryrefslogtreecommitdiff
path: root/src/wasm/literal.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2018-04-11 12:02:29 -0700
committerGitHub <noreply@github.com>2018-04-11 12:02:29 -0700
commit92afb40eea6e9a09af2d355ff9ab6a4bd04c54bb (patch)
tree671827c29364ef509ce2a6ba050d9b119c54c9cc /src/wasm/literal.cpp
parent9b5ce471992033eeec9a8779bce55f2429496431 (diff)
downloadbinaryen-92afb40eea6e9a09af2d355ff9ab6a4bd04c54bb.tar.gz
binaryen-92afb40eea6e9a09af2d355ff9ab6a4bd04c54bb.tar.bz2
binaryen-92afb40eea6e9a09af2d355ff9ab6a4bd04c54bb.zip
Some simple integer math opts (#1504)
Stuff like x + 5 != 2 => x != -3. Also some cleanups of utility functions I noticed while writing this, isTypeFloat => isFloatType. Inspired by https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/gen/generic.rules
Diffstat (limited to 'src/wasm/literal.cpp')
-rw-r--r--src/wasm/literal.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp
index dca3d64b4..a6dcd17f0 100644
--- a/src/wasm/literal.cpp
+++ b/src/wasm/literal.cpp
@@ -249,8 +249,8 @@ Literal Literal::convertUToF64() const {
Literal Literal::neg() const {
switch (type) {
- case Type::i32: return Literal(i32 ^ 0x80000000);
- case Type::i64: return Literal(int64_t(i64 ^ 0x8000000000000000ULL));
+ case Type::i32: return Literal(-uint32_t(i32));
+ case Type::i64: return Literal(-uint64_t(i64));
case Type::f32: return Literal(i32 ^ 0x80000000).castToF32();
case Type::f64: return Literal(int64_t(i64 ^ 0x8000000000000000ULL)).castToF64();
default: WASM_UNREACHABLE();