Skip to content

Commit 85a1d4e

Browse files
committed
address pr comments
1 parent 2b0e964 commit 85a1d4e

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

clang/test/CodeGenHLSL/builtins/firstbithigh.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,4 @@ uint3 test_firstbithigh_long3(int64_t3 p0) {
150150
// CHECK: call <4 x i32> @llvm.[[TARGET]].firstbitshigh.v4i64
151151
uint4 test_firstbithigh_long4(int64_t4 p0) {
152152
return firstbithigh(p0);
153-
}
153+
}

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,9 +2590,9 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
25902590
case Intrinsic::spv_sign:
25912591
return selectSign(ResVReg, ResType, I);
25922592
case Intrinsic::spv_firstbituhigh: // There is no CL equivalent of FindUMsb
2593-
return selectFirstBitHigh(ResVReg, ResType, I, false);
2593+
return selectFirstBitHigh(ResVReg, ResType, I, /*IsSigned=*/false);
25942594
case Intrinsic::spv_firstbitshigh: // There is no CL equivalent of FindSMsb
2595-
return selectFirstBitHigh(ResVReg, ResType, I, true);
2595+
return selectFirstBitHigh(ResVReg, ResType, I, /*IsSigned=*/true);
25962596
case Intrinsic::spv_group_memory_barrier_with_group_sync: {
25972597
Register MemSemReg =
25982598
buildI32Constant(SPIRV::MemorySemantics::SequentiallyConsistent, I);
@@ -2771,32 +2771,30 @@ bool SPIRVInstructionSelector::selectFirstBitHigh64(Register ResVReg,
27712771
// count should be one.
27722772

27732773
Register HighReg = MRI->createVirtualRegister(GR.getRegClass(VResType));
2774-
auto MIB =
2775-
BuildMI(*I.getParent(), I, I.getDebugLoc(),
2776-
TII.get(SPIRV::OpVectorShuffle))
2777-
.addDef(HighReg)
2778-
.addUse(GR.getSPIRVTypeID(VResType))
2779-
.addUse(FBHReg)
2780-
.addUse(
2781-
FBHReg); // this vector will not be selected from; could be empty
2782-
unsigned i;
2783-
for (i = 0; i < count * 2; i += 2) {
2784-
MIB.addImm(i);
2774+
auto MIB = BuildMI(*I.getParent(), I, I.getDebugLoc(),
2775+
TII.get(SPIRV::OpVectorShuffle))
2776+
.addDef(HighReg)
2777+
.addUse(GR.getSPIRVTypeID(VResType))
2778+
.addUse(FBHReg)
2779+
.addUse(FBHReg);
2780+
// ^^ this vector will not be selected from; could be empty
2781+
unsigned j;
2782+
for (j = 0; j < count * 2; j += 2) {
2783+
MIB.addImm(j);
27852784
}
27862785
Result &= MIB.constrainAllUses(TII, TRI, RBI);
27872786

27882787
// get low bits
27892788
Register LowReg = MRI->createVirtualRegister(GR.getRegClass(VResType));
2790-
MIB =
2791-
BuildMI(*I.getParent(), I, I.getDebugLoc(),
2792-
TII.get(SPIRV::OpVectorShuffle))
2793-
.addDef(LowReg)
2794-
.addUse(GR.getSPIRVTypeID(VResType))
2795-
.addUse(FBHReg)
2796-
.addUse(
2797-
FBHReg); // this vector will not be selected from; could be empty
2798-
for (i = 1; i < count * 2; i += 2) {
2799-
MIB.addImm(i);
2789+
MIB = BuildMI(*I.getParent(), I, I.getDebugLoc(),
2790+
TII.get(SPIRV::OpVectorShuffle))
2791+
.addDef(LowReg)
2792+
.addUse(GR.getSPIRVTypeID(VResType))
2793+
.addUse(FBHReg)
2794+
.addUse(FBHReg);
2795+
// ^^ this vector will not be selected from; could be empty
2796+
for (j = 1; j < count * 2; j += 2) {
2797+
MIB.addImm(j);
28002798
}
28012799
Result &= MIB.constrainAllUses(TII, TRI, RBI);
28022800

@@ -2825,6 +2823,7 @@ bool SPIRVInstructionSelector::selectFirstBitHigh64(Register ResVReg,
28252823
Register AddReg = ResVReg;
28262824
if (isScalarRes)
28272825
AddReg = MRI->createVirtualRegister(GR.getRegClass(VResType));
2826+
28282827
Result &= selectNAryOpWithSrcs(AddReg, VResType, I, {ValReg, TmpReg},
28292828
SPIRV::OpIAddV);
28302829

@@ -2842,17 +2841,21 @@ bool SPIRVInstructionSelector::selectFirstBitHigh(Register ResVReg,
28422841
const SPIRVType *ResType,
28432842
MachineInstr &I,
28442843
bool IsSigned) const {
2845-
// FindUMsb intrinsic only supports 32 bit integers
2844+
// FindUMsb and FindSMsb intrinsics only support 32 bit integers
28462845
Register OpReg = I.getOperand(2).getReg();
28472846
SPIRVType *OpType = GR.getSPIRVTypeForVReg(OpReg);
2848-
unsigned bitWidth = GR.getScalarOrVectorBitWidth(OpType);
28492847

2850-
if (bitWidth == 16)
2848+
switch (GR.getScalarOrVectorBitWidth(OpType)) {
2849+
case 16:
28512850
return selectFirstBitHigh16(ResVReg, ResType, I, IsSigned);
2852-
else if (bitWidth == 32)
2851+
case 32:
28532852
return selectFirstBitHigh32(ResVReg, ResType, I, OpReg, IsSigned);
2854-
else // 64 bit
2853+
case 64:
28552854
return selectFirstBitHigh64(ResVReg, ResType, I, IsSigned);
2855+
default:
2856+
report_fatal_error(
2857+
"spv_firstbituhigh and spv_firstbitshigh only support 16,32,64 bits.");
2858+
}
28562859
}
28572860

28582861
bool SPIRVInstructionSelector::selectAllocaArray(Register ResVReg,

0 commit comments

Comments
 (0)