Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/passes/OptimizeInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
// shifting a 0 is a 0, or anything by 0 has no effect, all unless the shift has side effects
if (((left && left->value.geti32() == 0) || (right && Bits::getEffectiveShifts(right) == 0)) &&
!EffectAnalyzer(passOptions, curr->right).hasSideEffects()) {
replaceCurrent(left);
replaceCurrent(curr->left);
return;
}
} else if (curr->op == MulInt32) {
Expand Down
19 changes: 19 additions & 0 deletions test/passes/optimize-instructions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2179,4 +2179,23 @@
(i32.const -31744)
)
)
(func $return-proper-value-from-shift-left-by-zero (type $2) (result i32)
(if (result i32)
(i32.add
(loop $label$0 (result i32)
(block $label$1
(br_if $label$1
(i32.load
(i32.const 0)
)
)
)
(i32.const -62)
)
(i32.const 40)
)
(i32.const 1)
(i32.const 0)
)
)
)
25 changes: 25 additions & 0 deletions test/passes/optimize-instructions.wast
Original file line number Diff line number Diff line change
Expand Up @@ -2615,4 +2615,29 @@
(i32.const -1024)
)
)
(func $return-proper-value-from-shift-left-by-zero (result i32)
(if (result i32)
(i32.sub
(i32.add
(loop $label$0 (result i32)
(block $label$1
(br_if $label$1
(i32.shl
(i32.load
(i32.const 0)
)
(i32.const -31904) ;; really 0 shifts
)
)
)
(i32.const -62)
)
(i32.const 38)
)
(i32.const -2)
)
(i32.const 1)
(i32.const 0)
)
)
)