[llvm] [InstCombine] Fold dependent IVs (PR #81151)

via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 09:56:01 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))) ||
----------------
goldsteinn wrote:

I would think just about any binop would work here: https://alive2.llvm.org/ce/z/nA8yg3 (for sub/xor).

https://github.com/llvm/llvm-project/pull/81151


More information about the llvm-commits mailing list