Commit caeb636e authored by Nikita Popov's avatar Nikita Popov
Browse files

[AutoUpgrade] Remove redundant remangling code (NFCI)

If the only purpose of the upgrade is a mangling change, this is
handled generically by intrinsic remangling, and does not require
any hand-written code.
parent e6338254
Loading
Loading
Loading
Loading
+1 −82
Original line number Diff line number Diff line
@@ -1013,32 +1013,6 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
    break;
  case 'i':
  case 'l': {
    bool IsLifetimeStart = Name.startswith("lifetime.start");
    if (IsLifetimeStart || Name.startswith("invariant.start")) {
      Intrinsic::ID ID = IsLifetimeStart ?
        Intrinsic::lifetime_start : Intrinsic::invariant_start;
      auto Args = F->getFunctionType()->params();
      Type* ObjectPtr[1] = {Args[1]};
      if (F->getName() != Intrinsic::getName(ID, ObjectPtr, F->getParent())) {
        rename(F);
        NewFn = Intrinsic::getDeclaration(F->getParent(), ID, ObjectPtr);
        return true;
      }
    }

    bool IsLifetimeEnd = Name.startswith("lifetime.end");
    if (IsLifetimeEnd || Name.startswith("invariant.end")) {
      Intrinsic::ID ID = IsLifetimeEnd ?
        Intrinsic::lifetime_end : Intrinsic::invariant_end;

      auto Args = F->getFunctionType()->params();
      Type* ObjectPtr[1] = {Args[IsLifetimeEnd ? 1 : 2]};
      if (F->getName() != Intrinsic::getName(ID, ObjectPtr, F->getParent())) {
        rename(F);
        NewFn = Intrinsic::getDeclaration(F->getParent(), ID, ObjectPtr);
        return true;
      }
    }
    if (Name.startswith("invariant.group.barrier")) {
      // Rename invariant.group.barrier to launder.invariant.group
      auto Args = F->getFunctionType()->params();
@@ -1053,35 +1027,6 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
    break;
  }
  case 'm': {
    StringRef MaskPfx = "masked.";
    if (Name.startswith(MaskPfx)) {
      // Renaming masked intrinsics with no address space overloading
      // to the new overload, which includes an address space.
      Intrinsic::ID ID =
          StringSwitch<Intrinsic::ID>(Name.substr(MaskPfx.size()))
              .StartsWith("load.", Intrinsic::masked_load)
              .StartsWith("store.", Intrinsic::masked_store)
              .StartsWith("gather.", Intrinsic::masked_gather)
              .StartsWith("scatter.", Intrinsic::masked_scatter)
              .Default(Intrinsic::not_intrinsic);
      if (ID != Intrinsic::not_intrinsic) {
        const auto *FT = F->getFunctionType();
        SmallVector<Type *, 2> Tys;
        if (ID == Intrinsic::masked_load || ID == Intrinsic::masked_gather)
          // Loading operations overload on the return type.
          Tys.push_back(FT->getReturnType());
        Tys.push_back(FT->getParamType(0));
        if (ID == Intrinsic::masked_store || ID == Intrinsic::masked_scatter)
          // Store operations overload on the stored type.
          Tys.push_back(FT->getParamType(1));
        if (F->getName() != Intrinsic::getName(ID, Tys, F->getParent())) {
          rename(F);
          NewFn = Intrinsic::getDeclaration(F->getParent(), ID, Tys);
          return true;
        }
      }
      break; // No other 'masked.*'
    }
    // Updating the memory intrinsics (memcpy/memmove/memset) that have an
    // alignment parameter to embedding the alignment as an attribute of
    // the pointer args.
@@ -1169,17 +1114,7 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
    break;

  case 'p':
    if (Name == "prefetch") {
      // Handle address space overloading.
      Type *Tys[] = {F->arg_begin()->getType()};
      if (F->getName() !=
          Intrinsic::getName(Intrinsic::prefetch, Tys, F->getParent())) {
        rename(F);
        NewFn =
            Intrinsic::getDeclaration(F->getParent(), Intrinsic::prefetch, Tys);
        return true;
      }
    } else if (Name.startswith("ptr.annotation.") && F->arg_size() == 4) {
    if (Name.startswith("ptr.annotation.") && F->arg_size() == 4) {
      rename(F);
      NewFn = Intrinsic::getDeclaration(
          F->getParent(), Intrinsic::ptr_annotation,
@@ -4636,22 +4571,6 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
    break;
  }

  case Intrinsic::invariant_start:
  case Intrinsic::invariant_end: {
    SmallVector<Value *, 4> Args(CI->args());
    NewCall = Builder.CreateCall(NewFn, Args);
    break;
  }
  case Intrinsic::masked_load:
  case Intrinsic::masked_store:
  case Intrinsic::masked_gather:
  case Intrinsic::masked_scatter: {
    SmallVector<Value *, 4> Args(CI->args());
    NewCall = Builder.CreateCall(NewFn, Args);
    NewCall->copyMetadata(*CI);
    break;
  }

  case Intrinsic::memcpy:
  case Intrinsic::memmove:
  case Intrinsic::memset: {