Skip to content

Commit

Permalink
Merge from 'master' to 'xmain-web' (KhronosGroup#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
iclsrc committed Feb 3, 2021
2 parents ce10ba6 + bec81d1 commit 598f901
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 9 additions & 5 deletions lib/SPIRV/SPIRVToOCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ std::string SPIRVToOCL::groupOCToOCLBuiltinName(CallInst *CI, Op OC) {
return FuncName;
}

static bool extendRetTyToi32(Op OC) {
/// Return true if the original boolean return type needs to be changed to i32
/// when mapping the SPIR-V op to an OpenCL builtin.
static bool needsInt32RetTy(Op OC) {
return OC == OpGroupAny || OC == OpGroupAll || OC == OpGroupNonUniformAny ||
OC == OpGroupNonUniformAll || OC == OpGroupNonUniformAllEqual ||
OC == OpGroupNonUniformElect || OC == OpGroupNonUniformInverseBallot ||
Expand All @@ -408,15 +410,17 @@ void SPIRVToOCL::visitCallSPIRVGroupBuiltin(CallInst *CI, Op OC) {
Args[0] = CastInst::CreateZExtOrBitCast(Args[0], Int32Ty, "", CI);

// Handle function return type
if (extendRetTyToi32(OC))
if (needsInt32RetTy(OC))
RetTy = Int32Ty;

return FuncName;
};
auto ModifyRetTy = [=](CallInst *CI) -> Instruction * {
if (extendRetTyToi32(OC)) {
Type *RetTy = Type::getInt1Ty(*Ctx);
return CastInst::CreateTruncOrBitCast(CI, RetTy, "", CI->getNextNode());
if (needsInt32RetTy(OC)) {
// The OpenCL builtin returns a non-zero integer value. Convert to a
// boolean value.
Constant *Zero = ConstantInt::get(CI->getType(), 0);
return new ICmpInst(CI->getNextNode(), CmpInst::ICMP_NE, CI, Zero);
} else
return CI;
};
Expand Down
6 changes: 4 additions & 2 deletions test/transcoding/sub_group_ballot.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1054,8 +1054,10 @@ declare dso_local spir_func double @_Z25sub_group_broadcast_firstd(double) local

; CHECK-LLVM-LABEL: @testBallotOperations
; CHECK-LLVM: %[[ballot:[0-9]+]] = call spir_func <4 x i32> @_Z16sub_group_balloti(i32 {{.*}})
; CHECK-LLVM: call spir_func i32 @_Z24sub_group_inverse_ballotDv4_j(<4 x i32> %[[ballot]])
; CHECK-LLVM: call spir_func i32 @_Z28sub_group_ballot_bit_extractDv4_jj(<4 x i32> %[[ballot]], i32 0)
; CHECK-LLVM: %[[inverse_ballot:[0-9]+]] = call spir_func i32 @_Z24sub_group_inverse_ballotDv4_j(<4 x i32> %[[ballot]])
; CHECK-LLVM-NEXT: icmp ne i32 %[[inverse_ballot]], 0
; CHECK-LLVM: %[[bit_extract:[0-9]+]] = call spir_func i32 @_Z28sub_group_ballot_bit_extractDv4_jj(<4 x i32> %[[ballot]], i32 0)
; CHECK-LLVM-NEXT: icmp ne i32 %[[bit_extract]], 0
; CHECK-LLVM: call spir_func i32 @_Z26sub_group_ballot_bit_countDv4_j(<4 x i32> %[[ballot]])
; CHECK-LLVM: call spir_func i32 @_Z31sub_group_ballot_inclusive_scanDv4_j(<4 x i32> %[[ballot]])
; CHECK-LLVM: call spir_func i32 @_Z31sub_group_ballot_exclusive_scanDv4_j(<4 x i32> %[[ballot]])
Expand Down

0 comments on commit 598f901

Please sign in to comment.