Commit cb465e7e by PENGUINLIONG Committed by Tianqi Chen

Fix boolean type (#862)

parent 79d503fd
...@@ -311,6 +311,15 @@ Value IRBuilder::GetConst_(const SType& dtype, const uint64_t* pvalue) { ...@@ -311,6 +311,15 @@ Value IRBuilder::GetConst_(const SType& dtype, const uint64_t* pvalue) {
} }
CHECK_LE(dtype.type.bits(), 64); CHECK_LE(dtype.type.bits(), 64);
Value ret = NewValue(dtype, kConstant); Value ret = NewValue(dtype, kConstant);
if (1 == dtype.type.bits() && dtype.is_uint()) {
// Boolean types.
if (*pvalue) {
ib_.Begin(spv::OpConstantTrue).AddSeq(ret);
} else {
ib_.Begin(spv::OpConstantFalse).AddSeq(ret);
}
} else {
// Integral/floating-point types.
ib_.Begin(spv::OpConstant).AddSeq(dtype, ret); ib_.Begin(spv::OpConstant).AddSeq(dtype, ret);
uint64_t mask = 0xFFFFFFFFUL; uint64_t mask = 0xFFFFFFFFUL;
ib_.Add(static_cast<uint32_t>(pvalue[0] & mask)); ib_.Add(static_cast<uint32_t>(pvalue[0] & mask));
...@@ -324,6 +333,7 @@ Value IRBuilder::GetConst_(const SType& dtype, const uint64_t* pvalue) { ...@@ -324,6 +333,7 @@ Value IRBuilder::GetConst_(const SType& dtype, const uint64_t* pvalue) {
ib_.Add(static_cast<uint32_t>((pvalue[0] >> 32UL) & mask)); ib_.Add(static_cast<uint32_t>((pvalue[0] >> 32UL) & mask));
} }
} }
}
ib_.Commit(&global_); ib_.Commit(&global_);
const_tbl_[key] = ret; const_tbl_[key] = ret;
return ret; return ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment