[llvm] [InstCombine] fold (Binop phi(a, b) phi(b, a)) -> (Binop a, b) while Binop is commutative. (PR #75765)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 21 05:23:08 PST 2023


================
@@ -1096,6 +1096,53 @@ Value *InstCombinerImpl::foldUsingDistributiveLaws(BinaryOperator &I) {
   return SimplifySelectsFeedingBinaryOp(I, LHS, RHS);
 }
 
+std::optional<std::pair<Value *, Value *>>
+InstCombinerImpl::matchSymmetricPhiNodesPair(PHINode *LHS, PHINode *RHS) {
+
+  if (LHS->getParent() != RHS->getParent())
+    return std::nullopt;
+
+  if (LHS->getNumIncomingValues() < 2)
+    return std::nullopt;
+
+  BasicBlock *B0 = LHS->getIncomingBlock(0);
+  Value *N1 = LHS->getIncomingValueForBlock(B0);
----------------
nikic wrote:

Doesn't writing literally that work?

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


More information about the llvm-commits mailing list