Skip to content

Commit 28d670a

Browse files
authored
fix regression from 45d88e3 - left may not exist, need to return curr->left, after that change (#1207)
1 parent 45d88e3 commit 28d670a

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/passes/OptimizeInstructions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
865865
// shifting a 0 is a 0, or anything by 0 has no effect, all unless the shift has side effects
866866
if (((left && left->value.geti32() == 0) || (right && Bits::getEffectiveShifts(right) == 0)) &&
867867
!EffectAnalyzer(passOptions, curr->right).hasSideEffects()) {
868-
replaceCurrent(left);
868+
replaceCurrent(curr->left);
869869
return;
870870
}
871871
} else if (curr->op == MulInt32) {

test/passes/optimize-instructions.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,4 +2179,23 @@
21792179
(i32.const -31744)
21802180
)
21812181
)
2182+
(func $return-proper-value-from-shift-left-by-zero (type $2) (result i32)
2183+
(if (result i32)
2184+
(i32.add
2185+
(loop $label$0 (result i32)
2186+
(block $label$1
2187+
(br_if $label$1
2188+
(i32.load
2189+
(i32.const 0)
2190+
)
2191+
)
2192+
)
2193+
(i32.const -62)
2194+
)
2195+
(i32.const 40)
2196+
)
2197+
(i32.const 1)
2198+
(i32.const 0)
2199+
)
2200+
)
21822201
)

test/passes/optimize-instructions.wast

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,4 +2615,29 @@
26152615
(i32.const -1024)
26162616
)
26172617
)
2618+
(func $return-proper-value-from-shift-left-by-zero (result i32)
2619+
(if (result i32)
2620+
(i32.sub
2621+
(i32.add
2622+
(loop $label$0 (result i32)
2623+
(block $label$1
2624+
(br_if $label$1
2625+
(i32.shl
2626+
(i32.load
2627+
(i32.const 0)
2628+
)
2629+
(i32.const -31904) ;; really 0 shifts
2630+
)
2631+
)
2632+
)
2633+
(i32.const -62)
2634+
)
2635+
(i32.const 38)
2636+
)
2637+
(i32.const -2)
2638+
)
2639+
(i32.const 1)
2640+
(i32.const 0)
2641+
)
2642+
)
26182643
)

0 commit comments

Comments
 (0)