[llvm] [InstCombine] Try to freely invert phi nodes (PR #80804)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 00:48:52 PST 2024


================
@@ -2375,6 +2375,33 @@ Value *InstCombiner::getFreelyInvertedImpl(Value *V, bool WillInvertAllUses,
     }
   }
 
+  if (PHINode *PN = dyn_cast<PHINode>(V)) {
+    SmallVector<std::pair<Value *, BasicBlock *>, 8> IncomingValues;
+    for (Use &U : PN->operands()) {
+      BasicBlock *IncomingBlock = PN->getIncomingBlock(U);
+      if (isa<PHINode>(U.get()))
+        return nullptr;
+      Value *NewIncomingVal =
+          getFreelyInvertedImpl(U.get(), /*WillInvertAllUses=*/false,
+                                /*Builder=*/nullptr, DoesConsume, Depth);
----------------
nikic wrote:

The general convention is that recursive analysis on phi nodes should reset Depth to `MaxAnalysisRecursionDepth - 1`.

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


More information about the llvm-commits mailing list