[llvm] [X86, SimplifyCFG] Support hoisting load/store with conditional faulting (Part II) (PR #108812)
Shengchen Kan via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 07:14:37 PDT 2024
================
@@ -7815,6 +7835,33 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
if (HoistCommon &&
hoistCommonCodeFromSuccessors(BI, !Options.HoistCommonInsts))
return requestResimplify();
+
+ if (BI && HoistLoadsStoresWithCondFaulting &&
+ Options.HoistLoadsStoresWithCondFaulting) {
+ SmallVector<Instruction *, 2> SpeculatedConditionalLoadsStores;
+ auto CanSpeculateConditionalLoadsStores = [&]() {
+ for (auto *Succ : successors(BB)) {
+ for (Instruction &I : *Succ) {
+ if (I.isTerminator()) {
+ if (I.getNumSuccessors() > 1)
+ return false;
+ continue;
+ } else if (!isSafeCheapLoadStore(&I, TTI) ||
+ SpeculatedConditionalLoadsStores.size() ==
+ HoistLoadsStoresWithCondFaultingThreshold) {
----------------
KanRobert wrote:
I think we should consider branch probability for this, e.g. `isProfitableToSpeculate`. If A has two successors B and C, it's not profitable to execute more instructions to eliminate the branch if the branch is well-predicated and the load/store comes from the unlikely successor.
https://github.com/llvm/llvm-project/pull/108812
More information about the llvm-commits
mailing list