Skip to content

Commit 79f8455

Browse files
committed
address review comments
1 parent b935d6b commit 79f8455

File tree

3 files changed

+9
-35
lines changed

3 files changed

+9
-35
lines changed

llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,15 +1106,6 @@ static void translateGetSurfaceIndex(CallInst &CI) {
11061106
CI.replaceAllUsesWith(SI);
11071107
}
11081108

1109-
static void translateBitcast(CallInst &CI) {
1110-
auto opnd = CI.getArgOperand(0);
1111-
IRBuilder<> Builder(&CI);
1112-
auto BC = Builder.CreateBitCast(opnd, CI.getType());
1113-
auto *SI = cast<CastInst>(BC);
1114-
SI->setDebugLoc(CI.getDebugLoc());
1115-
CI.replaceAllUsesWith(SI);
1116-
}
1117-
11181109
// Newly created GenX intrinsic might have different return type than expected.
11191110
// This helper function creates cast operation from GenX intrinsic return type
11201111
// to currently expected. Returns pointer to created cast instruction if it
@@ -1775,11 +1766,6 @@ size_t SYCLLowerESIMDPass::runOnFunction(Function &F,
17751766
ToErase.push_back(CI);
17761767
continue;
17771768
}
1778-
if (Name.startswith("__esimd_bitcast")) {
1779-
translateBitcast(*CI);
1780-
ToErase.push_back(CI);
1781-
continue;
1782-
}
17831769
assert(!Name.startswith("__esimd_set_kernel_properties") &&
17841770
"__esimd_set_kernel_properties must have been lowered");
17851771

sycl/include/sycl/ext/intel/esimd/detail/bfloat16_type_traits.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ using bfloat16 = sycl::ext::oneapi::experimental::bfloat16;
2525

2626
template <> struct element_type_traits<bfloat16> {
2727
// TODO map the raw type to __bf16 once SPIRV target supports it:
28-
using RawT =
29-
typename std::invoke_result_t<decltype(&bfloat16::raw), bfloat16>;
28+
using RawT = uint_type_t<sizeof(bfloat16)>;
3029
// Nearest standard enclosing C++ type to delegate natively unsupported
3130
// operations to:
3231
using EnclosingCppT = float;
@@ -54,12 +53,12 @@ template <int N> struct vector_conversion_traits<bfloat16, N> {
5453
using RawVecT = vector_type_t<vc_be_bfloat16_raw_t, N>;
5554
RawVecT ConvVal = __esimd_bf_cvt<vc_be_bfloat16_raw_t, StdT, N>(Val);
5655
// cast from _Float16 to int16_t:
57-
return __esimd_bitcast<vector_type_t<RawT, N>>(ConvVal);
56+
return sycl::bit_cast<vector_type_t<RawT, N>>(ConvVal);
5857
#else
5958
vector_type_t<RawT, N> Output = 0;
6059

6160
for (int i = 0; i < N; i++) {
62-
Output[i] = bfloat16(Val[i]).raw();
61+
Output[i] = sycl::bit_cast<RawT>(Val[i]);
6362
}
6463
return Output;
6564
#endif // __SYCL_DEVICE_ONLY__
@@ -69,26 +68,28 @@ template <int N> struct vector_conversion_traits<bfloat16, N> {
6968
convert_to_cpp(vector_type_t<RawT, N> Val) {
7069
#ifdef __SYCL_DEVICE_ONLY__
7170
using RawVecT = vector_type_t<vc_be_bfloat16_raw_t, N>;
72-
RawVecT Bits = __esimd_bitcast<RawVecT>(Val);
71+
RawVecT Bits = sycl::bit_cast<RawVecT>(Val);
7372
return __esimd_bf_cvt<StdT, vc_be_bfloat16_raw_t, N>(Bits);
7473
#else
7574
vector_type_t<StdT, N> Output;
7675

7776
for (int i = 0; i < N; i++) {
78-
Output[i] = bfloat16::from_bits(Val[i]);
77+
Output[i] = sycl::bit_cast<bfloat16>(Val[i]);
7978
}
8079
return Output;
8180
#endif // __SYCL_DEVICE_ONLY__
8281
}
8382
};
8483

84+
// TODO: remove bitcasts from the scalar_conversion_traits, and replace with
85+
// sycl::bit_cast directly
8586
template <> struct scalar_conversion_traits<bfloat16> {
8687
using RawT = __raw_t<bfloat16>;
8788

88-
static ESIMD_INLINE RawT bitcast_to_raw(bfloat16 Val) { return Val.raw(); }
89+
static ESIMD_INLINE RawT bitcast_to_raw(bfloat16 Val) { return sycl::bit_cast<RawT>(Val); }
8990

9091
static ESIMD_INLINE bfloat16 bitcast_to_wrapper(RawT Val) {
91-
return bfloat16::from_bits(Val);
92+
return sycl::bit_cast<bfloat16>(Val);
9293
}
9394
};
9495

sycl/include/sycl/ext/intel/esimd/detail/intrin.hpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,6 @@ __esimd_wrindirect(__ESIMD_DNS::vector_type_t<T, N> OldVal,
337337
}
338338
#endif // __SYCL_DEVICE_ONLY__
339339

340-
// TODO should be replaced by std::bit_cast once C++20 is supported.
341-
template <class To, class From,
342-
class = std::enable_if_t<sizeof(From) == sizeof(To)>>
343-
__ESIMD_INTRIN To __esimd_bitcast(From Src)
344-
#ifdef __SYCL_DEVICE_ONLY__
345-
;
346-
#else
347-
{
348-
auto *Ptr = reinterpret_cast<To *>(&Src);
349-
return *Ptr;
350-
}
351-
#endif // __SYCL_DEVICE_ONLY__
352-
353340
#ifdef __SYCL_DEVICE_ONLY__
354341
// This intrinsic requires one of the types to be _Float16, which is absent on
355342
// host, so it can't be represented on host. Callers must emulate it.

0 commit comments

Comments
 (0)