[llvm] [SimplifyCFG] Increase budget for FoldTwoEntryPHINode() if the branch is unpredictable. (PR #98495)

Tianqing Wang via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 18 11:27:57 PDT 2024


================
@@ -419,6 +419,11 @@ class TargetTransformInfo {
   /// this factor, it is very likely to be predicted correctly.
   BranchProbability getPredictableBranchThreshold() const;
 
+  // Returns an integer indicating how aggressive the target wants for
+  // eliminating unpredictable branches. A zero return value means extra
+  // optimization applied to them should be minimal.
+  unsigned getBranchMispredictPenalty() const;
----------------
tianqingw wrote:

I'm actually not sure about it and I'd like to have more discussion. IMO this is still very new and more use cases are needed to determine what's the best way for optimizations to leverage it. But for the time being, using it as an latency seems to be good.

Not sure about InstructionCost. With InstructionCost we need to:
1) Define what Invalid represents. Perhaps just means unknown and no extra optimization.
2) Define what 0 represents, and how it differs from Invalid. Maybe a (potentially hypothetical) hardware with very cheap branching, in which case we need to avoid folding branches at best effort? I can't think about a practical case yet.

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


More information about the llvm-commits mailing list