[llvm] SimplifyCFG: fold trivial non-empty blocks with safe instructions (PR #180350)

Ridham Khurana via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 7 07:39:58 PST 2026


rmkhurana28 wrote:

@nikic 
Hi Nikita, thanks for the feedback. Regarding the value of this patch: currently, SimplifyCFG misses trivial "middle-man" blocks that contain a single safe arithmetic or memory operation. This patch extends the folder to catch these cases, reducing branch overhead and improving IR canonicalization for subsequent passes like the Loop Optimizer and GlobalDCE.
I've manually reviewed the implementation to ensure it remains conservative,, specifically sticking to single-predecessor blocks to avoid code duplication. I have also updated the patch to ensure we correctly move debug and lifetime markers into the predecessor during the splice, making the transformation fully metadata-preserving. The stability of this logic has been verified against the full ninja check-llvm suite.

Regarding AI tool usage (per the LLVM AI tool usage policy): AI tools were used mainly for drafting or rephrasing natural-language text (e.g. comment wording, PR description phrasing, explanations). All algorithmic decisions, safety analysis, IR-transformation logic, and test cases were written, reasoned about, and validated manually by me. The implementation logic is my own, and I have personally reviewed and tested the patch and verified that it behaves as intended.

Please let me know if any additional clarification is needed.


https://github.com/llvm/llvm-project/pull/180350


More information about the llvm-commits mailing list