[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
Sun Nov 24 18:34:18 PST 2024
================
@@ -7854,6 +7877,35 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
if (HoistCommon &&
hoistCommonCodeFromSuccessors(BI, !Options.HoistCommonInsts))
return requestResimplify();
+
+ if (BI && HoistLoadsStoresWithCondFaulting &&
+ Options.HoistLoadsStoresWithCondFaulting &&
+ isProfitableToSpeculate(BI, std::nullopt, TTI)) {
+ 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) {
+ return false;
+ }
+ SpeculatedConditionalLoadsStores.push_back(&I);
+ }
+ }
+ return !SpeculatedConditionalLoadsStores.empty();
+ };
+
+ if (CanSpeculateConditionalLoadsStores()) {
----------------
KanRobert wrote:
It seems the lambda is used once, maybe
```
bool CanSpeculateConditionalLoadsStores = <your lambda>();
```
looks better?
https://github.com/llvm/llvm-project/pull/108812
More information about the llvm-commits
mailing list