[llvm] 1ed1761 - [NFC][LLVM] Simplify `PruningFunctionCloner::cloneInstruction` (#195389)

via llvm-commits llvm-commits at lists.llvm.org
Sat May 2 05:09:22 PDT 2026


Author: Rahul Joshi
Date: 2026-05-02T05:09:17-07:00
New Revision: 1ed176101cc404e08eda219655f11834a24c238a

URL: https://github.com/llvm/llvm-project/commit/1ed176101cc404e08eda219655f11834a24c238a
DIFF: https://github.com/llvm/llvm-project/commit/1ed176101cc404e08eda219655f11834a24c238a.diff

LOG: [NFC][LLVM] Simplify `PruningFunctionCloner::cloneInstruction` (#195389)

Add early returns and decrease indendation of the code that does
implements calls to constrained intrinsics.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/CloneFunction.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 8bf941cf19cd9..56ea6bc657c52 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -458,73 +458,68 @@ struct PruningFunctionCloner {
 
 Instruction *
 PruningFunctionCloner::cloneInstruction(BasicBlock::const_iterator II) {
+  if (!HostFuncIsStrictFP)
+    return II->clone();
+
   const Instruction &OldInst = *II;
-  Instruction *NewInst = nullptr;
-  if (HostFuncIsStrictFP) {
-    Intrinsic::ID CIID = getConstrainedIntrinsicID(OldInst);
-    if (CIID != Intrinsic::not_intrinsic) {
-      // Instead of cloning the instruction, a call to constrained intrinsic
-      // should be created.
-      // Assume the first arguments of constrained intrinsics are the same as
-      // the operands of original instruction.
-
-      // Determine overloaded types of the intrinsic.
-      SmallVector<Type *, 2> TParams;
-      SmallVector<Intrinsic::IITDescriptor, 8> Descriptor;
-      getIntrinsicInfoTableEntries(CIID, Descriptor);
-      for (unsigned I = 0, E = Descriptor.size(); I != E; ++I) {
-        Intrinsic::IITDescriptor Operand = Descriptor[I];
-        switch (Operand.Kind) {
-        case Intrinsic::IITDescriptor::Overloaded:
-          if (Operand.getOverloadKind() !=
-              Intrinsic::IITDescriptor::AK_MatchType) {
-            if (I == 0)
-              TParams.push_back(OldInst.getType());
-            else
-              TParams.push_back(OldInst.getOperand(I - 1)->getType());
-          }
-          break;
-        case Intrinsic::IITDescriptor::SameVecWidth:
-          ++I;
-          break;
-        default:
-          break;
-        }
+  Intrinsic::ID CIID = getConstrainedIntrinsicID(OldInst);
+  if (CIID == Intrinsic::not_intrinsic)
+    return II->clone();
+
+  // Instead of cloning the instruction, a call to constrained intrinsic should
+  // be created. Assume the first arguments of constrained intrinsics are the
+  // same as the operands of original instruction.
+
+  // Determine overloaded types of the intrinsic.
+  SmallVector<Type *, 2> TParams;
+  SmallVector<Intrinsic::IITDescriptor, 8> Descriptor;
+  getIntrinsicInfoTableEntries(CIID, Descriptor);
+  for (unsigned I = 0, E = Descriptor.size(); I != E; ++I) {
+    Intrinsic::IITDescriptor Operand = Descriptor[I];
+    switch (Operand.Kind) {
+    case Intrinsic::IITDescriptor::Overloaded:
+      if (Operand.getOverloadKind() != Intrinsic::IITDescriptor::AK_MatchType) {
+        if (I == 0)
+          TParams.push_back(OldInst.getType());
+        else
+          TParams.push_back(OldInst.getOperand(I - 1)->getType());
       }
+      break;
+    case Intrinsic::IITDescriptor::SameVecWidth:
+      ++I;
+      break;
+    default:
+      break;
+    }
+  }
 
-      // Create intrinsic call.
-      LLVMContext &Ctx = NewFunc->getContext();
-      Function *IFn = Intrinsic::getOrInsertDeclaration(NewFunc->getParent(),
-                                                        CIID, TParams);
-      SmallVector<Value *, 4> Args;
-      unsigned NumOperands = OldInst.getNumOperands();
-      if (isa<CallInst>(OldInst))
-        --NumOperands;
-      for (unsigned I = 0; I < NumOperands; ++I) {
-        Value *Op = OldInst.getOperand(I);
-        Args.push_back(Op);
-      }
-      if (const auto *CmpI = dyn_cast<FCmpInst>(&OldInst)) {
-        FCmpInst::Predicate Pred = CmpI->getPredicate();
-        StringRef PredName = FCmpInst::getPredicateName(Pred);
-        Args.push_back(MetadataAsValue::get(Ctx, MDString::get(Ctx, PredName)));
-      }
+  // Create intrinsic call.
+  LLVMContext &Ctx = NewFunc->getContext();
+  Function *IFn =
+      Intrinsic::getOrInsertDeclaration(NewFunc->getParent(), CIID, TParams);
+  SmallVector<Value *, 4> Args;
+  unsigned NumOperands = OldInst.getNumOperands();
+  if (isa<CallInst>(OldInst))
+    --NumOperands;
+  for (unsigned I = 0; I < NumOperands; ++I)
+    Args.push_back(OldInst.getOperand(I));
+
+  if (const auto *CmpI = dyn_cast<FCmpInst>(&OldInst)) {
+    FCmpInst::Predicate Pred = CmpI->getPredicate();
+    StringRef PredName = FCmpInst::getPredicateName(Pred);
+    Args.push_back(MetadataAsValue::get(Ctx, MDString::get(Ctx, PredName)));
+  }
 
-      // The last arguments of a constrained intrinsic are metadata that
-      // represent rounding mode (absents in some intrinsics) and exception
-      // behavior. The inlined function uses default settings.
-      if (Intrinsic::hasConstrainedFPRoundingModeOperand(CIID))
-        Args.push_back(
-            MetadataAsValue::get(Ctx, MDString::get(Ctx, "round.tonearest")));
-      Args.push_back(
-          MetadataAsValue::get(Ctx, MDString::get(Ctx, "fpexcept.ignore")));
+  // The last arguments of a constrained intrinsic are metadata that
+  // represent rounding mode (absents in some intrinsics) and exception
+  // behavior. The inlined function uses default settings.
+  if (Intrinsic::hasConstrainedFPRoundingModeOperand(CIID))
+    Args.push_back(
+        MetadataAsValue::get(Ctx, MDString::get(Ctx, "round.tonearest")));
+  Args.push_back(
+      MetadataAsValue::get(Ctx, MDString::get(Ctx, "fpexcept.ignore")));
 
-      NewInst = CallInst::Create(IFn, Args, OldInst.getName() + ".strict");
-    }
-  }
-  if (!NewInst)
-    NewInst = II->clone();
-  return NewInst;
+  return CallInst::Create(IFn, Args, OldInst.getName() + ".strict");
 }
 
 /// The specified block is found to be reachable, clone it and


        


More information about the llvm-commits mailing list