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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 6 05:58:55 PDT 2025


================
@@ -1752,6 +1752,76 @@ void VPlanTransforms::clearReductionWrapFlags(VPlan &Plan) {
   }
 }
 
+/// Hash the underlying data of a VPSingleDefRecipe pointer, instead of hashing
+/// the pointer itself.
+namespace {
+struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
+  static bool isSentinel(const VPSingleDefRecipe *Def) {
+    return Def == getEmptyKey() || Def == getTombstoneKey();
+  }
+
+  static bool canHandle(const VPSingleDefRecipe *Def) {
+    return isa<VPInstruction, VPWidenRecipe, VPWidenCastRecipe,
+               VPWidenSelectRecipe, VPHistogramRecipe, VPPartialReductionRecipe,
+               VPReplicateRecipe, VPWidenIntrinsicRecipe>(Def);
+  }
+
+  static unsigned getHashValue(const VPSingleDefRecipe *Def) {
+    return hash_combine(Def->getVPDefID(), vputils::getOpcode(*Def),
+                        vputils::isSingleScalar(Def),
+                        hash_combine_range(Def->operands()));
----------------
lukel97 wrote:

It's listed in canHandle?

```c++
return isa<VPInstruction, VPWidenRecipe, VPWidenCastRecipe,
               VPWidenSelectRecipe, VPHistogramRecipe, VPPartialReductionRecipe,
               VPReplicateRecipe, VPWidenIntrinsicRecipe>(Def);
```

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


More information about the llvm-commits mailing list