Skip to content

Commit 990ffe1

Browse files
committed
address pr comments
1 parent a5cc2af commit 990ffe1

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
@@ -2589,9 +2589,9 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
25892589
case Intrinsic::spv_sign:
25902590
return selectSign(ResVReg, ResType, I);
25912591
case Intrinsic::spv_firstbituhigh: // There is no CL equivalent of FindUMsb
2592-
return selectFirstBitHigh(ResVReg, ResType, I, false);
2592+
return selectFirstBitHigh(ResVReg, ResType, I, /*IsSigned=*/false);
25932593
case Intrinsic::spv_firstbitshigh: // There is no CL equivalent of FindSMsb
2594-
return selectFirstBitHigh(ResVReg, ResType, I, true);
2594+
return selectFirstBitHigh(ResVReg, ResType, I, /*IsSigned=*/true);
25952595
case Intrinsic::spv_lifetime_start:
25962596
case Intrinsic::spv_lifetime_end: {
25972597
unsigned Op = IID == Intrinsic::spv_lifetime_start ? SPIRV::OpLifetimeStart
@@ -2729,32 +2729,30 @@ bool SPIRVInstructionSelector::selectFirstBitHigh64(Register ResVReg,
27292729
// count should be one.
27302730

27312731
Register HighReg = MRI->createVirtualRegister(GR.getRegClass(VResType));
2732-
auto MIB =
2733-
BuildMI(*I.getParent(), I, I.getDebugLoc(),
2734-
TII.get(SPIRV::OpVectorShuffle))
2735-
.addDef(HighReg)
2736-
.addUse(GR.getSPIRVTypeID(VResType))
2737-
.addUse(FBHReg)
2738-
.addUse(
2739-
FBHReg); // this vector will not be selected from; could be empty
2740-
unsigned i;
2741-
for (i = 0; i < count * 2; i += 2) {
2742-
MIB.addImm(i);
2732+
auto MIB = BuildMI(*I.getParent(), I, I.getDebugLoc(),
2733+
TII.get(SPIRV::OpVectorShuffle))
2734+
.addDef(HighReg)
2735+
.addUse(GR.getSPIRVTypeID(VResType))
2736+
.addUse(FBHReg)
2737+
.addUse(FBHReg);
2738+
// ^^ this vector will not be selected from; could be empty
2739+
unsigned j;
2740+
for (j = 0; j < count * 2; j += 2) {
2741+
MIB.addImm(j);
27432742
}
27442743
Result &= MIB.constrainAllUses(TII, TRI, RBI);
27452744

27462745
// get low bits
27472746
Register LowReg = MRI->createVirtualRegister(GR.getRegClass(VResType));
2748-
MIB =
2749-
BuildMI(*I.getParent(), I, I.getDebugLoc(),
2750-
TII.get(SPIRV::OpVectorShuffle))
2751-
.addDef(LowReg)
2752-
.addUse(GR.getSPIRVTypeID(VResType))
2753-
.addUse(FBHReg)
2754-
.addUse(
2755-
FBHReg); // this vector will not be selected from; could be empty
2756-
for (i = 1; i < count * 2; i += 2) {
2757-
MIB.addImm(i);
2747+
MIB = BuildMI(*I.getParent(), I, I.getDebugLoc(),
2748+
TII.get(SPIRV::OpVectorShuffle))
2749+
.addDef(LowReg)
2750+
.addUse(GR.getSPIRVTypeID(VResType))
2751+
.addUse(FBHReg)
2752+
.addUse(FBHReg);
2753+
// ^^ this vector will not be selected from; could be empty
2754+
for (j = 1; j < count * 2; j += 2) {
2755+
MIB.addImm(j);
27582756
}
27592757
Result &= MIB.constrainAllUses(TII, TRI, RBI);
27602758

@@ -2783,6 +2781,7 @@ bool SPIRVInstructionSelector::selectFirstBitHigh64(Register ResVReg,
27832781
Register AddReg = ResVReg;
27842782
if (isScalarRes)
27852783
AddReg = MRI->createVirtualRegister(GR.getRegClass(VResType));
2784+
27862785
Result &= selectNAryOpWithSrcs(AddReg, VResType, I, {ValReg, TmpReg},
27872786
SPIRV::OpIAddV);
27882787

@@ -2800,17 +2799,21 @@ bool SPIRVInstructionSelector::selectFirstBitHigh(Register ResVReg,
28002799
const SPIRVType *ResType,
28012800
MachineInstr &I,
28022801
bool IsSigned) const {
2803-
// FindUMsb intrinsic only supports 32 bit integers
2802+
// FindUMsb and FindSMsb intrinsics only support 32 bit integers
28042803
Register OpReg = I.getOperand(2).getReg();
28052804
SPIRVType *OpType = GR.getSPIRVTypeForVReg(OpReg);
2806-
unsigned bitWidth = GR.getScalarOrVectorBitWidth(OpType);
28072805

2808-
if (bitWidth == 16)
2806+
switch (GR.getScalarOrVectorBitWidth(OpType)) {
2807+
case 16:
28092808
return selectFirstBitHigh16(ResVReg, ResType, I, IsSigned);
2810-
else if (bitWidth == 32)
2809+
case 32:
28112810
return selectFirstBitHigh32(ResVReg, ResType, I, OpReg, IsSigned);
2812-
else // 64 bit
2811+
case 64:
28132812
return selectFirstBitHigh64(ResVReg, ResType, I, IsSigned);
2813+
default:
2814+
report_fatal_error(
2815+
"spv_firstbituhigh and spv_firstbitshigh only support 16,32,64 bits.");
2816+
}
28142817
}
28152818

28162819
bool SPIRVInstructionSelector::selectAllocaArray(Register ResVReg,

0 commit comments

Comments
 (0)