When CodeExtractor saves the result of InvokeInst at the first insertion point of the 'normal destination' basic block, this block can be omitted in the outlined region, so store is placed outside of the function. The suggested solution is to process saving outputs after creating exit stubs for new function, and stores will be placed in that blocks before return in this case.
Details
Diff Detail
Event Timeline
Thanks! This mostly looks good, and I believe it resolves llvm.org/PR40455.
lib/Transforms/Utils/CodeExtractor.cpp | ||
---|---|---|
1141 | Could you assert that the insertion point is in 'newFunction'? | |
unittests/Transforms/Utils/CodeExtractorTest.cpp | ||
200 | Are the 'entry' and 'cond.true' blocks needed to reproduce the issue? | |
228 | Is DT needed? |
lib/Transforms/Utils/CodeExtractor.cpp | ||
---|---|---|
1141 | At this point the extracted blocks are still in the old function, and exit stubs are created immediately in new function; so insertion point should be in newFunction or in one of extracted blocks. | |
unittests/Transforms/Utils/CodeExtractorTest.cpp | ||
200 | Agree that test can be simplified. | |
228 | It seems that dominator tree is only used to verify that all blocks are reachable from entry, so I think it can be safely removed from all CodeExtractor tests. |
Add assertion for the InsertPt
Remove DT construction from CodeExtractor tests
Simplify test
Thanks for doing this! LGTM with a simple change.
lib/Transforms/Utils/CodeExtractor.cpp | ||
---|---|---|
1142 | It looks like we always deref InsertPt below. Can we just define 'InsertBefore = &*InsertPt' once, and then use it in the assert? Also, it might be simpler to write InsertBefore->getFunction(). |
Could you assert that the insertion point is in 'newFunction'?