diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-02-15 13:55:52 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-02-15 13:55:52 +0000 |
commit | 6a0f667077fcd7f8af813384b34f3937702388d4 (patch) | |
tree | a1d89fe8e5656f9174f089fd1ab4a48bd73df02f /llvm/lib/IR/Constants.cpp | |
parent | b5f8ca47e716c7817acfdf9fa59c6932439726a3 (diff) | |
download | bcm5719-llvm-6a0f667077fcd7f8af813384b34f3937702388d4.tar.gz bcm5719-llvm-6a0f667077fcd7f8af813384b34f3937702388d4.zip |
[InstCombine] allow X / C -> X * (1.0/C) for vector splat FP constants
llvm-svn: 325237
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index dccba779deb..a601f54a359 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -635,6 +635,17 @@ Constant *ConstantFP::get(Type *Ty, double V) { return C; } +Constant *ConstantFP::get(Type *Ty, const APFloat &V) { + ConstantFP *C = get(Ty->getContext(), V); + assert(C->getType() == Ty->getScalarType() && + "ConstantFP type doesn't match the type implied by its value!"); + + // For vectors, broadcast the value. + if (auto *VTy = dyn_cast<VectorType>(Ty)) + return ConstantVector::getSplat(VTy->getNumElements(), C); + + return C; +} Constant *ConstantFP::get(Type *Ty, StringRef Str) { LLVMContext &Context = Ty->getContext(); |