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

via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 21 05:29:13 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);
----------------
sun-jacobi wrote:

Oh, it works. Thanks a lot !

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


More information about the llvm-commits mailing list