[PATCH] D106426: [FuncSpec] Support specialising recursive functions

Chuanqi Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 21 04:03:40 PDT 2021


ChuanqiXu added a comment.

The example in the summary looks a little bit scaring at the first glance. I thought it may specialize 1000 times if the code looks like:

  int Global = 1;
  void recursiveFunc(int *arg) {
    if (*arg < 1000) {
      print(*arg);
      recursiveFunc(*arg + 1);
    }
  }
  void main() {
    recursiveFunc(&Global);
  }

And I found that it is controlled by `FuncSpecializationMaxIters` which is 1 by default.
And my question is: what would be different if we don't change the value for `FuncSpecializationMaxIters`?



================
Comment at: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp:74
+// transition to ValueLatticeElement.
+bool isConstant(const ValueLatticeElement &LV) {
+    return LV.isConstant() ||
----------------
mark this with `static`


================
Comment at: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp:84
+
+static Constant *isAllocaPromotable(AllocaInst *Alloca, CallInst *Call) {
+  Value *StoreValue = nullptr;
----------------
maybe we need a better name such as `getPromotableAlloca`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106426/new/

https://reviews.llvm.org/D106426



More information about the llvm-commits mailing list