taichi/analysis/last_store_or_atomic.cpp
// Only if **both** branches finally store the variable with exactly the same
// data, can we forward it to the local load statement.
Only if **both** branches finally store the variable with exactly the same
data, can we forward it to the local load statement.
Only if ** both ** branches finally store the variable with exactly the same data can we forward it to the local load statement .
void visit(IfStmt *if_stmt) override {
    std::pair<bool, Stmt *> true_branch(true, nullptr);
    if (if_stmt->true_statements) {
      true_branch = run(if_stmt->true_statements.get(), var_);
    }
    std::pair<bool, Stmt *> false_branch(true, nullptr);
    if (if_stmt->false_statements) {
      false_branch = run(if_stmt->false_statements.get(), var_);
    }
    auto true_stmt = true_branch.second;
    auto false_stmt = false_branch.second;
    if (!true_branch.first || !false_branch.first) {
      is_valid_ = false;
    } else if (true_stmt == nullptr && false_stmt == nullptr) {
      return;
    } else if (true_stmt == nullptr || false_stmt == nullptr) {
      is_valid_ = false;
    } else {
      TI_ASSERT(true_stmt->is<LocalStoreStmt>());
      TI_ASSERT(false_stmt->is<LocalStoreStmt>());
      if (true_stmt->as<LocalStoreStmt>()->val !=
          false_stmt->as<LocalStoreStmt>()->val) {
        is_valid_ = false;
      } else {
        is_valid_ = true;
        result_ = true_stmt;  
      }
    }
  }
void visit ( IfStmt * if_stmt ) override { std :: pair < bool , Stmt * > true_branch ( true , nullptr ) ; if ( if_stmt -> true_statements ) { true_branch = run ( if_stmt -> true_statements . get ( ) , var_ ) ; } std :: pair < bool , Stmt * > false_branch ( true , nullptr ) ; if ( if_stmt -> false_statements ) { false_branch = run ( if_stmt -> false_statements . get ( ) , var_ ) ; } auto true_stmt = true_branch . second ; auto false_stmt = false_branch . second ; if ( ! true_branch . first || ! false_branch . first ) { is_valid_ = false ; } else if ( true_stmt == nullptr && false_stmt == nullptr ) { return ; } else if ( true_stmt == nullptr || false_stmt == nullptr ) { is_valid_ = false ; } else { TI_ASSERT ( true_stmt -> is < LocalStoreStmt > ( ) ) ; TI_ASSERT ( false_stmt -> is < LocalStoreStmt > ( ) ) ; if ( true_stmt -> as < LocalStoreStmt > ( ) -> val != false_stmt -> as < LocalStoreStmt > ( ) -> val ) { is_valid_ = false ; } else { is_valid_ = true ; result_ = true_stmt ; } } }
Only if **both** branches finally store the variable with exactly the same
data, can we forward it to the local load statement.
Only if ** both ** branches finally store the variable with exactly the same data can we forward it to the local load statement .
// the default return value: valid, no stores // create a new LocalStoreForwarder instance // at least one branch finally modifies the variable without storing // both branches don't modify the variable // only one branch modifies the variable // two branches finally store the variable differently // same as false_stmt