Skip to content

Commit bd7f7ca

Browse files
committed
fix shl shift computation in getMaxBits
1 parent 1de1204 commit bd7f7ca

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/passes/OptimizeInstructions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Index getMaxBits(Expression* curr, LocalInfoProvider* localInfoProvider) {
188188
case OrInt32: case XorInt32: return std::max(getMaxBits(binary->left, localInfoProvider), getMaxBits(binary->right, localInfoProvider));
189189
case ShlInt32: {
190190
if (auto* shifts = binary->right->dynCast<Const>()) {
191-
return std::min(Index(32), getMaxBits(binary->left, localInfoProvider) + shifts->value.geti32());
191+
return std::min(Index(32), getMaxBits(binary->left, localInfoProvider) + (shifts->value.geti32() & 31));
192192
}
193193
return 32;
194194
}

test/passes/optimize-instructions.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,4 +2015,13 @@
20152015
(i32.const 255)
20162016
)
20172017
)
2018+
(func $neg-shifts-and-255-b (type $2) (result i32)
2019+
(i32.and
2020+
(i32.shl
2021+
(i32.const -2349025)
2022+
(i32.const -32)
2023+
)
2024+
(i32.const 255)
2025+
)
2026+
)
20182027
)

test/passes/optimize-instructions.wast

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,4 +2442,13 @@
24422442
(i32.const 255)
24432443
)
24442444
)
2445+
(func $neg-shifts-and-255-b (result i32)
2446+
(i32.and
2447+
(i32.shl
2448+
(i32.const -2349025)
2449+
(i32.const -32) ;; this shift does nothing
2450+
)
2451+
(i32.const 255)
2452+
)
2453+
)
24452454
)

0 commit comments

Comments
 (0)