1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

[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

llvm-svn: 329463
This commit is contained in:
Artem Belevich 2018-04-06 22:25:08 +00:00
parent 7d82dad4b5
commit a30930c676
2 changed files with 11 additions and 1 deletions

View File

@ -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);

View File

@ -1,5 +1,9 @@
; RUN: llc < %s -march=nvptx | FileCheck %s
; CHECK: .b8 half_array[8] = {1, 2, 3, 4, 5, 6, 7, 8};
@"half_array" = addrspace(1) constant [4 x half]
[half 0xH0201, half 0xH0403, half 0xH0605, half 0xH0807]
define void @test_load_store(half addrspace(1)* %in, half addrspace(1)* %out) {
; CHECK-LABEL: @test_load_store
; CHECK: ld.global.b16 [[TMP:%h[0-9]+]], [{{%r[0-9]+}}]