[compiler-rt] [llvm] [CallPromotionUtils]Implement conditional indirect call promotion with vtable-based comparison (PR #81378)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 14:12:54 PDT 2024


================
@@ -185,12 +187,30 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, CastInst **RetBitCast) {
     U->replaceUsesOfWith(&CB, Cast);
 }
 
+// Returns the or result of all icmp instructions.
+static Value *getOrs(const SmallVector<Value *, 2> &ICmps,
+                     IRBuilder<> &Builder) {
+  assert(!ICmps.empty() && "Must have at least one icmp instructions");
+  if (ICmps.size() == 1)
+    return ICmps[0];
+
+  SmallVector<Value *, 2> OrResults;
+  int i = 0, NumICmp = ICmps.size();
+  for (i = 0; i + 1 < NumICmp; i += 2)
+    OrResults.push_back(Builder.CreateOr(ICmps[i], ICmps[i + 1], "icmp-or"));
+
+  if (i < NumICmp)
+    OrResults.push_back(ICmps[i]);
+
+  return getOrs(OrResults, Builder);
----------------
minglotus-6 wrote:

For vtable-based comparison to be efficient (compared with function-based comparison), the number of `icmp`s needs to be gated. I tend to make the threshold 2(i.e., at most two `icmp`s) after tuning this on various workload. Thereby will use `Builder.CreateOr(ICmps)` as suggested.

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


More information about the llvm-commits mailing list