[llvm] [SimplifyCFG] Hoist out implied conditions from successor (PR #158773)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 17 14:06:19 PDT 2025
================
@@ -1853,6 +1853,113 @@ static void hoistConditionalLoadsStores(
}
}
+static std::optional<bool>
+visitConditions(Value *V, const Value *baseCond, const BasicBlock *contextBB,
+ SmallVectorImpl<Instruction *> &impliedConditions,
+ const DataLayout &DL) {
+ if (!isa<Instruction>(V))
+ return std::nullopt;
+
+ Instruction *I = cast<Instruction>(V);
+ // we only care about conditions in the same basic block
+ if (contextBB != I->getParent())
+ return std::nullopt;
+
+ std::optional<bool> Imp = isImpliedCondition(V, baseCond, DL);
+ // TODO: Handle negated condition case.
+ if (Imp != true)
+ return std::nullopt;
+
+ std::optional<bool> LHS = visitConditions(I->getOperand(0), baseCond,
----------------
nikic wrote:
I think this code is assuming that the instruction is an `and` without actually checking that?
Please add a test with e.g. `or`.
https://github.com/llvm/llvm-project/pull/158773
More information about the llvm-commits
mailing list