@@ -256,6 +256,9 @@ class SPIRVInstructionSelector : public InstructionSelector {
256256 bool selectSpvThreadId (Register ResVReg, const SPIRVType *ResType,
257257 MachineInstr &I) const ;
258258
259+ bool selectWaveActiveCountBits (Register ResVReg, const SPIRVType *ResType,
260+ MachineInstr &I) const ;
261+
259262 bool selectWaveReadLaneAt (Register ResVReg, const SPIRVType *ResType,
260263 MachineInstr &I) const ;
261264
@@ -1917,6 +1920,37 @@ bool SPIRVInstructionSelector::selectSign(Register ResVReg,
19171920 return Result;
19181921}
19191922
1923+ bool SPIRVInstructionSelector::selectWaveActiveCountBits (
1924+ Register ResVReg, const SPIRVType *ResType, MachineInstr &I) const {
1925+ assert (I.getNumOperands () == 3 );
1926+ assert (I.getOperand (2 ).isReg ());
1927+ MachineBasicBlock &BB = *I.getParent ();
1928+
1929+ SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType (32 , I, TII);
1930+ SPIRVType *BallotType = GR.getOrCreateSPIRVVectorType (IntTy, 4 , I, TII);
1931+ Register BallotReg = MRI->createVirtualRegister (GR.getRegClass (BallotType));
1932+
1933+ bool Result =
1934+ BuildMI (BB, I, I.getDebugLoc (), TII.get (SPIRV::OpGroupNonUniformBallot))
1935+ .addDef (BallotReg)
1936+ .addUse (GR.getSPIRVTypeID (BallotType))
1937+ .addUse (GR.getOrCreateConstInt (SPIRV::Scope::Subgroup, I, IntTy, TII))
1938+ .addUse (I.getOperand (2 ).getReg ())
1939+ .constrainAllUses (TII, TRI, RBI);
1940+
1941+ Result &=
1942+ BuildMI (BB, I, I.getDebugLoc (),
1943+ TII.get (SPIRV::OpGroupNonUniformBallotBitCount))
1944+ .addDef (ResVReg)
1945+ .addUse (GR.getSPIRVTypeID (ResType))
1946+ .addUse (GR.getOrCreateConstInt (SPIRV::Scope::Subgroup, I, IntTy, TII))
1947+ .addImm (SPIRV::GroupOperation::Reduce)
1948+ .addUse (BallotReg)
1949+ .constrainAllUses (TII, TRI, RBI);
1950+
1951+ return Result;
1952+ }
1953+
19201954bool SPIRVInstructionSelector::selectWaveReadLaneAt (Register ResVReg,
19211955 const SPIRVType *ResType,
19221956 MachineInstr &I) const {
@@ -2745,6 +2779,8 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
27452779 return selectExtInst (ResVReg, ResType, I, CL::u_clamp, GL::UClamp);
27462780 case Intrinsic::spv_sclamp:
27472781 return selectExtInst (ResVReg, ResType, I, CL::s_clamp, GL::SClamp);
2782+ case Intrinsic::spv_wave_active_countbits:
2783+ return selectWaveActiveCountBits (ResVReg, ResType, I);
27482784 case Intrinsic::spv_wave_is_first_lane: {
27492785 SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType (32 , I, TII);
27502786 return BuildMI (BB, I, I.getDebugLoc (),
0 commit comments