[PATCH] D113872: [CGP] Handle select instructions relying on the same condition

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 14 14:59:38 PST 2022


lebedev.ri added a comment.

I see. Well, i actually thought about that before. Basic idea is to rely on `MCSchedModel`'s
`MispredictPenalty` instead of "hardcoded" `TwoEntryPHINodeFoldingThreshold`. That sounds easy.

I guess the back-of-the-napkin math suggests that (assuming unpredictable branch),

- in 50% of cases, we pay the average cost of both of the blocks
- in other 50% of cases, we pay the average cost of both of the blocks, then the misprediction penalty, then again the average cost of both of the blocks

So roughly the actual profitability check should be

  cost(bb0) + cost(bb1) + cost(selects) <= ((1*((cost(bb0) + cost(bb1))/2) + 0*MispredictPenalty) + (2*((cost(bb0) + cost(bb1))/2) + MispredictPenalty))/2
  cost(bb0) + cost(bb1) + cost(selects) <= 0.75*(cost(bb0) + cost(bb1)) + 0.5*MispredictPenalty

I think the main problem is that we'd effectively need a MCA-like thingy
for IR instructions, because it is not generally correct to consider that the latency of two instructions
is a sum of their latencies, because they could be independent and could have been executed in parallel.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113872



More information about the llvm-commits mailing list