@@ -3191,16 +3191,13 @@ bool SPIRVInstructionSelector::selectFirstBitSet64Overflow(
3191
3191
// (ie i64x4 -> i64x2, i64x2)
3192
3192
MachineIRBuilder MIRBuilder (I);
3193
3193
SPIRVType *OpType = GR.getOrCreateSPIRVIntegerType (64 , MIRBuilder);
3194
- SPIRVType *LeftOpType;
3195
- SPIRVType *LeftResType;
3194
+ SPIRVType *LeftOpType = OpType ;
3195
+ SPIRVType *LeftResType = BaseType ;
3196
3196
if (LeftIsVector) {
3197
3197
LeftOpType =
3198
3198
GR.getOrCreateSPIRVVectorType (OpType, LeftComponentCount, MIRBuilder);
3199
3199
LeftResType =
3200
3200
GR.getOrCreateSPIRVVectorType (BaseType, LeftComponentCount, MIRBuilder);
3201
- } else {
3202
- LeftOpType = OpType;
3203
- LeftResType = BaseType;
3204
3201
}
3205
3202
3206
3203
SPIRVType *RightOpType =
@@ -3212,8 +3209,6 @@ bool SPIRVInstructionSelector::selectFirstBitSet64Overflow(
3212
3209
Register RightSideIn =
3213
3210
MRI->createVirtualRegister (GR.getRegClass (RightOpType));
3214
3211
3215
- bool Result;
3216
-
3217
3212
// Extract the left half from the SrcReg into LeftSideIn
3218
3213
// accounting for the special case when it only has one element
3219
3214
if (LeftIsVector) {
@@ -3225,14 +3220,16 @@ bool SPIRVInstructionSelector::selectFirstBitSet64Overflow(
3225
3220
// Per the spec, repeat the vector if only one vec is needed
3226
3221
.addUse (SrcReg);
3227
3222
3228
- for (unsigned J = 0 ; J < LeftComponentCount; J++) {
3223
+ for (unsigned J = 0 ; J < LeftComponentCount; J++)
3229
3224
MIB.addImm (J);
3230
- }
3231
3225
3232
- Result = MIB.constrainAllUses (TII, TRI, RBI);
3226
+ if (!MIB.constrainAllUses (TII, TRI, RBI))
3227
+ return false ;
3228
+
3233
3229
} 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 ;
3236
3233
}
3237
3234
3238
3235
// Extract the right half from the SrcReg into RightSideIn.
@@ -3246,28 +3243,28 @@ bool SPIRVInstructionSelector::selectFirstBitSet64Overflow(
3246
3243
// Per the spec, repeat the vector if only one vec is needed
3247
3244
.addUse (SrcReg);
3248
3245
3249
- for (unsigned J = LeftComponentCount; J < ComponentCount; J++) {
3246
+ for (unsigned J = LeftComponentCount; J < ComponentCount; J++)
3250
3247
MIB.addImm (J);
3251
- }
3252
3248
3253
- Result = Result && MIB.constrainAllUses (TII, TRI, RBI);
3249
+ if (!MIB.constrainAllUses (TII, TRI, RBI))
3250
+ return false ;
3254
3251
3255
3252
// Recursively call selectFirstBitSet64 on the 2 halves
3256
3253
Register LeftSideOut =
3257
3254
MRI->createVirtualRegister (GR.getRegClass (LeftResType));
3258
3255
Register RightSideOut =
3259
3256
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 ;
3266
3264
3267
3265
// Join the two resulting registers back into the return type
3268
3266
// (ie i32x2, i32x2 -> i32x4)
3269
- return Result &&
3270
- selectOpWithSrcs (ResVReg, ResType, I, {LeftSideOut, RightSideOut},
3267
+ return selectOpWithSrcs (ResVReg, ResType, I, {LeftSideOut, RightSideOut},
3271
3268
SPIRV::OpCompositeConstruct);
3272
3269
}
3273
3270
@@ -3297,13 +3294,15 @@ bool SPIRVInstructionSelector::selectFirstBitSet64(
3297
3294
GR.getOrCreateSPIRVVectorType (BaseType, 2 * ComponentCount, MIRBuilder);
3298
3295
Register BitcastReg =
3299
3296
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 ;
3302
3301
3303
3302
// 2. Find the first set bit from the primary side for all the pieces in #1
3304
3303
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 ;
3307
3306
3308
3307
// 3. Split result vector into high bits and low bits
3309
3308
Register HighReg = MRI->createVirtualRegister (GR.getRegClass (ResType));
@@ -3312,12 +3311,12 @@ bool SPIRVInstructionSelector::selectFirstBitSet64(
3312
3311
bool IsScalarRes = ResType->getOpcode () != SPIRV::OpTypeVector;
3313
3312
if (IsScalarRes) {
3314
3313
// 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 ;
3321
3320
} else {
3322
3321
// if vector do a shufflevector
3323
3322
auto MIB = BuildMI (*I.getParent (), I, I.getDebugLoc (),
@@ -3332,7 +3331,9 @@ bool SPIRVInstructionSelector::selectFirstBitSet64(
3332
3331
for (unsigned J = 0 ; J < ComponentCount * 2 ; J += 2 ) {
3333
3332
MIB.addImm (J);
3334
3333
}
3335
- Result = Result && MIB.constrainAllUses (TII, TRI, RBI);
3334
+
3335
+ if (!MIB.constrainAllUses (TII, TRI, RBI))
3336
+ return false ;
3336
3337
3337
3338
MIB = BuildMI (*I.getParent (), I, I.getDebugLoc (),
3338
3339
TII.get (SPIRV::OpVectorShuffle))
@@ -3346,7 +3347,8 @@ bool SPIRVInstructionSelector::selectFirstBitSet64(
3346
3347
for (unsigned J = 1 ; J < ComponentCount * 2 ; J += 2 ) {
3347
3348
MIB.addImm (J);
3348
3349
}
3349
- Result = Result && MIB.constrainAllUses (TII, TRI, RBI);
3350
+ if (!MIB.constrainAllUses (TII, TRI, RBI))
3351
+ return false ;
3350
3352
}
3351
3353
3352
3354
// 4. Check the result. When primary bits == -1 use secondary, otherwise use
@@ -3376,10 +3378,10 @@ bool SPIRVInstructionSelector::selectFirstBitSet64(
3376
3378
AddOp = SPIRV::OpIAddV;
3377
3379
}
3378
3380
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 ;
3383
3385
3384
3386
// By default the emitted opcodes check for the set bit from the MSB side.
3385
3387
// Setting SwapPrimarySide checks the set bit from the LSB side
@@ -3388,32 +3390,27 @@ bool SPIRVInstructionSelector::selectFirstBitSet64(
3388
3390
SecondaryReg = HighReg;
3389
3391
PrimaryShiftReg = Reg0;
3390
3392
SecondaryShiftReg = Reg32;
3391
- } else {
3392
- PrimaryReg = HighReg;
3393
- SecondaryReg = LowReg;
3394
- PrimaryShiftReg = Reg32;
3395
- SecondaryShiftReg = Reg0;
3396
3393
}
3397
3394
3398
3395
// Check if the primary bits are == -1
3399
3396
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 ;
3402
3400
3403
3401
// Select secondary bits if true in BReg, otherwise primary bits
3404
3402
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 ;
3408
3406
3409
3407
// 5. Add 32 when high bits are used, otherwise 0 for low bits
3410
3408
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 ;
3414
3412
3415
- return Result &&
3416
- selectOpWithSrcs (ResVReg, ResType, I, {ValReg, TmpReg}, AddOp);
3413
+ return selectOpWithSrcs (ResVReg, ResType, I, {ValReg, TmpReg}, AddOp);
3417
3414
}
3418
3415
3419
3416
bool SPIRVInstructionSelector::selectFirstBitHigh (Register ResVReg,
0 commit comments