<div dir="ltr">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?<div><br></div><div>You can use ConstantExpr::getFPExtend to do what you want.<div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 25, 2019 at 7:43 PM Yafei Liu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi, I want to create a double constant from a float constant, here's my code:<div><br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>auto* constFloat1 = static_cast<llvm::ConstantFP*>(llvm::ConstantFP::get(llvm::Type::getFloatTy(context), 3.1));</div><div><br></div><div>  assert(constFloat1->getType() == llvm::Type::getFloatTy(context));</div><div><br></div><div><br></div><div>  auto* constFloat2 = llvm::ConstantFP::get(llvm::Type::getDoubleTy(context), constFloat1->getValueAPF());</div><div><br></div><div>  assert(constFloat2->getType() == llvm::Type::getDoubleTy(context));</div><div><br></div></blockquote>but the second assert failed, the type of constFloat2 is still float, not double, why?</div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>