You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
flat lowering: a block merge should not keep a returned Result in a stack slot #4570
Each return Result::Err(e) in a function builds its Result in a stack slot of its own. When two such returns end in blocks that differ only in which slot they use, MLIR's greedy rewrite driver merges the two blocks. The merged block takes the slot as a block argument, which becomes a phi of pointers in LLVM IR. LLVM's SROA cannot move a slot that is written through such a phi into registers. So the function keeps its stack slots, grows larger, and LLVM does not inline it.
PR #4485 (for #4484) avoids the merge: four lowering passes no longer merge blocks in functions where they have no work. But the speedup depends on that. A new lowering pass that merges blocks would bring the stack slots back.
Fix
Make the flat lowering build the returned value so that a block merge does no harm. Two possible ways:
Build the returned value as an SSA value, not in a stack slot.
Use one return slot for each function, which every return writes.
With either one, the merged blocks have no slot operand that differs, and SROA can remove the slot.
How to check
tests/optimizations/pass/a_function_with_several_question_marks_keeps_its_result_in_registers.vx checks that Reader$header keeps no alloca after opt. After this fix, that check should still pass with the block merging of the greedy driver turned back on in the four passes.
Activity