- 
                Notifications
    
You must be signed in to change notification settings  - Fork 818
 
Optimize binary operators with equal children even if side effect #7460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c3d265b
              4362844
              b684076
              f7b9d49
              9010408
              256ce96
              844ec20
              e491494
              1b76476
              4a3bdf0
              3967445
              b240e1d
              53c9116
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 
          
            
          
           | 
    @@ -448,40 +448,15 @@ | |||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| (module | ||||||||||||||||||||||||||||
| ;; Return call to self with different params, then stop evaluating. | ||||||||||||||||||||||||||||
| ;; CHECK: (type $0 (func (param i32))) | ||||||||||||||||||||||||||||
| ;; CHECK: (type $0 (func)) | ||||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||||
| ;; CHECK: (type $1 (func)) | ||||||||||||||||||||||||||||
| ;; CHECK: (type $1 (func (param i32))) | ||||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||||
| ;; CHECK: (import "env" "import" (func $import (type $1))) | ||||||||||||||||||||||||||||
| ;; CHECK: (import "env" "import" (func $import (type $0))) | ||||||||||||||||||||||||||||
| (import "env" "import" (func $import)) | ||||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||||
| ;; CHECK: (global $g (mut i32) (i32.const 42)) | ||||||||||||||||||||||||||||
| (global $g (mut i32) (i32.const 0)) | ||||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||||
| ;; CHECK: (export "test" (func $test_2)) | ||||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||||
| ;; CHECK: (func $test (type $0) (param $0 i32) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (global.set $g | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (local.get $0) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (if | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (i32.eq | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (local.get $0) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (i32.const 42) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (then | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (call $import) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (else | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (return_call $test | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (i32.add | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (local.get $0) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (i32.const 1) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This optimization looks wrong - perhaps related to the issue with  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll check this as soon as possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated the code and tests as you suggested.  However, it still the same for the  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One way to debug it is to see which part of this PR causes that change. Try doing just one part of the PR and seeing if it happens. Sort of like bisection. Once we know the specific part of the PR, figuring it out may be simpler. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After debugging, the issue was caused by the logic handling the case        case EqInt32:    // Issue Caused Here
      ... fallthrough...
        return getDroppedChildrenAndAppend(
          binary, LiteralUtils::makeFromInt32(1, Type::i32, *getModule()));In more detail, the issue lies in the logic dealing with the    1 case EqInt32: {
  2 if (effects(binary->left).hasSideEffects()) {
  3   if (effects(binary->right).hasSideEffects()) {
  4     return getDroppedChildrenAndAppend(
  5       binary, LiteralUtils::makeFromInt32(1, Type::i32, *getModule()));
  6   } else {
  7     // This part causes that issue!
  8     // If we replace it to `return nullptr`, that's ok
  9     return getDroppedChildrenAndAppend(
 10       binary->left, LiteralUtils::makeFromInt32(1, Type::i32, *getModule()));
 11   }
 12 } else { 
 13   return getDroppedChildrenAndAppend(
 14     binary->right, LiteralUtils::makeFromInt32(1, Type::i32, *getModule()));
 15 }
 16 return LiteralUtils::makeFromInt32(1, Type::i32, *getModule());
 17 };
The logic in the  In my understanding, the code logic return getDroppedChildrenAndAppend(
  binary, LiteralUtils::makeFromInt32(1, Type::i32, *getModule()));is able to handle all the other cases, such as  Is it my PR that is wrong, or does the wasm2js check really need to be updated? Could you please check it carefully? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what's wrong. Your code looks right. Perhaps see if the optimizations in ctor-eval matter, binaryen/src/tools/wasm-ctor-eval.cpp Lines 1467 to 1479 in c528c7e 
 I would check if removing them makes a difference.  | 
||||||||||||||||||||||||||||
| (func $test (export "test") (param i32) | ||||||||||||||||||||||||||||
| (global.set $g | ||||||||||||||||||||||||||||
| (local.get 0) | ||||||||||||||||||||||||||||
| 
        
          
        
         | 
    @@ -506,24 +481,11 @@ | |||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||||
| ;; CHECK: (func $test_2 (type $0) (param $0 i32) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (if | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (i32.eq | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (local.tee $0 | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (i32.const 42) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (i32.const 42) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (then | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (call $import) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (else | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (return_call $test | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (i32.add | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (local.get $0) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (i32.const 1) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK: (export "test" (func $test_2)) | ||||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||||
| ;; CHECK: (func $test_2 (type $1) (param $0 i32) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (local.set $0 | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (i32.const 42) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: (call $import) | ||||||||||||||||||||||||||||
| ;; CHECK-NEXT: ) | ||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.