[all-commits] [llvm/llvm-project] fddc2c: [SimplifyCFG] Simplify identical predecessors (#17...

Kunqiu Chen via All-commits all-commits at lists.llvm.org
Wed Mar 11 23:59:07 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: fddc2c05b8153c15d565135ba9b394a14f2d5e87
      https://github.com/llvm/llvm-project/commit/fddc2c05b8153c15d565135ba9b394a14f2d5e87
  Author: Kunqiu Chen <camsyn at foxmail.com>
  Date:   2026-03-12 (Thu, 12 Mar 2026)

  Changed paths:
    M llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    A llvm/test/Transforms/SimplifyCFG/dup-preds.ll
    M llvm/test/Transforms/SimplifyCFG/switch-dup-bbs.ll

  Log Message:
  -----------
  [SimplifyCFG] Simplify identical predecessors (#173022)

When >1 predecessors of BB are identical, try to merge them into ONE.


---

Here is a simplified example (`sink` and `bb*`s share the same
predecessor `entry`, hindering the existing uncond br folding to
optimize such a case):
```diff
- entry:
-   switch to %br1, %br2, %br3, %sink
- bb1:
-   br label %sink
- bb2:
-   br label %sink
- bb3:
-   br label %sink
- sink:
-   %ret = phi i8 [ 0, %bb1 ], [ 0, %bb2 ], [ 0, %bb3 ], [ -1, %entry ]
+ entry:
+   switch to %br1, %sink
+ bb1:
+   br label %sink
+ sink:
+   %ret = phi i8 [ 0, %bb1 ], [ -1, %entry ]
```

Actually, `simplifyDuplicateSwitchArms` did similar things in a very
limited scope (only for switch arms), this patch generalizes its logic
to handle any BB with >1 identical predecessors.

---


This PR lands the
[discussion](https://github.com/dtcxzyw/llvm-opt-benchmark/pull/3033#discussion_r2506973226),
i.e., "merge identical predecessor bottom to up", and implements the
suggestion of
https://github.com/llvm/llvm-project/pull/114262#issuecomment-2448140669.

- IR diff: https://github.com/dtcxzyw/llvm-opt-benchmark/pull/3537
- CompTime Impact:
https://github.com/dtcxzyw/llvm-opt-benchmark/pull/3538



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list