diff options
author | Craig Topper <craig.topper@intel.com> | 2018-09-07 16:58:39 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2018-09-07 16:58:39 +0000 |
commit | 72964ae99eb71cba6f6fd4c63c697010ec9a8772 (patch) | |
tree | 65dd1512eda30fe4118c132802dc78a8e92d2f6b /llvm/lib/IR/AutoUpgrade.cpp | |
parent | 51e11788a48f06eca526485a1eedec8d6b0ed6a7 (diff) | |
download | bcm5719-llvm-72964ae99eb71cba6f6fd4c63c697010ec9a8772.tar.gz bcm5719-llvm-72964ae99eb71cba6f6fd4c63c697010ec9a8772.zip |
[X86] Change the addcarry and subborrow intrinsics to return 2 results and remove the pointer argument.
We should represent the store directly in IR instead. This gives the middle end a chance to remove it if it can see a load from the same address.
Differential Revision: https://reviews.llvm.org/D51769
llvm-svn: 341677
Diffstat (limited to 'llvm/lib/IR/AutoUpgrade.cpp')
-rw-r--r-- | llvm/lib/IR/AutoUpgrade.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 06db01fc196..171f82edf20 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -65,6 +65,17 @@ static bool UpgradeX86IntrinsicsWith8BitMask(Function *F, Intrinsic::ID IID, return true; } +static bool UpgradeADCSBBIntrinsic(Function *F, Intrinsic::ID IID, + Function *&NewFn) { + // If this intrinsic has 3 operands, it's the new version. + if (F->getFunctionType()->getNumParams() == 3) + return false; + + rename(F); + NewFn = Intrinsic::getDeclaration(F->getParent(), IID); + return true; +} + static bool ShouldUpgradeX86Intrinsic(Function *F, StringRef Name) { // All of the intrinsics matches below should be marked with which llvm // version started autoupgrading them. At some point in the future we would @@ -371,6 +382,19 @@ static bool UpgradeX86IntrinsicFunction(Function *F, StringRef Name, return true; } + if (Name == "addcarryx.u32") + return UpgradeADCSBBIntrinsic(F, Intrinsic::x86_addcarryx_u32, NewFn); + if (Name == "addcarryx.u64") + return UpgradeADCSBBIntrinsic(F, Intrinsic::x86_addcarryx_u64, NewFn); + if (Name == "addcarry.u32") + return UpgradeADCSBBIntrinsic(F, Intrinsic::x86_addcarry_u32, NewFn); + if (Name == "addcarry.u64") + return UpgradeADCSBBIntrinsic(F, Intrinsic::x86_addcarry_u64, NewFn); + if (Name == "subborrow.u32") + return UpgradeADCSBBIntrinsic(F, Intrinsic::x86_subborrow_u32, NewFn); + if (Name == "subborrow.u64") + return UpgradeADCSBBIntrinsic(F, Intrinsic::x86_subborrow_u64, NewFn); + // SSE4.1 ptest functions may have an old signature. if (Name.startswith("sse41.ptest")) { // Added in 3.2 if (Name.substr(11) == "c") @@ -3417,6 +3441,40 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { break; } + case Intrinsic::x86_addcarryx_u32: + case Intrinsic::x86_addcarryx_u64: + case Intrinsic::x86_addcarry_u32: + case Intrinsic::x86_addcarry_u64: + case Intrinsic::x86_subborrow_u32: + case Intrinsic::x86_subborrow_u64: { + // This used to take 4 arguments. If we only have 3 arguments its already + // upgraded. + if (CI->getNumOperands() == 3) + return; + + // Make a call with 3 operands. + NewCall = Builder.CreateCall(NewFn, { CI->getArgOperand(0), + CI->getArgOperand(1), + CI->getArgOperand(2)}); + // Extract the second result and store it. + Value *Data = Builder.CreateExtractValue(NewCall, 1); + // Cast the pointer to the right type. + Value *Ptr = Builder.CreateBitCast(CI->getArgOperand(3), + llvm::PointerType::getUnqual(Data->getType())); + Builder.CreateAlignedStore(Data, Ptr, 1); + // Replace the original call result with the first result of the new call. + Value *CF = Builder.CreateExtractValue(NewCall, 0); + + std::string Name = CI->getName(); + if (!Name.empty()) { + CI->setName(Name + ".old"); + NewCall->setName(Name); + } + CI->replaceAllUsesWith(CF); + CI->eraseFromParent(); + return; + } + case Intrinsic::x86_sse41_insertps: case Intrinsic::x86_sse41_dppd: case Intrinsic::x86_sse41_dpps: |