Skip to content

Commit 525a662

Browse files
committed
Address comments
1 parent 553335f commit 525a662

File tree

1 file changed

+51
-54
lines changed

1 file changed

+51
-54
lines changed

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,16 +3191,13 @@ bool SPIRVInstructionSelector::selectFirstBitSet64Overflow(
31913191
// (ie i64x4 -> i64x2, i64x2)
31923192
MachineIRBuilder MIRBuilder(I);
31933193
SPIRVType *OpType = GR.getOrCreateSPIRVIntegerType(64, MIRBuilder);
3194-
SPIRVType *LeftOpType;
3195-
SPIRVType *LeftResType;
3194+
SPIRVType *LeftOpType = OpType;
3195+
SPIRVType *LeftResType = BaseType;
31963196
if (LeftIsVector) {
31973197
LeftOpType =
31983198
GR.getOrCreateSPIRVVectorType(OpType, LeftComponentCount, MIRBuilder);
31993199
LeftResType =
32003200
GR.getOrCreateSPIRVVectorType(BaseType, LeftComponentCount, MIRBuilder);
3201-
} else {
3202-
LeftOpType = OpType;
3203-
LeftResType = BaseType;
32043201
}
32053202

32063203
SPIRVType *RightOpType =
@@ -3212,8 +3209,6 @@ bool SPIRVInstructionSelector::selectFirstBitSet64Overflow(
32123209
Register RightSideIn =
32133210
MRI->createVirtualRegister(GR.getRegClass(RightOpType));
32143211

3215-
bool Result;
3216-
32173212
// Extract the left half from the SrcReg into LeftSideIn
32183213
// accounting for the special case when it only has one element
32193214
if (LeftIsVector) {
@@ -3225,14 +3220,16 @@ bool SPIRVInstructionSelector::selectFirstBitSet64Overflow(
32253220
// Per the spec, repeat the vector if only one vec is needed
32263221
.addUse(SrcReg);
32273222

3228-
for (unsigned J = 0; J < LeftComponentCount; J++) {
3223+
for (unsigned J = 0; J < LeftComponentCount; J++)
32293224
MIB.addImm(J);
3230-
}
32313225

3232-
Result = MIB.constrainAllUses(TII, TRI, RBI);
3226+
if (!MIB.constrainAllUses(TII, TRI, RBI))
3227+
return false;
3228+
32333229
} else {
3234-
Result = selectOpWithSrcs(LeftSideIn, LeftOpType, I, {SrcReg, ConstIntZero},
3235-
SPIRV::OpVectorExtractDynamic);
3230+
if (!selectOpWithSrcs(LeftSideIn, LeftOpType, I, {SrcReg, ConstIntZero},
3231+
SPIRV::OpVectorExtractDynamic))
3232+
return false;
32363233
}
32373234

32383235
// Extract the right half from the SrcReg into RightSideIn.
@@ -3246,28 +3243,28 @@ bool SPIRVInstructionSelector::selectFirstBitSet64Overflow(
32463243
// Per the spec, repeat the vector if only one vec is needed
32473244
.addUse(SrcReg);
32483245

3249-
for (unsigned J = LeftComponentCount; J < ComponentCount; J++) {
3246+
for (unsigned J = LeftComponentCount; J < ComponentCount; J++)
32503247
MIB.addImm(J);
3251-
}
32523248

3253-
Result = Result && MIB.constrainAllUses(TII, TRI, RBI);
3249+
if (!MIB.constrainAllUses(TII, TRI, RBI))
3250+
return false;
32543251

32553252
// Recursively call selectFirstBitSet64 on the 2 halves
32563253
Register LeftSideOut =
32573254
MRI->createVirtualRegister(GR.getRegClass(LeftResType));
32583255
Register RightSideOut =
32593256
MRI->createVirtualRegister(GR.getRegClass(RightResType));
3260-
Result =
3261-
Result && selectFirstBitSet64(LeftSideOut, LeftResType, I, LeftSideIn,
3262-
BitSetOpcode, SwapPrimarySide);
3263-
Result =
3264-
Result && selectFirstBitSet64(RightSideOut, RightResType, I, RightSideIn,
3265-
BitSetOpcode, SwapPrimarySide);
3257+
3258+
if (!selectFirstBitSet64(LeftSideOut, LeftResType, I, LeftSideIn,
3259+
BitSetOpcode, SwapPrimarySide))
3260+
return false;
3261+
if (!selectFirstBitSet64(RightSideOut, RightResType, I, RightSideIn,
3262+
BitSetOpcode, SwapPrimarySide))
3263+
return false;
32663264

32673265
// Join the two resulting registers back into the return type
32683266
// (ie i32x2, i32x2 -> i32x4)
3269-
return Result &&
3270-
selectOpWithSrcs(ResVReg, ResType, I, {LeftSideOut, RightSideOut},
3267+
return selectOpWithSrcs(ResVReg, ResType, I, {LeftSideOut, RightSideOut},
32713268
SPIRV::OpCompositeConstruct);
32723269
}
32733270

@@ -3297,13 +3294,15 @@ bool SPIRVInstructionSelector::selectFirstBitSet64(
32973294
GR.getOrCreateSPIRVVectorType(BaseType, 2 * ComponentCount, MIRBuilder);
32983295
Register BitcastReg =
32993296
MRI->createVirtualRegister(GR.getRegClass(PostCastType));
3300-
bool Result =
3301-
selectOpWithSrcs(BitcastReg, PostCastType, I, {SrcReg}, SPIRV::OpBitcast);
3297+
3298+
if (!selectOpWithSrcs(BitcastReg, PostCastType, I, {SrcReg},
3299+
SPIRV::OpBitcast))
3300+
return false;
33023301

33033302
// 2. Find the first set bit from the primary side for all the pieces in #1
33043303
Register FBSReg = MRI->createVirtualRegister(GR.getRegClass(PostCastType));
3305-
Result = Result && selectFirstBitSet32(FBSReg, PostCastType, I, BitcastReg,
3306-
BitSetOpcode);
3304+
if (!selectFirstBitSet32(FBSReg, PostCastType, I, BitcastReg, BitSetOpcode))
3305+
return false;
33073306

33083307
// 3. Split result vector into high bits and low bits
33093308
Register HighReg = MRI->createVirtualRegister(GR.getRegClass(ResType));
@@ -3312,12 +3311,12 @@ bool SPIRVInstructionSelector::selectFirstBitSet64(
33123311
bool IsScalarRes = ResType->getOpcode() != SPIRV::OpTypeVector;
33133312
if (IsScalarRes) {
33143313
// if scalar do a vector extract
3315-
Result =
3316-
Result && selectOpWithSrcs(HighReg, ResType, I, {FBSReg, ConstIntZero},
3317-
SPIRV::OpVectorExtractDynamic);
3318-
Result =
3319-
Result && selectOpWithSrcs(LowReg, ResType, I, {FBSReg, ConstIntOne},
3320-
SPIRV::OpVectorExtractDynamic);
3314+
if (!selectOpWithSrcs(HighReg, ResType, I, {FBSReg, ConstIntZero},
3315+
SPIRV::OpVectorExtractDynamic))
3316+
return false;
3317+
if (!selectOpWithSrcs(LowReg, ResType, I, {FBSReg, ConstIntOne},
3318+
SPIRV::OpVectorExtractDynamic))
3319+
return false;
33213320
} else {
33223321
// if vector do a shufflevector
33233322
auto MIB = BuildMI(*I.getParent(), I, I.getDebugLoc(),
@@ -3332,7 +3331,9 @@ bool SPIRVInstructionSelector::selectFirstBitSet64(
33323331
for (unsigned J = 0; J < ComponentCount * 2; J += 2) {
33333332
MIB.addImm(J);
33343333
}
3335-
Result = Result && MIB.constrainAllUses(TII, TRI, RBI);
3334+
3335+
if (!MIB.constrainAllUses(TII, TRI, RBI))
3336+
return false;
33363337

33373338
MIB = BuildMI(*I.getParent(), I, I.getDebugLoc(),
33383339
TII.get(SPIRV::OpVectorShuffle))
@@ -3346,7 +3347,8 @@ bool SPIRVInstructionSelector::selectFirstBitSet64(
33463347
for (unsigned J = 1; J < ComponentCount * 2; J += 2) {
33473348
MIB.addImm(J);
33483349
}
3349-
Result = Result && MIB.constrainAllUses(TII, TRI, RBI);
3350+
if (!MIB.constrainAllUses(TII, TRI, RBI))
3351+
return false;
33503352
}
33513353

33523354
// 4. Check the result. When primary bits == -1 use secondary, otherwise use
@@ -3376,10 +3378,10 @@ bool SPIRVInstructionSelector::selectFirstBitSet64(
33763378
AddOp = SPIRV::OpIAddV;
33773379
}
33783380

3379-
Register PrimaryReg;
3380-
Register SecondaryReg;
3381-
Register PrimaryShiftReg;
3382-
Register SecondaryShiftReg;
3381+
Register PrimaryReg = HighReg;
3382+
Register SecondaryReg = LowReg;
3383+
Register PrimaryShiftReg = Reg32;
3384+
Register SecondaryShiftReg = Reg0;
33833385

33843386
// By default the emitted opcodes check for the set bit from the MSB side.
33853387
// Setting SwapPrimarySide checks the set bit from the LSB side
@@ -3388,32 +3390,27 @@ bool SPIRVInstructionSelector::selectFirstBitSet64(
33883390
SecondaryReg = HighReg;
33893391
PrimaryShiftReg = Reg0;
33903392
SecondaryShiftReg = Reg32;
3391-
} else {
3392-
PrimaryReg = HighReg;
3393-
SecondaryReg = LowReg;
3394-
PrimaryShiftReg = Reg32;
3395-
SecondaryShiftReg = Reg0;
33963393
}
33973394

33983395
// Check if the primary bits are == -1
33993396
Register BReg = MRI->createVirtualRegister(GR.getRegClass(BoolType));
3400-
Result = Result && selectOpWithSrcs(BReg, BoolType, I,
3401-
{PrimaryReg, NegOneReg}, SPIRV::OpIEqual);
3397+
if (!selectOpWithSrcs(BReg, BoolType, I, {PrimaryReg, NegOneReg},
3398+
SPIRV::OpIEqual))
3399+
return false;
34023400

34033401
// Select secondary bits if true in BReg, otherwise primary bits
34043402
Register TmpReg = MRI->createVirtualRegister(GR.getRegClass(ResType));
3405-
Result =
3406-
Result && selectOpWithSrcs(TmpReg, ResType, I,
3407-
{BReg, SecondaryReg, PrimaryReg}, SelectOp);
3403+
if (!selectOpWithSrcs(TmpReg, ResType, I, {BReg, SecondaryReg, PrimaryReg},
3404+
SelectOp))
3405+
return false;
34083406

34093407
// 5. Add 32 when high bits are used, otherwise 0 for low bits
34103408
Register ValReg = MRI->createVirtualRegister(GR.getRegClass(ResType));
3411-
Result = Result && selectOpWithSrcs(
3412-
ValReg, ResType, I,
3413-
{BReg, SecondaryShiftReg, PrimaryShiftReg}, SelectOp);
3409+
if (!selectOpWithSrcs(ValReg, ResType, I,
3410+
{BReg, SecondaryShiftReg, PrimaryShiftReg}, SelectOp))
3411+
return false;
34143412

3415-
return Result &&
3416-
selectOpWithSrcs(ResVReg, ResType, I, {ValReg, TmpReg}, AddOp);
3413+
return selectOpWithSrcs(ResVReg, ResType, I, {ValReg, TmpReg}, AddOp);
34173414
}
34183415

34193416
bool SPIRVInstructionSelector::selectFirstBitHigh(Register ResVReg,

0 commit comments

Comments
 (0)