[llvm] [CGData][GMF] Skip No Params (PR #116548)

Zhaoxuan Jiang via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 17 22:25:15 PST 2024


================
@@ -159,22 +169,28 @@ static bool isProfitable(
   unsigned InstCount = SFS[0]->InstCount;
   if (InstCount < GlobalMergingMinInstrs)
     return false;
-
-  unsigned ParamCount = SFS[0]->IndexOperandHashMap->size();
-  if (ParamCount > GlobalMergingMaxParams)
-    return false;
-
-  unsigned Benefit = InstCount * (StableFunctionCount - 1);
-  unsigned Cost =
-      (GlobalMergingParamOverhead * ParamCount + GlobalMergingCallOverhead) *
-          StableFunctionCount +
-      GlobalMergingExtraThreshold;
+  double Benefit =
+      InstCount * (StableFunctionCount - 1) * GlobalMergingInstOverhead;
+
+  double Cost = 0.0;
+  SmallSet<stable_hash, 8> UniqueHashVals;
+  for (auto &SF : SFS) {
+    UniqueHashVals.clear();
+    for (auto &[IndexPair, Hash] : *SF->IndexOperandHashMap)
+      UniqueHashVals.insert(Hash);
+    unsigned ParamCount = UniqueHashVals.size();
+    if (ParamCount > GlobalMergingMaxParams)
+      return false;
+    if (GlobalMergingSkipNoParams && ParamCount == 0)
----------------
nocchijiang wrote:

So this pass acts as an IR-level ICF when `ParamCount == 0`? If your testing result shows it is beneficial then I have no problems with it.

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


More information about the llvm-commits mailing list