Unverified Commit 1ed17610 authored by Rahul Joshi's avatar Rahul Joshi Committed by GitHub
Browse files

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

Add early returns and decrease indendation of the code that does
implements calls to constrained intrinsics.
parent 7b026ac8
Loading
Loading
Loading
Loading
+57 −62
Original line number Diff line number Diff line
@@ -458,15 +458,17 @@ public:

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.
  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;
@@ -476,8 +478,7 @@ PruningFunctionCloner::cloneInstruction(BasicBlock::const_iterator II) {
    Intrinsic::IITDescriptor Operand = Descriptor[I];
    switch (Operand.Kind) {
    case Intrinsic::IITDescriptor::Overloaded:
          if (Operand.getOverloadKind() !=
              Intrinsic::IITDescriptor::AK_MatchType) {
      if (Operand.getOverloadKind() != Intrinsic::IITDescriptor::AK_MatchType) {
        if (I == 0)
          TParams.push_back(OldInst.getType());
        else
@@ -494,16 +495,15 @@ PruningFunctionCloner::cloneInstruction(BasicBlock::const_iterator II) {

  // Create intrinsic call.
  LLVMContext &Ctx = NewFunc->getContext();
      Function *IFn = Intrinsic::getOrInsertDeclaration(NewFunc->getParent(),
                                                        CIID, TParams);
  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);
      }
  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);
@@ -519,12 +519,7 @@ PruningFunctionCloner::cloneInstruction(BasicBlock::const_iterator II) {
  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