[PATCH] D94633: [FunctionAttrs] Infer willreturn for functions without loops

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 14 09:50:03 PST 2021


fhahn added inline comments.


================
Comment at: lib/Transforms/IPO/FunctionAttrs.cpp:1441
+  SmallVector<std::pair<const BasicBlock *, const BasicBlock *>> Backedges;
+  FindFunctionBackedges(F, Backedges);
+  if (!Backedges.empty())
----------------
 We do not really need to find all back edges, wouldn't it be sufficient to just traverse the CFG and exit once we found a cycle?


================
Comment at: lib/Transforms/IPO/FunctionAttrs.cpp:1447
+  // it are willreturn.
+  for (const BasicBlock &BB : F)
+    for (const Instruction &I : BB)
----------------
You could use the `instruction()` iterator range to directly iterate over all instructions, e.g.

```
  return all_of(instructions(F), [](const Instruction &I){
    const auto *CB = dyn_cast<CallBase>(&I);
    return !CB || CB->hasFnAttr(Attribute::WillReturn);
  });
```


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

https://reviews.llvm.org/D94633



More information about the llvm-commits mailing list