diff options
author | Albert Gutowski <agutowski@google.com> | 2016-10-04 22:29:49 +0000 |
---|---|---|
committer | Albert Gutowski <agutowski@google.com> | 2016-10-04 22:29:49 +0000 |
commit | f3a0bce1557f2c070518875122a8eb648f971211 (patch) | |
tree | f1820a93a695c12671d7145bd32d722631905749 /clang/lib/CodeGen/CGBuiltin.cpp | |
parent | e7439392f14f46b5214a5cf9c8d0244259cd6689 (diff) | |
download | bcm5719-llvm-f3a0bce1557f2c070518875122a8eb648f971211.tar.gz bcm5719-llvm-f3a0bce1557f2c070518875122a8eb648f971211.zip |
Separate builtins for x84-64 and i386; implement __mulh and __umulh
Summary: We need x86-64-specific builtins if we want to implement some of the MS intrinsics - winnt.h contains definitions of some functions for i386, but not for x86-64 (for example _InterlockedOr64), which means that we cannot treat them as builtins for both i386 and x86-64, because then we have definitions of builtin functions in winnt.h on i386.
Reviewers: thakis, majnemer, hans, rnk
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D24598
llvm-svn: 283264
Diffstat (limited to 'clang/lib/CodeGen/CGBuiltin.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index e9248b35cd6..d05e910f244 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -7575,6 +7575,30 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 6); case X86::BI__builtin_ia32_cmpordsd: return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 7); + + case X86::BI__mulh: + case X86::BI__umulh: { + Value *LHS = EmitScalarExpr(E->getArg(0)); + Value *RHS = EmitScalarExpr(E->getArg(1)); + llvm::Type *ResType = ConvertType(E->getType()); + llvm::Type *Int128Ty = llvm::IntegerType::get(getLLVMContext(), 128); + + bool IsSigned = (BuiltinID == X86::BI__mulh); + LHS = Builder.CreateIntCast(LHS, Int128Ty, IsSigned); + RHS = Builder.CreateIntCast(RHS, Int128Ty, IsSigned); + + Value *MulResult, *HigherBits; + if (IsSigned) { + MulResult = Builder.CreateNSWMul(LHS, RHS); + HigherBits = Builder.CreateAShr(MulResult, 64); + } else { + MulResult = Builder.CreateNUWMul(LHS, RHS); + HigherBits = Builder.CreateLShr(MulResult, 64); + } + + HigherBits = Builder.CreateIntCast(HigherBits, ResType, IsSigned); + return HigherBits; + } } } |