Skip to content

Commit e6cd0d0

Browse files
committed
address pr comments
1 parent 916d845 commit e6cd0d0

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
@@ -2708,9 +2708,9 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
27082708
case Intrinsic::spv_sign:
27092709
return selectSign(ResVReg, ResType, I);
27102710
case Intrinsic::spv_firstbituhigh: // There is no CL equivalent of FindUMsb
2711-
return selectFirstBitHigh(ResVReg, ResType, I, false);
2711+
return selectFirstBitHigh(ResVReg, ResType, I, /*IsSigned=*/false);
27122712
case Intrinsic::spv_firstbitshigh: // There is no CL equivalent of FindSMsb
2713-
return selectFirstBitHigh(ResVReg, ResType, I, true);
2713+
return selectFirstBitHigh(ResVReg, ResType, I, /*IsSigned=*/true);
27142714
case Intrinsic::spv_group_memory_barrier_with_group_sync: {
27152715
Register MemSemReg =
27162716
buildI32Constant(SPIRV::MemorySemantics::SequentiallyConsistent, I);
@@ -2889,32 +2889,30 @@ bool SPIRVInstructionSelector::selectFirstBitHigh64(Register ResVReg,
28892889
// count should be one.
28902890

28912891
Register HighReg = MRI->createVirtualRegister(GR.getRegClass(VResType));
2892-
auto MIB =
2893-
BuildMI(*I.getParent(), I, I.getDebugLoc(),
2894-
TII.get(SPIRV::OpVectorShuffle))
2895-
.addDef(HighReg)
2896-
.addUse(GR.getSPIRVTypeID(VResType))
2897-
.addUse(FBHReg)
2898-
.addUse(
2899-
FBHReg); // this vector will not be selected from; could be empty
2900-
unsigned i;
2901-
for (i = 0; i < count * 2; i += 2) {
2902-
MIB.addImm(i);
2892+
auto MIB = BuildMI(*I.getParent(), I, I.getDebugLoc(),
2893+
TII.get(SPIRV::OpVectorShuffle))
2894+
.addDef(HighReg)
2895+
.addUse(GR.getSPIRVTypeID(VResType))
2896+
.addUse(FBHReg)
2897+
.addUse(FBHReg);
2898+
// ^^ this vector will not be selected from; could be empty
2899+
unsigned j;
2900+
for (j = 0; j < count * 2; j += 2) {
2901+
MIB.addImm(j);
29032902
}
29042903
Result &= MIB.constrainAllUses(TII, TRI, RBI);
29052904

29062905
// get low bits
29072906
Register LowReg = MRI->createVirtualRegister(GR.getRegClass(VResType));
2908-
MIB =
2909-
BuildMI(*I.getParent(), I, I.getDebugLoc(),
2910-
TII.get(SPIRV::OpVectorShuffle))
2911-
.addDef(LowReg)
2912-
.addUse(GR.getSPIRVTypeID(VResType))
2913-
.addUse(FBHReg)
2914-
.addUse(
2915-
FBHReg); // this vector will not be selected from; could be empty
2916-
for (i = 1; i < count * 2; i += 2) {
2917-
MIB.addImm(i);
2907+
MIB = BuildMI(*I.getParent(), I, I.getDebugLoc(),
2908+
TII.get(SPIRV::OpVectorShuffle))
2909+
.addDef(LowReg)
2910+
.addUse(GR.getSPIRVTypeID(VResType))
2911+
.addUse(FBHReg)
2912+
.addUse(FBHReg);
2913+
// ^^ this vector will not be selected from; could be empty
2914+
for (j = 1; j < count * 2; j += 2) {
2915+
MIB.addImm(j);
29182916
}
29192917
Result &= MIB.constrainAllUses(TII, TRI, RBI);
29202918

@@ -2943,6 +2941,7 @@ bool SPIRVInstructionSelector::selectFirstBitHigh64(Register ResVReg,
29432941
Register AddReg = ResVReg;
29442942
if (isScalarRes)
29452943
AddReg = MRI->createVirtualRegister(GR.getRegClass(VResType));
2944+
29462945
Result &= selectNAryOpWithSrcs(AddReg, VResType, I, {ValReg, TmpReg},
29472946
SPIRV::OpIAddV);
29482947

@@ -2960,17 +2959,21 @@ bool SPIRVInstructionSelector::selectFirstBitHigh(Register ResVReg,
29602959
const SPIRVType *ResType,
29612960
MachineInstr &I,
29622961
bool IsSigned) const {
2963-
// FindUMsb intrinsic only supports 32 bit integers
2962+
// FindUMsb and FindSMsb intrinsics only support 32 bit integers
29642963
Register OpReg = I.getOperand(2).getReg();
29652964
SPIRVType *OpType = GR.getSPIRVTypeForVReg(OpReg);
2966-
unsigned bitWidth = GR.getScalarOrVectorBitWidth(OpType);
29672965

2968-
if (bitWidth == 16)
2966+
switch (GR.getScalarOrVectorBitWidth(OpType)) {
2967+
case 16:
29692968
return selectFirstBitHigh16(ResVReg, ResType, I, IsSigned);
2970-
else if (bitWidth == 32)
2969+
case 32:
29712970
return selectFirstBitHigh32(ResVReg, ResType, I, OpReg, IsSigned);
2972-
else // 64 bit
2971+
case 64:
29732972
return selectFirstBitHigh64(ResVReg, ResType, I, IsSigned);
2973+
default:
2974+
report_fatal_error(
2975+
"spv_firstbituhigh and spv_firstbitshigh only support 16,32,64 bits.");
2976+
}
29742977
}
29752978

29762979
bool SPIRVInstructionSelector::selectAllocaArray(Register ResVReg,

0 commit comments

Comments
 (0)