[PATCH] D148514: [BranchFolding] Remove redundant conditional branch.

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 17 20:37:57 PDT 2023


goldstein.w.n added inline comments.


================
Comment at: llvm/lib/CodeGen/BranchFolding.cpp:1676
+  // BB2: Fallthrough or explicit branch to BB3
+  if (!CurUnAnalyzable && !PriorUnAnalyzable && MBB->pred_size() == 1) {
+    // If the our predecessor has a conditional branch to other block and
----------------
Instead of only 1 pred, you could check that all predecessors share the conditions?


================
Comment at: llvm/lib/CodeGen/BranchFolding.cpp:1679
+    // fallthrough or jump to us
+    if (PriorTBB && PriorTBB != MBB && (!PriorFBB || PriorFBB == MBB)) {
+      // and our block is branch only and has the same conditional branch
----------------
There is more than just this 1 case no?

IIUC you have
```
BB1 Cond0
        T -> Narian
        F -> BB2

BB2 Cond0
       T -> Narnia
       F -> BB3
---
BB1 Cond0
      T -> Narnia
      F -> BB2
BB2 -> BB3
```

But you could also have:

1)
```
BB1 Cond0
        T -> BB2
        F -> Narian

BB2 Cond0
       T -> BB3
       F -> Narnai
---
BB1 Cond0
      T -> BB2
      F -> Narnia
BB2 -> BB3
```

2)
```
BB1 Cond0
        T -> Narian
        F -> BB2

BB2 Cond0
       T -> BB3
       F -> Narnai
---
BB1 Cond0
      T -> Narnia
      F -> BB2
BB2 -> Narnia
```

3)
```
BB1 Cond0
        T -> Narian
        F -> BB2

BB2 Cond0
       T -> Narnia
       F -> BB3
---
BB1 Cond0
      T -> Narnia
      F -> BB2
BB2 -> BB3
```

In which could it would really just be that one of `PriorTBB` or `PriorFBB` equals `MBB` then where `MBB` goes based on which.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148514/new/

https://reviews.llvm.org/D148514



More information about the llvm-commits mailing list