[llvm] [VPlan] Introduce CSE pass (PR #151872)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 4 04:37:15 PDT 2025


================
@@ -122,6 +122,49 @@ void VPDef::dump() const {
 }
 #endif
 
+bool VPValue::isIdenticalTo(const VPValue *Other) const {
+  if (getVPValueID() != Other->getVPValueID() ||
+      hasDefiningRecipe() != Other->hasDefiningRecipe() ||
+      !getUnderlyingValue() != !Other->getUnderlyingValue())
+    return false;
+
+  auto *I = dyn_cast_or_null<Instruction>(getUnderlyingValue());
+  auto *OtherI = dyn_cast_or_null<Instruction>(Other->getUnderlyingValue());
+  if (I && OtherI)
+    return I->isIdenticalTo(OtherI);
+
+  if (hasDefiningRecipe()) {
+    // Special case for matching flags on instruction.
+    auto *VPI = dyn_cast<VPInstruction>(this);
+    auto *OtherVPI = dyn_cast<VPInstruction>(Other);
+    if (VPI && OtherVPI && VPI->hashFlags() != OtherVPI->hashFlags())
+      return false;
+
+    const VPRecipeBase *DefL = getDefiningRecipe();
+    const VPRecipeBase *DefR = Other->getDefiningRecipe();
+    return vputils::getOpcode(*DefL) == vputils::getOpcode(*DefR) &&
+           equal(DefL->operands(), DefR->operands());
+  }
+  return getUnderlyingValue() == Other->getUnderlyingValue();
+}
+
+hash_code llvm::hash_value(const VPValue &V) {
+  if (Instruction *I = dyn_cast_or_null<Instruction>(V.getUnderlyingValue()))
+    return hash_combine(I->getOpcode(), I->getRawSubclassOptionalData(),
+                        hash_combine_range(I->operand_values()));
----------------
fhahn wrote:

as per above, we should not look at the underlying value.

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


More information about the llvm-commits mailing list