diff --git a/lib/Optimizer/Scalar/FuncSigOpts.cpp b/lib/Optimizer/Scalar/FuncSigOpts.cpp index 69d37deff9c..9d2b1b74582 100644 --- a/lib/Optimizer/Scalar/FuncSigOpts.cpp +++ b/lib/Optimizer/Scalar/FuncSigOpts.cpp @@ -169,15 +169,16 @@ static bool performFSO(Function *F, std::vector &worklist) { llvh::DenseSet toRedo; - // Replace all unused arguments with undef. + // Replace all unused arguments with 0 (which is cheap to create). + Literal *zero = builder.getLiteralPositiveZero(); for (auto &arg : unusedParams) { Value *prevArg = arg.call->getArgument(arg.idx); if (!llvh::isa(prevArg)) toRedo.insert(arg.call->getParent()->getParent()); - arg.call->setArgument(undef, arg.idx); + arg.call->setArgument(zero, arg.idx); if (arg.param) - arg.param->setType(Type::createUndefined()); + arg.param->setType(Type::createUint32()); NumArgsOpt++; } diff --git a/test/Optimizer/callee.js b/test/Optimizer/callee.js index 6d1a60c584b..52f066767bc 100644 --- a/test/Optimizer/callee.js +++ b/test/Optimizer/callee.js @@ -70,7 +70,7 @@ function load_store_multiple_test() { // CHECK-NEXT:frame = [] // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = CreateFunctionInst (:object) %foo(): number -// CHECK-NEXT: %1 = CallInst (:number) %0: object, %foo(): number, empty: any, undefined: undefined, 12: number +// CHECK-NEXT: %1 = CallInst (:number) %0: object, %foo(): number, empty: any, 0: number, 12: number // CHECK-NEXT: %2 = ReturnInst 12: number // CHECK-NEXT:function_end @@ -80,7 +80,7 @@ function load_store_multiple_test() { // CHECK-NEXT: %0 = CreateFunctionInst (:object) %"foo 1#"(): number // CHECK-NEXT: %1 = LoadPropertyInst (:any) %0: object, "prototype": string // CHECK-NEXT: %2 = CreateThisInst (:object) %1: any, %0: object -// CHECK-NEXT: %3 = ConstructInst (:number) %0: object, %"foo 1#"(): number, empty: any, undefined: undefined, 12: number +// CHECK-NEXT: %3 = ConstructInst (:number) %0: object, %"foo 1#"(): number, empty: any, 0: number, 12: number // CHECK-NEXT: %4 = ReturnInst %2: object // CHECK-NEXT:function_end @@ -90,7 +90,7 @@ function load_store_multiple_test() { // CHECK-NEXT: %0 = CreateFunctionInst (:object) %ping(): number // CHECK-NEXT: %1 = CreateFunctionInst (:object) %k(): number // CHECK-NEXT: %2 = StoreFrameInst %1: object, [k]: object -// CHECK-NEXT: %3 = CallInst (:number) %0: object, %ping(): number, empty: any, undefined: undefined +// CHECK-NEXT: %3 = CallInst (:number) %0: object, %ping(): number, empty: any, 0: number // CHECK-NEXT: %4 = ReturnInst 123: number // CHECK-NEXT:function_end @@ -100,7 +100,7 @@ function load_store_multiple_test() { // CHECK-NEXT: %0 = CreateFunctionInst (:object) %"foo 2#"(): number // CHECK-NEXT: %1 = StoreFrameInst %0: object, [foo]: object // CHECK-NEXT: %2 = CreateFunctionInst (:object) %bar(): number -// CHECK-NEXT: %3 = CallInst (:number) %2: object, %bar(): number, empty: any, undefined: undefined +// CHECK-NEXT: %3 = CallInst (:number) %2: object, %bar(): number, empty: any, 0: number // CHECK-NEXT: %4 = ReturnInst %3: number // CHECK-NEXT:function_end @@ -120,7 +120,7 @@ function load_store_multiple_test() { // CHECK-NEXT:frame = [] // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = LoadFrameInst (:object) [k@load_store_test]: object -// CHECK-NEXT: %1 = CallInst (:number) %0: object, %k(): number, empty: any, undefined: undefined, 123: number +// CHECK-NEXT: %1 = CallInst (:number) %0: object, %k(): number, empty: any, 0: number, 123: number // CHECK-NEXT: %2 = ReturnInst 123: number // CHECK-NEXT:function_end @@ -141,8 +141,8 @@ function load_store_multiple_test() { // CHECK-NEXT:frame = [] // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = LoadFrameInst (:object) [foo@load_store_multiple_test]: object -// CHECK-NEXT: %1 = CallInst (:number) %0: object, %"foo 2#"(): number, empty: any, undefined: undefined, true: boolean, 7: number -// CHECK-NEXT: %2 = CallInst (:number) %0: object, %"foo 2#"(): number, empty: any, undefined: undefined, true: boolean, 8: number +// CHECK-NEXT: %1 = CallInst (:number) %0: object, %"foo 2#"(): number, empty: any, 0: number, true: boolean, 7: number +// CHECK-NEXT: %2 = CallInst (:number) %0: object, %"foo 2#"(): number, empty: any, 0: number, true: boolean, 8: number // CHECK-NEXT: %3 = BinaryAddInst (:number) %1: number, %2: number // CHECK-NEXT: %4 = ReturnInst %3: number // CHECK-NEXT:function_end diff --git a/test/Optimizer/constructor_callee.js b/test/Optimizer/constructor_callee.js index de020d3ee8a..4292fecf352 100644 --- a/test/Optimizer/constructor_callee.js +++ b/test/Optimizer/constructor_callee.js @@ -60,7 +60,7 @@ function ctor_load_store_test() { // CHECK-NEXT: %0 = CreateFunctionInst (:object) %"use_this 1#"(): undefined // CHECK-NEXT: %1 = StoreFrameInst %0: object, [use_this]: object // CHECK-NEXT: %2 = CreateFunctionInst (:object) %construct_use_this(): object -// CHECK-NEXT: %3 = CallInst (:object) %2: object, %construct_use_this(): object, empty: any, undefined: undefined +// CHECK-NEXT: %3 = CallInst (:object) %2: object, %construct_use_this(): object, empty: any, 0: number // CHECK-NEXT: %4 = ReturnInst %3: object // CHECK-NEXT:function_end diff --git a/test/Optimizer/func_sig_opts.js b/test/Optimizer/func_sig_opts.js index a945061c42e..0150d8b739c 100644 --- a/test/Optimizer/func_sig_opts.js +++ b/test/Optimizer/func_sig_opts.js @@ -89,7 +89,7 @@ function test_async() { // CHECK-NEXT: %1 = CreateFunctionInst (:object) %foo(): number // CHECK-NEXT: %2 = CreateFunctionInst (:object) %bar(): string|number|bigint // CHECK-NEXT: %3 = StorePropertyStrictInst %2: object, %0: any, "p": string -// CHECK-NEXT: %4 = CallInst (:number) %1: object, %foo(): number, empty: any, undefined: undefined, 1: number, 2: number +// CHECK-NEXT: %4 = CallInst (:number) %1: object, %foo(): number, empty: any, 0: number, 1: number, 2: number // CHECK-NEXT: %5 = CallInst (:string|number|bigint) %2: object, %bar(): string|number|bigint, empty: any, undefined: undefined, 1: number, 2: number // CHECK-NEXT: %6 = BinaryAddInst (:string|number) %4: number, %5: string|number|bigint // CHECK-NEXT: %7 = ReturnInst %6: string|number @@ -99,8 +99,8 @@ function test_async() { // CHECK-NEXT:frame = [] // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = CreateFunctionInst (:object) %builder(): number -// CHECK-NEXT: %1 = CallInst (:number) %0: object, %builder(): number, empty: any, undefined: undefined -// CHECK-NEXT: %2 = CallInst (:number) %0: object, %builder(): number, empty: any, undefined: undefined +// CHECK-NEXT: %1 = CallInst (:number) %0: object, %builder(): number, empty: any, 0: number +// CHECK-NEXT: %2 = CallInst (:number) %0: object, %builder(): number, empty: any, 0: number // CHECK-NEXT: %3 = BinaryAddInst (:number) %1: number, %2: number // CHECK-NEXT: %4 = ReturnInst %3: number // CHECK-NEXT:function_end @@ -166,7 +166,7 @@ function test_async() { // CHECK-NEXT: %2 = ReturnInst %1: number // CHECK-NEXT:function_end -// CHECK:function foo2(a: any, b: number, c: number, d: undefined): string|number [allCallsitesKnownInStrictMode] +// CHECK:function foo2(a: any, b: number, c: number, d: number): string|number [allCallsitesKnownInStrictMode] // CHECK-NEXT:frame = [] // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = LoadParamInst (:any) %a: any @@ -181,7 +181,7 @@ function test_async() { // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = LoadParamInst (:any) %e: any // CHECK-NEXT: %1 = LoadFrameInst (:object) [foo2@test_unused_and_duplicate_params]: object -// CHECK-NEXT: %2 = CallInst (:string|number) %1: object, %foo2(): string|number, empty: any, undefined: undefined, %0: any, 2: number, 1: number, undefined: undefined, undefined: undefined, undefined: undefined +// CHECK-NEXT: %2 = CallInst (:string|number) %1: object, %foo2(): string|number, empty: any, 0: number, %0: any, 2: number, 1: number, 0: number, 0: number, 0: number // CHECK-NEXT: %3 = ReturnInst undefined: undefined // CHECK-NEXT:function_end @@ -190,7 +190,7 @@ function test_async() { // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = LoadParamInst (:any) %e: any // CHECK-NEXT: %1 = LoadFrameInst (:object) [foo2@test_unused_and_duplicate_params]: object -// CHECK-NEXT: %2 = CallInst (:string|number) %1: object, %foo2(): string|number, empty: any, undefined: undefined, %0: any, 2: number, 3: number, undefined: undefined, undefined: undefined +// CHECK-NEXT: %2 = CallInst (:string|number) %1: object, %foo2(): string|number, empty: any, 0: number, %0: any, 2: number, 3: number, 0: number, 0: number // CHECK-NEXT: %3 = ReturnInst undefined: undefined // CHECK-NEXT:function_end diff --git a/test/Optimizer/function-analysis-call-closure.js b/test/Optimizer/function-analysis-call-closure.js index 51756bb1b4b..13c67113d1c 100644 --- a/test/Optimizer/function-analysis-call-closure.js +++ b/test/Optimizer/function-analysis-call-closure.js @@ -30,7 +30,7 @@ function main() { // CHECK-NEXT:frame = [] // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = CreateFunctionInst (:object) %f(): undefined -// CHECK-NEXT: %1 = CallInst (:undefined) %0: object, %f(): undefined, empty: any, undefined: undefined +// CHECK-NEXT: %1 = CallInst (:undefined) %0: object, %f(): undefined, empty: any, 0: number // CHECK-NEXT: %2 = ReturnInst undefined: undefined // CHECK-NEXT:function_end diff --git a/test/Optimizer/function-analysis-chained-vars.js b/test/Optimizer/function-analysis-chained-vars.js index ded290e31fd..7abc5923a18 100644 --- a/test/Optimizer/function-analysis-chained-vars.js +++ b/test/Optimizer/function-analysis-chained-vars.js @@ -41,7 +41,7 @@ function main() { // CHECK-NEXT: %0 = CreateFunctionInst (:object) %foo(): object // CHECK-NEXT: %1 = CreateFunctionInst (:object) %x(): number // CHECK-NEXT: %2 = StoreFrameInst %1: object, [x]: object -// CHECK-NEXT: %3 = CallInst (:object) %0: object, %foo(): object, empty: any, undefined: undefined +// CHECK-NEXT: %3 = CallInst (:object) %0: object, %foo(): object, empty: any, 0: number // CHECK-NEXT: %4 = ReturnInst undefined: undefined // CHECK-NEXT:function_end @@ -64,6 +64,6 @@ function main() { // CHECK-NEXT:frame = [] // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = LoadFrameInst (:object) [y@foo]: object -// CHECK-NEXT: %1 = CallInst (:number) %0: object, %x(): number, empty: any, undefined: undefined +// CHECK-NEXT: %1 = CallInst (:number) %0: object, %x(): number, empty: any, 0: number // CHECK-NEXT: %2 = ReturnInst undefined: undefined // CHECK-NEXT:function_end diff --git a/test/Optimizer/function-analysis-construction-store.js b/test/Optimizer/function-analysis-construction-store.js index 4d90144db61..8550d1b7e83 100644 --- a/test/Optimizer/function-analysis-construction-store.js +++ b/test/Optimizer/function-analysis-construction-store.js @@ -33,7 +33,7 @@ function main() { // CHECK-NEXT: %0 = CreateFunctionInst (:object) %f(): undefined // CHECK-NEXT: %1 = LoadPropertyInst (:any) %0: object, "prototype": string // CHECK-NEXT: %2 = CreateThisInst (:object) %1: any, %0: object -// CHECK-NEXT: %3 = ConstructInst (:undefined) %0: object, %f(): undefined, empty: any, undefined: undefined +// CHECK-NEXT: %3 = ConstructInst (:undefined) %0: object, %f(): undefined, empty: any, 0: number // CHECK-NEXT: %4 = ReturnInst %2: object // CHECK-NEXT:function_end diff --git a/test/Optimizer/function-analysis-construction.js b/test/Optimizer/function-analysis-construction.js index 73b634788c6..5bef7a42450 100644 --- a/test/Optimizer/function-analysis-construction.js +++ b/test/Optimizer/function-analysis-construction.js @@ -32,7 +32,7 @@ function main() { // CHECK-NEXT: %0 = CreateFunctionInst (:object) %f(): undefined // CHECK-NEXT: %1 = LoadPropertyInst (:any) %0: object, "prototype": string // CHECK-NEXT: %2 = CreateThisInst (:object) %1: any, %0: object -// CHECK-NEXT: %3 = ConstructInst (:undefined) %0: object, %f(): undefined, empty: any, undefined: undefined +// CHECK-NEXT: %3 = ConstructInst (:undefined) %0: object, %f(): undefined, empty: any, 0: number // CHECK-NEXT: %4 = ReturnInst %2: object // CHECK-NEXT:function_end diff --git a/test/Optimizer/function-analysis-single-store.js b/test/Optimizer/function-analysis-single-store.js index f3f5db6a3e8..f3447b38d5c 100644 --- a/test/Optimizer/function-analysis-single-store.js +++ b/test/Optimizer/function-analysis-single-store.js @@ -30,7 +30,7 @@ function main(x) { // CHECK-NEXT:frame = [] // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = CreateFunctionInst (:object) %f(): undefined -// CHECK-NEXT: %1 = CallInst (:undefined) %0: object, %f(): undefined, empty: any, undefined: undefined +// CHECK-NEXT: %1 = CallInst (:undefined) %0: object, %f(): undefined, empty: any, 0: number // CHECK-NEXT: %2 = ReturnInst undefined: undefined // CHECK-NEXT:function_end diff --git a/test/Optimizer/inline-directive.js b/test/Optimizer/inline-directive.js index deba1705d7d..e7f5e4a49f0 100644 --- a/test/Optimizer/inline-directive.js +++ b/test/Optimizer/inline-directive.js @@ -25,7 +25,7 @@ // CHECK-NEXT:frame = [] // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = CreateFunctionInst (:object) %""(): number -// CHECK-NEXT: %1 = CallInst (:number) %0: object, %""(): number, empty: any, undefined: undefined +// CHECK-NEXT: %1 = CallInst (:number) %0: object, %""(): number, empty: any, 0: number // CHECK-NEXT: %2 = ReturnInst %1: number // CHECK-NEXT:function_end diff --git a/test/Optimizer/inline-recursive.js b/test/Optimizer/inline-recursive.js index a0ded7b80df..158f8a26a37 100644 --- a/test/Optimizer/inline-recursive.js +++ b/test/Optimizer/inline-recursive.js @@ -37,6 +37,6 @@ // CHECK-NEXT:frame = [] // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = LoadFrameInst (:object) [f@main]: object -// CHECK-NEXT: %1 = CallInst (:any) %0: object, %f(): any, empty: any, undefined: undefined +// CHECK-NEXT: %1 = CallInst (:any) %0: object, %f(): any, empty: any, 0: number // CHECK-NEXT: %2 = ReturnInst %1: any // CHECK-NEXT:function_end diff --git a/test/Optimizer/inline-unreachable-2.js b/test/Optimizer/inline-unreachable-2.js index da8f790e8e9..818e0872f53 100644 --- a/test/Optimizer/inline-unreachable-2.js +++ b/test/Optimizer/inline-unreachable-2.js @@ -26,7 +26,7 @@ // CHECK-NEXT:frame = [] // CHECK-NEXT:%BB0: // CHECK-NEXT: %0 = CreateFunctionInst (:object) %main(): undefined -// CHECK-NEXT: %1 = CallInst (:undefined) %0: object, %main(): undefined, empty: any, undefined: undefined +// CHECK-NEXT: %1 = CallInst (:undefined) %0: object, %main(): undefined, empty: any, 0: number // CHECK-NEXT: %2 = ReturnInst undefined: undefined // CHECK-NEXT:function_end