summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/AutoUpgrade.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR/AutoUpgrade.cpp')
-rw-r--r--llvm/lib/IR/AutoUpgrade.cpp58
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:
OpenPOWER on IntegriCloud