[llvm] [Extractor] Fix for return attrs of extracted functions (PR #194687)

David Li via llvm-commits llvm-commits at lists.llvm.org
Tue May 5 09:47:32 PDT 2026


================
@@ -2121,13 +2121,35 @@ void CodeExtractor::insertReplacerCall(
     }
   }
 
-  if (FuncRetVal)
+  if (FuncRetVal) {
     for (User *U : FuncRetVal->users()) {
       Instruction *inst = cast<Instruction>(U);
       if (inst->getParent()->getParent() == oldFunction)
         inst->replaceUsesOfWith(FuncRetVal, ReplacerCall);
     }
 
+    Use *U = ReplacerCall->getSingleUndroppableUse();
+    AttrBuilder RetAttrs(oldFunction->getContext(),
+                         oldFunction->getAttributes().getRetAttrs());
+    if (RetAttrs.hasAttributes()) {
+      // Update the return attributes for the extracted function and the
+      // replacer call if the result of the call is immediately followed by
+      // return instruction.
+      while (U) {
+        Value *User = U->getUser();
+        if (isa<PHINode>(User)) {
+          U = User->getSingleUndroppableUse();
----------------
david-xl wrote:

Is it possible to have an infinite loop here ?

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


More information about the llvm-commits mailing list