8000 Wasm: Better codegen for Long shifts with constant right-hand-side. · scala-js/scala-js@01ee94a · GitHub
[go: up one dir, main page]

Skip to content

Commit 01ee94a

Browse files
committed
Wasm: Better codegen for Long shifts with constant right-hand-side.
In our IR, the rhs of Long shifts is an Int, but in Wasm it must be a Long as well. In the common-case where the rhs is a constant, we now constant-fold the extension to 64 bits.
1 parent 70a4164 commit 01ee94a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

linker/shared/src/main/scala/org/scalajs/linker/backend/wasmemitter/FunctionEmitter.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,9 +1648,18 @@ private class FunctionEmitter private (
16481648

16491649
def genLongShiftOp(shiftInstr: wa.Instr): Type = {
16501650
genTree(lhs, LongType)
1651-
genTree(rhs, IntType)
1652-
markPosition(tree)
1653-
fb += wa.I64ExtendI32S
1651+
rhs match {
1652+
case IntLiteral(r) =>
1653+
// common case: fold the extension to 64 bits into the literal
1654+
markPosition(rhs)
1655+
fb += wa.I64Const(r.toLong)
1656+
markPosition(tree)
1657+
case _ =>
1658+
// otherwise, extend at run-time
1659+
genTree(rhs, IntType)
1660+
markPosition(tree)
1661+
fb += wa.I64ExtendI32S
1662+
}
16541663
fb += shiftInstr
16551664
LongType
16561665
}

0 commit comments

Comments
 (0)
0