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

Kai Luo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 13 02:04:11 PST 2022


lkail added a comment.

> could we prevent SimplifyCFG from forming these selects in the first place? Is the cost model broken in some way or just not accurate enough?

Sorry I have missed this one. IIUC, `FoldTwoEntryPHINode` should be the place performing branch to select transformation. `FoldTwoEntryPHINode` checks

  // Okay, we found that we can merge this two-entry phi node into a select.                                                                                                                  
  // Doing so would require us to fold *all* two entry phi nodes in this block.                                                                                                               
  // At some point this becomes non-profitable (particularly if the target                                                                                                                    
  // doesn't support cmov's).  Only do this transformation if there are two or                                                                                                                
  // fewer PHI nodes in this block.                                                                                                                                                           
  unsigned NumPhis = 0;                                                                                                                                                                       
  for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++NumPhis, ++I)                                                                                                                 
    if (NumPhis > 2)                                                                                                                                                                          
      return false;

which looks not accurate enough.

Is it appropriate to improve this heuristic rather than in CGP, since SimplifyCFGPass looks like a canonical pass to me and also we lack subtarget info(which includes mispredict penalty) in SimplifyCFGPass?


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