diff options
author | Craig Topper <craig.topper@intel.com> | 2018-05-11 21:59:34 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2018-05-11 21:59:34 +0000 |
commit | a17d627abbf9bf3825770a7d0afc89785954b6f5 (patch) | |
tree | 8ac8fed757ac44076ca1d1f2dcf68075651c1756 /llvm/lib/IR/AutoUpgrade.cpp | |
parent | 669375814c0aef15b7f018ccd9e91b3ec9883efc (diff) | |
download | bcm5719-llvm-a17d627abbf9bf3825770a7d0afc89785954b6f5.tar.gz bcm5719-llvm-a17d627abbf9bf3825770a7d0afc89785954b6f5.zip |
[X86] Remove and autoupgrade a bunch of FMA instrinsics that are no longer used by clang.
llvm-svn: 332146
Diffstat (limited to 'llvm/lib/IR/AutoUpgrade.cpp')
-rw-r--r-- | llvm/lib/IR/AutoUpgrade.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index bd1bbd3800a..a2bc44742f0 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -87,6 +87,10 @@ static bool ShouldUpgradeX86Intrinsic(Function *F, StringRef Name) { if (Name=="ssse3.pabs.b.128" || // Added in 6.0 Name=="ssse3.pabs.w.128" || // Added in 6.0 Name=="ssse3.pabs.d.128" || // Added in 6.0 + Name.startswith("fma.vfmsub.") || // Added in 7.0 + Name.startswith("fma.vfmsubadd.") || // Added in 7.0 + Name.startswith("fma.vfnmadd.") || // Added in 7.0 + Name.startswith("fma.vfnmsub.") || // Added in 7.0 Name.startswith("avx512.mask.shuf.i") || // Added in 6.0 Name.startswith("avx512.mask.shuf.f") || // Added in 6.0 Name.startswith("avx512.kunpck") || //added in 6.0 @@ -2360,6 +2364,85 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { Rep = EmitX86Select(Builder, CI->getArgOperand(3), Rep, CI->getArgOperand(2)); } + } else if (IsX86 && Name.startswith("fma.vfmsub")) { + // Handle FMSUB and FSUBADD. + unsigned VecWidth = CI->getType()->getPrimitiveSizeInBits(); + unsigned EltWidth = CI->getType()->getScalarSizeInBits(); + Intrinsic::ID IID; + if (Name[10] == '.' && Name[11] == 'p') { + // Packed FMSUB + if (VecWidth == 128 && EltWidth == 32) + IID = Intrinsic::x86_fma_vfmadd_ps; + else if (VecWidth == 128 && EltWidth == 64) + IID = Intrinsic::x86_fma_vfmadd_pd; + else if (VecWidth == 256 && EltWidth == 32) + IID = Intrinsic::x86_fma_vfmadd_ps_256; + else if (VecWidth == 256 && EltWidth == 64) + IID = Intrinsic::x86_fma_vfmadd_pd_256; + else + llvm_unreachable("Unexpected intrinsic"); + } else if (Name[10] == '.' && Name[11] == 's') { + // Scalar FMSUB + if (EltWidth == 32) + IID = Intrinsic::x86_fma_vfmadd_ss; + else if (EltWidth == 64) + IID = Intrinsic::x86_fma_vfmadd_sd; + else + llvm_unreachable("Unexpected intrinsic"); + } else { + // FMSUBADD + if (VecWidth == 128 && EltWidth == 32) + IID = Intrinsic::x86_fma_vfmaddsub_ps; + else if (VecWidth == 128 && EltWidth == 64) + IID = Intrinsic::x86_fma_vfmaddsub_pd; + else if (VecWidth == 256 && EltWidth == 32) + IID = Intrinsic::x86_fma_vfmaddsub_ps_256; + else if (VecWidth == 256 && EltWidth == 64) + IID = Intrinsic::x86_fma_vfmaddsub_pd_256; + else + llvm_unreachable("Unexpected intrinsic"); + } + Value *Arg2 = Builder.CreateFNeg(CI->getArgOperand(2)); + Value *Ops[] = { CI->getArgOperand(0), CI->getArgOperand(1), Arg2 }; + Rep = Builder.CreateCall(Intrinsic::getDeclaration(CI->getModule(), IID), + Ops); + } else if (IsX86 && (Name.startswith("fma.vfnmadd.") || + Name.startswith("fma.vfnmsub."))) { + Value *Arg0 = CI->getArgOperand(0); + Value *Arg1 = CI->getArgOperand(1); + Value *Arg2 = CI->getArgOperand(2); + unsigned VecWidth = CI->getType()->getPrimitiveSizeInBits(); + unsigned EltWidth = CI->getType()->getScalarSizeInBits(); + Intrinsic::ID IID; + if (Name[12] == 'p') { + // Packed FNMADD/FNSUB + Arg0 = Builder.CreateFNeg(Arg0); + if (VecWidth == 128 && EltWidth == 32) + IID = Intrinsic::x86_fma_vfmadd_ps; + else if (VecWidth == 128 && EltWidth == 64) + IID = Intrinsic::x86_fma_vfmadd_pd; + else if (VecWidth == 256 && EltWidth == 32) + IID = Intrinsic::x86_fma_vfmadd_ps_256; + else if (VecWidth == 256 && EltWidth == 64) + IID = Intrinsic::x86_fma_vfmadd_pd_256; + else + llvm_unreachable("Unexpected intrinsic"); + } else { + // Scalar FNMADD/FNMSUB + Arg1 = Builder.CreateFNeg(Arg1); // Arg0 is passthru so invert Arg1. + if (EltWidth == 32) + IID = Intrinsic::x86_fma_vfmadd_ss; + else if (EltWidth == 64) + IID = Intrinsic::x86_fma_vfmadd_sd; + else + llvm_unreachable("Unexpected intrinsic"); + } + // Invert for FNMSUB. + if (Name[8] == 's') + Arg2 = Builder.CreateFNeg(Arg2); + Value *Ops[] = { Arg0, Arg1, Arg2 }; + Rep = Builder.CreateCall(Intrinsic::getDeclaration(CI->getModule(), IID), + Ops); } else if (IsX86 && Name.startswith("avx512.mask.") && upgradeAVX512MaskToSelect(Name, Builder, *CI, Rep)) { // Rep will be updated by the call in the condition. |