llvm.org GIT mirror llvm / ee51703
Keep attributes, calling convention, etc, when remangling intrinsic Summary: Fix issue reported where intrinsic calling convention is dropped after r295253. Reviewers: sanjoy Subscribers: materi, llvm-commits Differential Revision: https://reviews.llvm.org/D30422 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296563 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Berlin 3 years ago
2 changed file(s) with 43 addition(s) and 53 deletion(s). Raw diff Collapse all Expand all
19101910 return;
19111911 }
19121912
1913 std::string Name = CI->getName();
1914 if (!Name.empty())
1915 CI->setName(Name + ".old");
1916
1913 CallInst *NewCall = nullptr;
19171914 switch (NewFn->getIntrinsicID()) {
19181915 default: {
19191916 // Handle generic mangling change, but nothing else
19201917 assert(
19211918 (CI->getCalledFunction()->getName() != NewFn->getName()) &&
19221919 "Unknown function for CallInst upgrade and isn't just a name change");
1923 SmallVector Args(CI->arg_operands().begin(),
1924 CI->arg_operands().end());
1925 CI->replaceAllUsesWith(Builder.CreateCall(NewFn, Args));
1926 CI->eraseFromParent();
1920 CI->setCalledFunction(NewFn);
19271921 return;
19281922 }
19291923
19431937 case Intrinsic::arm_neon_vst4lane: {
19441938 SmallVector Args(CI->arg_operands().begin(),
19451939 CI->arg_operands().end());
1946 CI->replaceAllUsesWith(Builder.CreateCall(NewFn, Args));
1947 CI->eraseFromParent();
1948 return;
1940 NewCall = Builder.CreateCall(NewFn, Args);
1941 break;
19491942 }
19501943
19511944 case Intrinsic::bitreverse:
1952 CI->replaceAllUsesWith(Builder.CreateCall(NewFn, {CI->getArgOperand(0)}));
1953 CI->eraseFromParent();
1954 return;
1945 NewCall = Builder.CreateCall(NewFn, {CI->getArgOperand(0)});
1946 break;
19551947
19561948 case Intrinsic::ctlz:
19571949 case Intrinsic::cttz:
19581950 assert(CI->getNumArgOperands() == 1 &&
19591951 "Mismatch between function args and call args");
1960 CI->replaceAllUsesWith(Builder.CreateCall(
1961 NewFn, {CI->getArgOperand(0), Builder.getFalse()}, Name));
1962 CI->eraseFromParent();
1963 return;
1952 NewCall =
1953 Builder.CreateCall(NewFn, {CI->getArgOperand(0), Builder.getFalse()});
1954 break;
19641955
19651956 case Intrinsic::objectsize:
1966 CI->replaceAllUsesWith(Builder.CreateCall(
1967 NewFn, {CI->getArgOperand(0), CI->getArgOperand(1)}, Name));
1968 CI->eraseFromParent();
1969 return;
1957 NewCall =
1958 Builder.CreateCall(NewFn, {CI->getArgOperand(0), CI->getArgOperand(1)});
1959 break;
19701960
19711961 case Intrinsic::ctpop:
1972 CI->replaceAllUsesWith(Builder.CreateCall(NewFn, {CI->getArgOperand(0)}));
1973 CI->eraseFromParent();
1974 return;
1962 NewCall = Builder.CreateCall(NewFn, {CI->getArgOperand(0)});
1963 break;
19751964
19761965 case Intrinsic::convert_from_fp16:
1977 CI->replaceAllUsesWith(Builder.CreateCall(NewFn, {CI->getArgOperand(0)}));
1978 CI->eraseFromParent();
1979 return;
1966 NewCall = Builder.CreateCall(NewFn, {CI->getArgOperand(0)});
1967 break;
19801968
19811969 case Intrinsic::x86_xop_vfrcz_ss:
19821970 case Intrinsic::x86_xop_vfrcz_sd:
1983 CI->replaceAllUsesWith(
1984 Builder.CreateCall(NewFn, {CI->getArgOperand(1)}, Name));
1985 CI->eraseFromParent();
1986 return;
1971 NewCall = Builder.CreateCall(NewFn, {CI->getArgOperand(1)});
1972 break;
19871973
19881974 case Intrinsic::x86_xop_vpermil2pd:
19891975 case Intrinsic::x86_xop_vpermil2ps:
19941980 VectorType *FltIdxTy = cast(Args[2]->getType());
19951981 VectorType *IntIdxTy = VectorType::getInteger(FltIdxTy);
19961982 Args[2] = Builder.CreateBitCast(Args[2], IntIdxTy);
1997 CI->replaceAllUsesWith(Builder.CreateCall(NewFn, Args, Name));
1998 CI->eraseFromParent();
1999 return;
1983 NewCall = Builder.CreateCall(NewFn, Args);
1984 break;
20001985 }
20011986
20021987 case Intrinsic::x86_sse41_ptestc:
20182003 Value *BC0 = Builder.CreateBitCast(Arg0, NewVecTy, "cast");
20192004 Value *BC1 = Builder.CreateBitCast(Arg1, NewVecTy, "cast");
20202005
2021 CallInst *NewCall = Builder.CreateCall(NewFn, {BC0, BC1}, Name);
2022 CI->replaceAllUsesWith(NewCall);
2023 CI->eraseFromParent();
2024 return;
2006 NewCall = Builder.CreateCall(NewFn, {BC0, BC1});
2007 break;
20252008 }
20262009
20272010 case Intrinsic::x86_sse41_insertps:
20372020
20382021 // Replace the last argument with a trunc.
20392022 Args.back() = Builder.CreateTrunc(Args.back(), Type::getInt8Ty(C), "trunc");
2040
2041 CallInst *NewCall = Builder.CreateCall(NewFn, Args);
2042 CI->replaceAllUsesWith(NewCall);
2043 CI->eraseFromParent();
2044 return;
2023 NewCall = Builder.CreateCall(NewFn, Args);
2024 break;
20452025 }
20462026
20472027 case Intrinsic::thread_pointer: {
2048 CI->replaceAllUsesWith(Builder.CreateCall(NewFn, {}));
2049 CI->eraseFromParent();
2050 return;
2028 NewCall = Builder.CreateCall(NewFn, {});
2029 break;
20512030 }
20522031
20532032 case Intrinsic::invariant_start:
20562035 case Intrinsic::masked_store: {
20572036 SmallVector Args(CI->arg_operands().begin(),
20582037 CI->arg_operands().end());
2059 CI->replaceAllUsesWith(Builder.CreateCall(NewFn, Args));
2060 CI->eraseFromParent();
2061 return;
2062 }
2063 }
2038 NewCall = Builder.CreateCall(NewFn, Args);
2039 break;
2040 }
2041 }
2042 assert(NewCall && "Should have either set this variable or returned through "
2043 "the default case");
2044 std::string Name = CI->getName();
2045 if (!Name.empty()) {
2046 CI->setName(Name + ".old");
2047 NewCall->setName(Name);
2048 }
2049 CI->replaceAllUsesWith(NewCall);
2050 CI->eraseFromParent();
20642051 }
20652052
20662053 void llvm::UpgradeCallsToIntrinsic(Function *F) {
0 ; RUN: opt -verify -S < %s
1 ; RUN: opt -S < %s | FileCheck %s
12
23 ; Tests the name mangling performed by the codepath following
34 ; getMangledTypeStr(). Only tests that code with the various manglings
6667
6768 define %i32* @test_broken_names(%i32* %v) gc "statepoint-example" {
6869 entry:
69 %tok = call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.deadbeef(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, %i32* %v)
70 %tok = call fastcc token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.deadbeef(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, %i32* %v)
71 ; Make sure we do not destroy the calling convention when remangling
72 ; CHECK: fastcc
7073 %v-new = call %i32* @llvm.experimental.gc.relocate.beefdead(token %tok, i32 7, i32 7)
7174 ret %i32* %v-new
7275 }