diff --git a/service/dedup-blocks/DedupBlocks.cpp b/service/dedup-blocks/DedupBlocks.cpp index 0b348e9c1c8..745716ec81a 100644 --- a/service/dedup-blocks/DedupBlocks.cpp +++ b/service/dedup-blocks/DedupBlocks.cpp @@ -870,7 +870,10 @@ class DedupBlocksImpl { auto fwd_ir_it = IRList::iterator(std::prev(it.base())); split_block = cfg.split_block(block, fwd_ir_it); } - copy_over_source_block(block, split_block); + // add a source block in the beginning if there isn't one already + if (split_block->begin()->type != MFLOW_SOURCE_BLOCK) { + copy_over_source_block(block, split_block); + } continue; } @@ -897,10 +900,13 @@ class DedupBlocksImpl { } auto cfg_it = block->to_cfg_instruction_iterator(fwd_it); - // Split the block + // Split the block and add a source block in the beginning if there + // isn't one already auto split_block = cfg.split_block(cfg_it); + if (split_block->begin()->type != MFLOW_SOURCE_BLOCK) { + copy_over_source_block(block, split_block); + } - copy_over_source_block(block, split_block); TRACE(DEDUP_BLOCKS, 4, "split_postfix: split block : old = %zu, new = %zu", block->id(), split_block->id()); diff --git a/test/integ/SourceBlocksDedupTest.cpp b/test/integ/SourceBlocksDedupTest.cpp index 8d8ad6e491b..7b733a89e1d 100644 --- a/test/integ/SourceBlocksDedupTest.cpp +++ b/test/integ/SourceBlocksDedupTest.cpp @@ -536,7 +536,7 @@ TEST_F(SourceBlocksDedupTest, source_blocks_chain) { succs: (goto B6)\n\ Block B6:\n\ preds: (goto B3) (goto B4) (goto B5)\n\ - SOURCE-BLOCKS: Lcom/facebook/redextest/SourceBlocksDedupTest;.useSwitch:()I@4294967295() Lcom/facebook/redextest/SourceBlocksDedupTest;.useSwitch:()I@100() " + SOURCE-BLOCKS: Lcom/facebook/redextest/SourceBlocksDedupTest;.useSwitch:()I@100() " "Lcom/facebook/redextest/SourceBlocksDedupTest;.useSwitch:()I@100() Lcom/facebook/redextest/SourceBlocksDedupTest;.useSwitch:()I@100()\n\ POSITION: Lcom/facebook/redextest/SourceBlocksDedupTest;.useSwitch:()I(SourceBlocksDedupTest.java:22)\n\ OPCODE: INVOKE_VIRTUAL v4, Lcom/facebook/redextest/SourceBlocksDedupTest;.someFunc:()V\n\