Skip to content

Commit a3984e5

Browse files
committed
fix scalar relational operator translation.
The CL spec for relational operators says that for scalar values the return value is 0/1 not 0/-1 which is for vectors. Fix the translator to use 0/1 when it's a scalar operator.
1 parent a9391f7 commit a3984e5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/SPIRV/OCLToSPIRV.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -1137,11 +1137,15 @@ void OCLToSPIRVBase::visitCallRelational(CallInst *CI,
11371137
OCLSPIRVBuiltinMap::find(DemangledName.str(), &OC);
11381138
// i1 or <i1 x N>, depending on whether it returns a vector type.
11391139
Type *BoolTy = CI->getType()->getWithNewType(Type::getInt1Ty(*Ctx));
1140-
mutateCallInst(CI, OC).changeReturnType(BoolTy, [=](IRBuilder<> &Builder,
1141-
CallInst *NewCI) {
1142-
return Builder.CreateSelect(NewCI, Constant::getAllOnesValue(CI->getType()),
1143-
Constant::getNullValue(CI->getType()));
1144-
});
1140+
mutateCallInst(CI, OC).changeReturnType(
1141+
BoolTy, [=](IRBuilder<> &Builder, CallInst *NewCI) {
1142+
Constant *ResultTrue =
1143+
CI->getType()->isVectorTy()
1144+
? Constant::getAllOnesValue(CI->getType())
1145+
: Constant::getIntegerValue(CI->getType(), APInt(32, 1));
1146+
return Builder.CreateSelect(NewCI, ResultTrue,
1147+
Constant::getNullValue(CI->getType()));
1148+
});
11451149
}
11461150

11471151
void OCLToSPIRVBase::visitCallVecLoadStore(CallInst *CI, StringRef MangledName,

0 commit comments

Comments
 (0)