[llvm] [InstCombine] Fold dependent IVs (PR #81151)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 13 09:51:19 PST 2024
================
@@ -1378,6 +1378,47 @@ static Value *simplifyUsingControlFlow(InstCombiner &Self, PHINode &PN,
return nullptr;
}
+// Fold iv = phi(start, iv.next = iv2.next + start)
+// where iv2 = phi(iv2.start, iv2.next = iv2 + iv2.step)
+// to iv = iv2 + start
+static Value *foldDependentIVs(PHINode &PN, IRBuilderBase &Builder) {
+ BasicBlock *BB = PN.getParent();
+ if (PN.getNumIncomingValues() != 2)
+ return nullptr;
+
+ Value *Start;
+ Instruction *IvNext;
+ BinaryOperator *Iv2Next;
+ auto MatchOuterIV = [&](Value *V1, Value *V2) {
+ if (match(V2, m_c_Add(m_Specific(V1), m_BinOp(Iv2Next))) ||
+ match(V2, m_PtrAdd(m_Specific(V1), m_BinOp(Iv2Next)))) {
----------------
goldsteinn wrote:
This will work for any `GPE`, not just `i8`, no?
https://github.com/llvm/llvm-project/pull/81151
More information about the llvm-commits
mailing list