Skip to content

Commit c3feab4

Browse files
AlexeySachkovaneshlya
authored andcommitted
Fix generation of min/max calls for SYCL
SYCL 2020 specification does not define min/max overloads accepting `bool` data type, but yarpgen generates code that calls them. Of course, such code does not compile and to fix this, we do a promotion from `bool` to `char` (or `signed char`, to be precise). Signed-off-by: Alexey Sachkov <alexey.sachkov@intel.com>
1 parent a62446a commit c3feab4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/expr.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,6 +3033,21 @@ void LibCallExpr::cxxArgPromotion(std::shared_ptr<Expr> &arg,
30333033
true);
30343034
}
30353035

3036+
// SYCL 2020 specification defines min and max as accepting two GenInt values.
3037+
// GenInt does *not* include bool, so we need to turn it into a char.
3038+
void static syclBoolPromotion(std::shared_ptr<Expr> &expr) {
3039+
auto expr_type = expr->getValue()->getType();
3040+
if (!expr_type->isIntType())
3041+
return;
3042+
3043+
auto expr_int_type = std::static_pointer_cast<IntegralType>(expr_type);
3044+
if (expr_int_type->getIntTypeId() != IntTypeID::BOOL)
3045+
return;
3046+
3047+
auto int_type = IntegralType::init(IntTypeID::SCHAR);
3048+
expr = std::make_shared<TypeCastExpr>(expr, int_type, false);
3049+
}
3050+
30363051
MinMaxCallBase::MinMaxCallBase(std::shared_ptr<Expr> _a,
30373052
std::shared_ptr<Expr> _b, LibCallKind _kind)
30383053
: a(std::move(_a)), b(std::move(_b)), kind(_kind) {}
@@ -3052,6 +3067,11 @@ bool MinMaxCallBase::propagateType() {
30523067
ispcBoolPromotion(b);
30533068
}
30543069

3070+
if (options.isSYCL()) {
3071+
syclBoolPromotion(a);
3072+
syclBoolPromotion(b);
3073+
}
3074+
30553075
IntTypeID top_type_id = getTopIntID({a, b});
30563076
cxxArgPromotion(a, top_type_id);
30573077
cxxArgPromotion(b, top_type_id);

0 commit comments

Comments
 (0)