diff options
author | Artem Belevich <tra@google.com> | 2018-04-06 22:25:08 +0000 |
---|---|---|
committer | Artem Belevich <tra@google.com> | 2018-04-06 22:25:08 +0000 |
commit | 256777471ea1e380b5f5ff3a1e816564100bd43c (patch) | |
tree | 925e69af0c5b447134f82459be640bbdeb0fe6c8 /llvm/lib/Target/NVPTX | |
parent | 90f5d2c28d664ad3bdb3266a5927bf303220ebef (diff) |
[NVPTX] add support for initializing fp16 arrays.
Previously HalfTy was not handled which would either trigger an assertion,
or result in array initialized with garbage.
Differential Revision: https://reviews.llvm.org/D45391
Diffstat (limited to 'llvm/lib/Target/NVPTX')
-rw-r--r-- | llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp index 357e24136a5..2fd0689b1aa 100644 --- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -1945,11 +1945,17 @@ void NVPTXAsmPrinter::bufferLEByte(const Constant *CPV, int Bytes, llvm_unreachable("unsupported integer const type"); break; } + case Type::HalfTyID: case Type::FloatTyID: case Type::DoubleTyID: { const ConstantFP *CFP = dyn_cast<ConstantFP>(CPV); Type *Ty = CFP->getType(); - if (Ty == Type::getFloatTy(CPV->getContext())) { + if (Ty == Type::getHalfTy(CPV->getContext())) { + APInt API = CFP->getValueAPF().bitcastToAPInt(); + uint16_t float16 = API.getLoBits(16).getZExtValue(); + ConvertIntToBytes<>(ptr, float16); + aggBuffer->addBytes(ptr, 2, Bytes); + } else if (Ty == Type::getFloatTy(CPV->getContext())) { float float32 = (float) CFP->getValueAPF().convertToFloat(); ConvertFloatToBytes(ptr, float32); aggBuffer->addBytes(ptr, 4, Bytes); |