Yafei Liu via llvm-dev
2019-Sep-26 02:42 UTC
[llvm-dev] ConstantFP->getType() is not right
Hi, I want to create a double constant from a float constant, here's my code: auto* constFloat1 static_cast<llvm::ConstantFP*>(llvm::ConstantFP::get(llvm::Type::getFloatTy(context), 3.1)); assert(constFloat1->getType() == llvm::Type::getFloatTy(context)); auto* constFloat2 llvm::ConstantFP::get(llvm::Type::getDoubleTy(context), constFloat1->getValueAPF()); assert(constFloat2->getType() == llvm::Type::getDoubleTy(context)); but the second assert failed, the type of constFloat2 is still float, not double, why? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190926/4395687a/attachment.html>
Craig Topper via llvm-dev
2019-Sep-26 02:59 UTC
[llvm-dev] ConstantFP->getType() is not right
The Type passed to llvm::ConstantFP::get is only used to get the context and to determine if the constant needs to be a vector. The width is taken from the APFloat passed in. There is an assert in the implementation that makes sure the scalar type of the type passed in matches the size of the APFloat. Is your llvm library compiled with asserts enabled? You can use ConstantExpr::getFPExtend to do what you want. ~Craig On Wed, Sep 25, 2019 at 7:43 PM Yafei Liu via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi, I want to create a double constant from a float constant, here's my > code: > > auto* constFloat1 > static_cast<llvm::ConstantFP*>(llvm::ConstantFP::get(llvm::Type::getFloatTy(context), > 3.1)); > > assert(constFloat1->getType() == llvm::Type::getFloatTy(context)); > > > auto* constFloat2 > llvm::ConstantFP::get(llvm::Type::getDoubleTy(context), > constFloat1->getValueAPF()); > > assert(constFloat2->getType() == llvm::Type::getDoubleTy(context)); > > but the second assert failed, the type of constFloat2 is still float, not > double, why? > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190925/5a418789/attachment.html>
Yafei Liu via llvm-dev
2019-Sep-26 03:38 UTC
[llvm-dev] ConstantFP->getType() is not right
Hi Craig, it works, appreciate your help On Thu, Sep 26, 2019 at 10:59 AM Craig Topper <craig.topper at gmail.com> wrote:> The Type passed to llvm::ConstantFP::get is only used to get the context > and to determine if the constant needs to be a vector. The width is taken > from the APFloat passed in. There is an assert in the implementation that > makes sure the scalar type of the type passed in matches the size of the > APFloat. Is your llvm library compiled with asserts enabled? > > You can use ConstantExpr::getFPExtend to do what you want. > > ~Craig > > > On Wed, Sep 25, 2019 at 7:43 PM Yafei Liu via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> Hi, I want to create a double constant from a float constant, here's my >> code: >> >> auto* constFloat1 >> static_cast<llvm::ConstantFP*>(llvm::ConstantFP::get(llvm::Type::getFloatTy(context), >> 3.1)); >> >> assert(constFloat1->getType() == llvm::Type::getFloatTy(context)); >> >> >> auto* constFloat2 >> llvm::ConstantFP::get(llvm::Type::getDoubleTy(context), >> constFloat1->getValueAPF()); >> >> assert(constFloat2->getType() == llvm::Type::getDoubleTy(context)); >> >> but the second assert failed, the type of constFloat2 is still float, not >> double, why? >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190926/84378e22/attachment-0001.html>
Reasonably Related Threads
- [LLVMdev] AllocaInst for FunctionType?
- [LLVMdev] JIT : Does it cache the compiled code of executed functions upon runFunction(..)?
- [LLVMdev] JIT compiled intrinsics calls is call to null pointer
- [LLVMdev] Best strategy to add a parameter to a function
- [LLVMdev] get unsigned integer pattern for ConstantFP