@@ -58,26 +58,6 @@ bool HasVarInIndicesOrValue(const ir::Expr& block, const ir::Var& var) {
5858 return var_use.size () > 0 ;
5959}
6060
61- // Check whether the block has an inplace update (e.g. a[i] = a[i] + b[i])
62- // by comparing between the block's read_buffers and write_buffers.
63- bool HasInplaceUpdate (const ir::Expr& block) {
64- auto * schedule_block = block.As <ir::ScheduleBlockRealize>()
65- ->schedule_block .As <ir::ScheduleBlock>();
66- std::set<std::string> read_buffer_names;
67- for (auto & buffer_range : schedule_block->read_buffers ) {
68- read_buffer_names.insert (
69- buffer_range.As <ir::_BufferRange_>()->buffer .as_buffer ()->name );
70- }
71- for (auto & buffer_range : schedule_block->write_buffers ) {
72- auto & write_buffer_name =
73- buffer_range.As <ir::_BufferRange_>()->buffer .as_buffer ()->name ;
74- if (read_buffer_names.count (write_buffer_name) > 0 ) {
75- return true ;
76- }
77- }
78- return false ;
79- }
80-
8161// Check whether the block is writing to a buffer whose scope is smaller than
8262// the For node's scope.
8363bool HasWriteToSmallerScope (const ir::Expr& block, const ir::For* for_node) {
@@ -112,7 +92,7 @@ struct InvariantLoopEliminator : public ir::IRMutator<> {
11292 ir::Var loop_var = node->loop_var ;
11393 for (auto & block : child_blocks) {
11494 if (HasVarInIndicesOrValue (block, loop_var)) return ;
115- if (HasInplaceUpdate (block)) return ;
95+ if (ir::analyzer::IsReductionSBlock (block)) return ;
11696 if (node->is_binded ()) {
11797 if (HasWriteToSmallerScope (block, node)) return ;
11898 if (!ir::analyzer::GetConsumerSBlocks (block, *root_).empty ()) return ;
0 commit comments