[llvm] [CodeGen] Merge lowerConstantIntrinsics into pre-isel lowering (PR #97727)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 4 07:40:41 PDT 2024


================
@@ -66,6 +71,27 @@ struct PreISelIntrinsicLowering {
 
 } // namespace
 
+template <class T>
+static bool forEachCall(Function &Intrin, T Callback) {
+  // Lowering all intrinsics in a function will delete multiple uses, so we
+  // can't use an early-inc-range. In case some remain, we don't want to look
+  // at them again. Unfortunately, Value::UseList is private, so we can't use a
+  // simple Use**. If LastUse is null, we the next use to consider is
+  // Intrin.use_begin(), otherwise it's LastUse->getNext().
+  Use *LastUse = nullptr;
+  bool Changed = false;
+  while (!Intrin.use_empty() && (!LastUse || LastUse->getNext())) {
+    Use *U = LastUse ? LastUse->getNext() : &*Intrin.use_begin();
+    bool Removed = false;
+    auto CI = dyn_cast<CallInst>(U->getUser());
+    if (CI && CI->getCalledOperand() == &Intrin)
----------------
aengelke wrote:

Changed. I couldn't come up with a case where this invariant does not hold. It might make sense to simplify the other checks later.

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


More information about the llvm-commits mailing list