diff options
-rw-r--r-- | src/passes/PickLoadSigns.cpp | 4 | ||||
-rw-r--r-- | test/passes/pick-load-signs_all-features.txt | 24 | ||||
-rw-r--r-- | test/passes/pick-load-signs_all-features.wast | 23 |
3 files changed, 51 insertions, 0 deletions
diff --git a/src/passes/PickLoadSigns.cpp b/src/passes/PickLoadSigns.cpp index c3b5a2ba2..3541b1055 100644 --- a/src/passes/PickLoadSigns.cpp +++ b/src/passes/PickLoadSigns.cpp @@ -109,6 +109,10 @@ struct PickLoadSigns : public WalkerPass<ExpressionStackWalker<PickLoadSigns>> { load->bytes * 8)) { // unsigned usages exist but the wrong size continue; } + // Atomic operations are always unsigned, never signed. + if (load->isAtomic) { + continue; + } // we can pick the optimal one. our hope is to remove 2 items per // signed use (two shifts), so we factor that in load->signed_ = usage.signedUsages * 2 >= usage.unsignedUsages; diff --git a/test/passes/pick-load-signs_all-features.txt b/test/passes/pick-load-signs_all-features.txt new file mode 100644 index 000000000..4b08c75de --- /dev/null +++ b/test/passes/pick-load-signs_all-features.txt @@ -0,0 +1,24 @@ +(module + (type $none_=>_i32 (func (result i32))) + (memory $0 (shared 16 16)) + (func $atomics-are-always-unsigned (result i32) + (local $0 i32) + (drop + (block $block (result i32) + (local.set $0 + (i32.atomic.load16_u + (i32.const 27) + ) + ) + (i32.shr_s + (i32.shl + (local.get $0) + (i32.const 16) + ) + (i32.const 16) + ) + ) + ) + (i32.const -65) + ) +) diff --git a/test/passes/pick-load-signs_all-features.wast b/test/passes/pick-load-signs_all-features.wast new file mode 100644 index 000000000..20a77eae4 --- /dev/null +++ b/test/passes/pick-load-signs_all-features.wast @@ -0,0 +1,23 @@ +(module + (memory $0 (shared 16 16)) + (func $atomics-are-always-unsigned (result i32) + (local $0 i32) + (drop + (block (result i32) + (local.set $0 + (i32.atomic.load16_u ;; an atomic load cannot become signed + (i32.const 27) + ) + ) + (i32.shr_s + (i32.shl + (local.get $0) + (i32.const 16) + ) + (i32.const 16) + ) + ) + ) + (i32.const -65) + ) +) |