[llvm] 5ec2b75 - [Instruction] Speculatively undo isIdenticalToWhenDefined() PHI handling changes

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 29 09:39:20 PDT 2020


Author: Roman Lebedev
Date: 2020-08-29T19:38:57+03:00
New Revision: 5ec2b757cc7d37ff0d03b36ee863b0962fe78108

URL: https://github.com/llvm/llvm-project/commit/5ec2b757cc7d37ff0d03b36ee863b0962fe78108
DIFF: https://github.com/llvm/llvm-project/commit/5ec2b757cc7d37ff0d03b36ee863b0962fe78108.diff

LOG: [Instruction] Speculatively undo isIdenticalToWhenDefined() PHI handling changes

The stage2-stage3 differences persist even without instcombine-based
PHI CSE, so this is the only possible reason.

Added: 
    

Modified: 
    llvm/lib/IR/Instruction.cpp
    llvm/lib/Transforms/Utils/Local.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index e1472a792f44..3a67185bef31 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -483,33 +483,18 @@ bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const {
   if (getNumOperands() == 0 && I->getNumOperands() == 0)
     return haveSameSpecialState(this, I);
 
-  // PHI nodes are special.
-  if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
-    const PHINode *otherPHI = cast<PHINode>(I);
-    // PHI nodes don't necessarily have their operands in the same order,
-    // so we shouldn't just compare ranges of incoming blocks/values.
-
-    // If both PHI's are in the same basic block, which is the most interesting
-    // case, we know they must have identical predecessor list,
-    // so we only need to check the incoming values.
-    if (thisPHI->getParent() == otherPHI->getParent()) {
-      return all_of(thisPHI->blocks(), [thisPHI, otherPHI](BasicBlock *PredBB) {
-        return thisPHI->getIncomingValueForBlock(PredBB) ==
-               otherPHI->getIncomingValueForBlock(PredBB);
-      });
-    }
-
-    // Otherwise, let's just naively compare operands/blocks.
-    return std::equal(op_begin(), op_end(), I->op_begin()) &&
-           std::equal(thisPHI->block_begin(), thisPHI->block_end(),
-                      otherPHI->block_begin());
-  }
-
   // We have two instructions of identical opcode and #operands.  Check to see
   // if all operands are the same.
   if (!std::equal(op_begin(), op_end(), I->op_begin()))
     return false;
 
+  // WARNING: this logic must be kept in sync with EliminateDuplicatePHINodes()!
+  if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
+    const PHINode *otherPHI = cast<PHINode>(I);
+    return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
+                      otherPHI->block_begin());
+  }
+
   return haveSameSpecialState(this, I);
 }
 

diff  --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 1293037c9195..4234935e2b7c 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1117,6 +1117,8 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
   return true;
 }
 
+// WARNING: this logic must be kept in sync with
+//          Instruction::isIdenticalToWhenDefined()!
 bool llvm::EliminateDuplicatePHINodes(BasicBlock *BB) {
   // This implementation doesn't currently consider undef operands
   // specially. Theoretically, two phis which are identical except for


        


More information about the llvm-commits mailing list