[llvm] [LICM][WIP] Make an integer version of hoistFPAssociation. (PR #67736)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 2 12:32:30 PDT 2023
================
@@ -2719,6 +2728,65 @@ static bool hoistFPAssociation(Instruction &I, Loop &L,
return true;
}
+static bool hoistIntAssociation(Instruction &I, Loop &L,
+ ICFLoopSafetyInfo &SafetyInfo,
+ MemorySSAUpdater &MSSAU, AssumptionCache *AC,
+ DominatorTree *DT) {
+ using namespace PatternMatch;
+ Value *VariantOp = nullptr, *InvariantOp = nullptr;
+
+ if (!match(&I, m_Mul(m_Value(VariantOp), m_Value(InvariantOp))))
+ return false;
+ if (L.isLoopInvariant(VariantOp))
+ std::swap(VariantOp, InvariantOp);
+ if (L.isLoopInvariant(VariantOp) || !L.isLoopInvariant(InvariantOp))
+ return false;
+ Value *Factor = InvariantOp;
+
+ // First, we need to make sure we should do the transformation.
+ SmallVector<Use *> Changes;
+ SmallVector<BinaryOperator *> Worklist;
+ if (BinaryOperator *VariantBinOp = dyn_cast<BinaryOperator>(VariantOp))
+ Worklist.push_back(VariantBinOp);
+ while (!Worklist.empty()) {
+ BinaryOperator *BO = Worklist.pop_back_val();
+ if (!BO->hasOneUse())
+ return false;
+ BinaryOperator *Op0, *Op1;
+ if (match(BO, m_Add(m_BinOp(Op0), m_BinOp(Op1)))) {
+ Worklist.push_back(Op0);
+ Worklist.push_back(Op1);
+ continue;
+ }
+ if (BO->getOpcode() != Instruction::Mul || L.isLoopInvariant(BO))
+ return false;
+ Use &U0 = BO->getOperandUse(0);
----------------
preames wrote:
In principle, we should match the entire mul reduce tree, and perform the transform if *any* of the operands are loop invariant. Again, this is really a generalization on the prior code as well.
https://github.com/llvm/llvm-project/pull/67736
More information about the llvm-commits
mailing list