Skip to content

Commit 3980e53

Browse files
committed
Let the optimizer decide what it takes to become a select
1 parent d89703c commit 3980e53

18 files changed

+225
-242
lines changed

src/ast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,7 @@ export function mangleInternalName(declaration: DeclarationStatement): string {
22482248
function builderEndsWith(sb: string[], code: CharCode): bool {
22492249
if (sb.length) {
22502250
var last = sb[sb.length - 1];
2251-
return select<bool>(last.charCodeAt(last.length - 1) == code, false, last.length > 0);
2251+
return last.length > 0 ? last.charCodeAt(last.length - 1) == code : false;
22522252
}
22532253
return false;
22542254
}

src/builtins.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ export function compileGetConstant(compiler: Compiler, global: Global, reportNod
194194
/** Compiles a call to a built-in function. */
195195
export function compileCall(compiler: Compiler, prototype: FunctionPrototype, typeArguments: Type[] | null, operands: Expression[], contextualType: Type, reportNode: Node): ExpressionRef {
196196
var module = compiler.module;
197-
var usizeType = select<Type>(Type.usize64, Type.usize32, compiler.options.target == Target.WASM64);
198-
var nativeUsizeType = select<NativeType>(NativeType.I64, NativeType.I32, compiler.options.target == Target.WASM64);
197+
var usizeType = compiler.options.target == Target.WASM64 ? Type.usize64 : Type.usize32;
198+
var nativeUsizeType = compiler.options.target == Target.WASM64 ? NativeType.I64 : NativeType.I32;
199199

200200
var arg0: ExpressionRef,
201201
arg1: ExpressionRef,
@@ -365,7 +365,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
365365
}
366366
// fall-through
367367
case TypeKind.ISIZE:
368-
ret = module.createUnary(select<UnaryOp>(UnaryOp.ClzI64, UnaryOp.ClzI32, compiler.options.target == Target.WASM64), arg0);
368+
ret = module.createUnary(compiler.options.target == Target.WASM64 ? UnaryOp.ClzI64 : UnaryOp.ClzI32, arg0);
369369
break;
370370

371371
case TypeKind.I64:
@@ -418,7 +418,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
418418
}
419419
// fall-through
420420
case TypeKind.ISIZE:
421-
ret = module.createUnary(select<UnaryOp>(UnaryOp.CtzI64, UnaryOp.CtzI32, compiler.options.target == Target.WASM64), arg0);
421+
ret = module.createUnary(compiler.options.target == Target.WASM64 ? UnaryOp.CtzI64 : UnaryOp.CtzI32, arg0);
422422
break;
423423

424424
case TypeKind.I64:
@@ -471,7 +471,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
471471
}
472472
// fall-through
473473
case TypeKind.ISIZE:
474-
ret = module.createUnary(select<UnaryOp>(UnaryOp.PopcntI64, UnaryOp.PopcntI32, compiler.options.target == Target.WASM64), arg0);
474+
ret = module.createUnary(compiler.options.target == Target.WASM64 ? UnaryOp.PopcntI64 : UnaryOp.PopcntI32, arg0);
475475
break;
476476

477477
case TypeKind.I64:
@@ -533,7 +533,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
533533
}
534534
// fall-through
535535
case TypeKind.ISIZE:
536-
ret = module.createBinary(select<BinaryOp>(BinaryOp.RotlI64, BinaryOp.RotlI32, compiler.options.target == Target.WASM64), arg0, arg1);
536+
ret = module.createBinary(compiler.options.target == Target.WASM64 ? BinaryOp.RotlI64 : BinaryOp.RotlI32, arg0, arg1);
537537
break;
538538

539539
case TypeKind.I64:
@@ -594,7 +594,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
594594
}
595595
// fall-through
596596
case TypeKind.ISIZE:
597-
ret = module.createBinary(select<BinaryOp>(BinaryOp.RotrI64, BinaryOp.RotrI32, compiler.options.target == Target.WASM64), arg0, arg1);
597+
ret = module.createBinary(compiler.options.target == Target.WASM64 ? BinaryOp.RotrI64 : BinaryOp.RotrI32, arg0, arg1);
598598
break;
599599

600600
case TypeKind.I64:
@@ -656,11 +656,11 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
656656
tempLocal0 = compiler.currentFunction.getAndFreeTempLocal(usizeType);
657657
ret = module.createSelect(
658658
module.createTeeLocal(tempLocal0.index, arg0),
659-
module.createBinary(select<BinaryOp>(BinaryOp.SubI64, BinaryOp.SubI32, compiler.options.target == Target.WASM64),
659+
module.createBinary(compiler.options.target == Target.WASM64 ? BinaryOp.SubI64 : BinaryOp.SubI32,
660660
usizeType.toNativeZero(module),
661661
module.createGetLocal(tempLocal0.index, nativeUsizeType)
662662
),
663-
module.createBinary(select<BinaryOp>(BinaryOp.GtI64, BinaryOp.GtI32, compiler.options.target == Target.WASM64),
663+
module.createBinary(compiler.options.target == Target.WASM64 ? BinaryOp.GtI64 : BinaryOp.GtI32,
664664
module.createGetLocal(tempLocal0.index, nativeUsizeType),
665665
usizeType.toNativeZero(module)
666666
)
@@ -809,7 +809,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
809809
ret = module.createSelect(
810810
module.createTeeLocal(tempLocal0.index, arg0),
811811
module.createTeeLocal(tempLocal1.index, arg1),
812-
module.createBinary(select<BinaryOp>(BinaryOp.GtI64, BinaryOp.GtI32, compiler.options.target == Target.WASM64),
812+
module.createBinary(compiler.options.target == Target.WASM64 ? BinaryOp.GtI64 : BinaryOp.GtI32,
813813
module.createGetLocal(tempLocal0.index, nativeUsizeType),
814814
module.createGetLocal(tempLocal1.index, nativeUsizeType)
815815
)
@@ -828,7 +828,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
828828
ret = module.createSelect(
829829
module.createTeeLocal(tempLocal0.index, arg0),
830830
module.createTeeLocal(tempLocal1.index, arg1),
831-
module.createBinary(select<BinaryOp>(BinaryOp.GtU64, BinaryOp.GtU32, compiler.options.target == Target.WASM64),
831+
module.createBinary(compiler.options.target == Target.WASM64 ? BinaryOp.GtU64 : BinaryOp.GtU32,
832832
module.createGetLocal(tempLocal0.index, nativeUsizeType),
833833
module.createGetLocal(tempLocal1.index, nativeUsizeType)
834834
)
@@ -943,7 +943,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
943943
ret = module.createSelect(
944944
module.createTeeLocal(tempLocal0.index, arg0),
945945
module.createTeeLocal(tempLocal1.index, arg1),
946-
module.createBinary(select<BinaryOp>(BinaryOp.LtI64, BinaryOp.LtI32, compiler.options.target == Target.WASM64),
946+
module.createBinary(compiler.options.target == Target.WASM64 ? BinaryOp.LtI64 : BinaryOp.LtI32,
947947
module.createGetLocal(tempLocal0.index, nativeUsizeType),
948948
module.createGetLocal(tempLocal1.index, nativeUsizeType)
949949
)
@@ -962,7 +962,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
962962
ret = module.createSelect(
963963
module.createTeeLocal(tempLocal0.index, arg0),
964964
module.createTeeLocal(tempLocal1.index, arg1),
965-
module.createBinary(select<BinaryOp>(BinaryOp.LtU64, BinaryOp.LtU32, compiler.options.target == Target.WASM64),
965+
module.createBinary(compiler.options.target == Target.WASM64 ? BinaryOp.LtU64 : BinaryOp.LtU32,
966966
module.createGetLocal(tempLocal0.index, nativeUsizeType),
967967
module.createGetLocal(tempLocal1.index, nativeUsizeType)
968968
)
@@ -1603,7 +1603,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
16031603
case TypeKind.ISIZE:
16041604
case TypeKind.USIZE:
16051605
ret = module.createIf(
1606-
module.createUnary(select(UnaryOp.EqzI64, UnaryOp.EqzI32, compiler.options.target == Target.WASM64),
1606+
module.createUnary(compiler.options.target == Target.WASM64 ? UnaryOp.EqzI64 : UnaryOp.EqzI32,
16071607
arg0
16081608
),
16091609
module.createUnreachable()
@@ -1668,7 +1668,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
16681668
case TypeKind.USIZE:
16691669
tempLocal0 = compiler.currentFunction.getAndFreeTempLocal(usizeType);
16701670
ret = module.createIf(
1671-
module.createUnary(select<UnaryOp>(UnaryOp.EqzI64, UnaryOp.EqzI32, compiler.options.target == Target.WASM64),
1671+
module.createUnary(compiler.options.target == Target.WASM64 ? UnaryOp.EqzI64 : UnaryOp.EqzI32,
16721672
module.createTeeLocal(tempLocal0.index, arg0)
16731673
),
16741674
module.createUnreachable(),
@@ -1755,10 +1755,10 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
17551755
compiler.error(DiagnosticCode.Type_0_is_not_generic, reportNode.range, prototype.internalName);
17561756
if (operands.length != 1) {
17571757
compiler.error(DiagnosticCode.Expected_0_arguments_but_got_1, reportNode.range, "1", operands.length.toString(10));
1758-
compiler.currentType = select<Type>(Type.isize64, Type.isize32, compiler.options.target == Target.WASM64);
1758+
compiler.currentType = compiler.options.target == Target.WASM64 ? Type.isize64 : Type.isize32;
17591759
return module.createUnreachable();
17601760
}
1761-
return compiler.compileExpression(operands[0], select<Type>(Type.isize64, Type.isize32, compiler.options.target == Target.WASM64), ConversionKind.EXPLICIT);
1761+
return compiler.compileExpression(operands[0], compiler.options.target == Target.WASM64 ? Type.isize64 : Type.isize32, ConversionKind.EXPLICIT);
17621762

17631763
case "u8":
17641764
if (typeArguments)

0 commit comments

Comments
 (0)