[PATCH] D106650: [SimplifyCFG] Don't speculatively execute BB if it's predictably not taken

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 24 04:08:59 PDT 2021


spatel accepted this revision.
spatel added a comment.
This revision is now accepted and ready to land.

LGTM



================
Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:2380-2384
+      BranchProbability BITrueProb =
+          BranchProbability::getBranchProbability(TWeight, TWeight + FWeight);
+      BranchProbability BIThenProb =
+          !Invert ? BITrueProb : BITrueProb.getCompl();
+      BranchProbability BIEndProb = BIThenProb.getCompl();
----------------
I think it would be easier to read without the potential double complement:

```
    if (BI->extractProfMetadata(TWeight, FWeight) && (TWeight + FWeight) != 0) {
      uint64_t EndWeight = Invert ? TWeight : FWeight;
      BranchProbability BIEndProb =
          BranchProbability::getBranchProbability(EndWeight, TWeight + FWeight);

```
(although the meaning of `Invert` seems reversed from the code example in the function comment at line 2331)


================
Comment at: llvm/test/Transforms/SimplifyCFG/speculatively-execute-block-profmd.ll:219
 
 !0 = !{!"branch_weights", i32 99, i32 1}
 !1 = !{}
----------------
Add one more negative test to verify that we are respecting the TTI setting? It would need a different metadata - { 98, 2 } or similar.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106650



More information about the llvm-commits mailing list