-
Notifications
You must be signed in to change notification settings - Fork 648
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
InstSimplify: optimize equality comparisons based on type
Summary: Strict equality of non-overlapping types doesn't need to be performed. Loose equality is trickier, so we constrain ourselves only to comparing against `null|undefined`. Reviewed By: davedets Differential Revision: D67905084 fbshipit-source-id: ca0b7915973962de66ebddd9ecf61981e51d60c0
- Loading branch information
1 parent
2641863
commit d6c8fe6
Showing
2 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: %hermesc -O -dump-ir %s | %FileCheckOrRegen %s | ||
|
||
// Test equality comparisons against null|undefined when the other type can | ||
// be neither type. | ||
|
||
let o = {}; | ||
sink = o !== null; | ||
sink = o === null; | ||
sink = o != null; | ||
sink = o == null; | ||
sink = undefined !== o; | ||
sink = undefined === o; | ||
sink = undefined != o; | ||
sink = undefined == o; | ||
|
||
let n = +glob; | ||
sink = n !== undefined; | ||
sink = n === undefined; | ||
sink = n != undefined; | ||
sink = n == undefined; | ||
sink = null !== n; | ||
sink = null === n; | ||
sink = null != n; | ||
sink = null == n; | ||
|
||
// Auto-generated content below. Please do not modify manually. | ||
|
||
// CHECK:function global(): boolean | ||
// CHECK-NEXT:%BB0: | ||
// CHECK-NEXT: StorePropertyLooseInst true: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst false: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst true: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst false: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst true: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst false: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst true: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst false: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: %8 = TryLoadGlobalPropertyInst (:any) globalObject: object, "glob": string | ||
// CHECK-NEXT: %9 = AsNumberInst (:number) %8: any | ||
// CHECK-NEXT: StorePropertyLooseInst true: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst false: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst true: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst false: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst true: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst false: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst true: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: StorePropertyLooseInst false: boolean, globalObject: object, "sink": string | ||
// CHECK-NEXT: ReturnInst false: boolean | ||
// CHECK-NEXT:function_end |