Skip to content

Commit 4aa3463

Browse files
committed
handle squared shifts of an unreachable
1 parent b69f8a6 commit 4aa3463

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/passes/OptimizeInstructions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,9 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
539539
// shifts only use an effective amount from the constant, so adding must
540540
// be done carefully
541541
auto total = Bits::getEffectiveShifts(leftRight) + Bits::getEffectiveShifts(right);
542-
if (total == Bits::getEffectiveShifts(total, left->type)) {
542+
if (total == Bits::getEffectiveShifts(total, right->type)) {
543543
// no overflow, we can do this
544-
leftRight->value = LiteralUtils::makeLiteralFromInt32(total, left->type);
544+
leftRight->value = LiteralUtils::makeLiteralFromInt32(total, right->type);
545545
return left;
546546
} // TODO: handle overflows
547547
}

test/passes/optimize-instructions.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,4 +2055,10 @@
20552055
(i64.const 9)
20562056
)
20572057
)
2058+
(func $shifts-square-unreachable (type $3) (param $x i32) (result i32)
2059+
(i32.shr_u
2060+
(unreachable)
2061+
(i32.const 9)
2062+
)
2063+
)
20582064
)

test/passes/optimize-instructions.wast

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,4 +2487,13 @@
24872487
(i64.const 4098) ;; 2 bits effectively
24882488
)
24892489
)
2490+
(func $shifts-square-unreachable (param $x i32) (result i32)
2491+
(i32.shr_u
2492+
(i32.shr_u
2493+
(unreachable)
2494+
(i32.const 1031) ;; 7 bits effectively
2495+
)
2496+
(i32.const 4098) ;; 2 bits effectively
2497+
)
2498+
)
24902499
)

0 commit comments

Comments
 (0)