[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
Tue Dec 19 04:08:13 PST 2023


================
@@ -1096,6 +1096,50 @@ Value *InstCombinerImpl::foldUsingDistributiveLaws(BinaryOperator &I) {
   return SimplifySelectsFeedingBinaryOp(I, LHS, RHS);
 }
 
+bool InstCombinerImpl::matchSymmetricPhiNodesPair(PHINode *LHS, PHINode *RHS) {
+
+  if (LHS->getNumIncomingValues() != 2 || RHS->getNumIncomingValues() != 2)
+    return false;
+
+  BasicBlock *B0 = LHS->getIncomingBlock(0);
+  BasicBlock *B1 = LHS->getIncomingBlock(1);
+
+  bool RHSContainB0 = RHS->getBasicBlockIndex(B0) != -1;
+  bool RHSContainB1 = RHS->getBasicBlockIndex(B1) != -1;
+
+  if (!RHSContainB0 || !RHSContainB1)
----------------
sun-jacobi wrote:

Does this mean we need to add a check to see if the phi nodes are in the same basic block?

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


More information about the llvm-commits mailing list