Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions llvm_util/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "llvm_util/utils.h"
#include "ir/constant.h"
#include "ir/function.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
Expand Down Expand Up @@ -328,10 +329,16 @@ Value* get_operand(llvm::Value *v,

if (auto cnst = dyn_cast<llvm::ConstantFP>(v)) {
auto &apfloat = cnst->getValueAPF();
auto c
= make_unique<FloatConst>(*ty,
toString(apfloat.bitcastToAPInt(), 10, false),
true);
unique_ptr<FloatConst> c;
if (apfloat.isFinite()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to check for NaN?

llvm::SmallString<32> str;
apfloat.toString(str);
c = make_unique<FloatConst>(*ty, string(str), false);
} else {
c = make_unique<FloatConst>(*ty,
toString(apfloat.bitcastToAPInt(), 10, false),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very surprised we would need this patch. Either bitcastToAPInt is not working correctly, or something is off with the printing in constant.cpp. Representing the bit pattern of the number should be the most precise way of storing it.

true);
}
auto ret = c.get();
current_fn->addConstant(std::move(c));
RETURN_CACHE(ret);
Expand Down
Loading