Skip to content

Commit 7896ee7

Browse files
authored
[ExpandVectorPredication] Change function returns from Value* to bool. NFC (llvm#157199)
None of the callers do anything with the pointer other than check for null or equality. We can use bool to accomplish the same thing.
1 parent 0335eba commit 7896ee7

File tree

1 file changed

+46
-55
lines changed

1 file changed

+46
-55
lines changed

llvm/lib/CodeGen/ExpandVectorPredication.cpp

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -150,44 +150,40 @@ struct CachingVPExpander {
150150
ElementCount ElemCount);
151151

152152
/// If needed, folds the EVL in the mask operand and discards the EVL
153-
/// parameter. Returns a pair of the value of the intrinsic after the change
154-
/// (if any) and whether the mask was actually folded.
155-
std::pair<Value *, bool> foldEVLIntoMask(VPIntrinsic &VPI);
153+
/// parameter. Returns true if the mask was actually folded.
154+
bool foldEVLIntoMask(VPIntrinsic &VPI);
156155

157156
/// "Remove" the %evl parameter of \p PI by setting it to the static vector
158157
/// length of the operation. Returns true if the %evl (if any) was effectively
159158
/// changed.
160159
bool discardEVLParameter(VPIntrinsic &PI);
161160

162161
/// Lower this VP binary operator to a unpredicated binary operator.
163-
Value *expandPredicationInBinaryOperator(IRBuilder<> &Builder,
164-
VPIntrinsic &PI);
162+
bool expandPredicationInBinaryOperator(IRBuilder<> &Builder, VPIntrinsic &PI);
165163

166164
/// Lower this VP int call to a unpredicated int call.
167-
Value *expandPredicationToIntCall(IRBuilder<> &Builder, VPIntrinsic &PI);
165+
bool expandPredicationToIntCall(IRBuilder<> &Builder, VPIntrinsic &PI);
168166

169167
/// Lower this VP fp call to a unpredicated fp call.
170-
Value *expandPredicationToFPCall(IRBuilder<> &Builder, VPIntrinsic &PI,
171-
unsigned UnpredicatedIntrinsicID);
168+
bool expandPredicationToFPCall(IRBuilder<> &Builder, VPIntrinsic &PI,
169+
unsigned UnpredicatedIntrinsicID);
172170

173171
/// Lower this VP reduction to a call to an unpredicated reduction intrinsic.
174-
Value *expandPredicationInReduction(IRBuilder<> &Builder,
175-
VPReductionIntrinsic &PI);
172+
bool expandPredicationInReduction(IRBuilder<> &Builder,
173+
VPReductionIntrinsic &PI);
176174

177175
/// Lower this VP cast operation to a non-VP intrinsic.
178-
Value *expandPredicationToCastIntrinsic(IRBuilder<> &Builder,
179-
VPIntrinsic &VPI);
176+
bool expandPredicationToCastIntrinsic(IRBuilder<> &Builder, VPIntrinsic &VPI);
180177

181178
/// Lower this VP memory operation to a non-VP intrinsic.
182-
Value *expandPredicationInMemoryIntrinsic(IRBuilder<> &Builder,
183-
VPIntrinsic &VPI);
179+
bool expandPredicationInMemoryIntrinsic(IRBuilder<> &Builder,
180+
VPIntrinsic &VPI);
184181

185182
/// Lower this VP comparison to a call to an unpredicated comparison.
186-
Value *expandPredicationInComparison(IRBuilder<> &Builder,
187-
VPCmpIntrinsic &PI);
183+
bool expandPredicationInComparison(IRBuilder<> &Builder, VPCmpIntrinsic &PI);
188184

189185
/// Query TTI and expand the vector predication in \p P accordingly.
190-
Value *expandPredication(VPIntrinsic &PI);
186+
bool expandPredication(VPIntrinsic &PI);
191187

192188
/// Determine how and whether the VPIntrinsic \p VPI shall be expanded. This
193189
/// overrides TTI with the cl::opts listed at the top of this file.
@@ -227,9 +223,8 @@ Value *CachingVPExpander::convertEVLToMask(IRBuilder<> &Builder,
227223
return Builder.CreateICmp(CmpInst::ICMP_ULT, IdxVec, VLSplat);
228224
}
229225

230-
Value *
231-
CachingVPExpander::expandPredicationInBinaryOperator(IRBuilder<> &Builder,
232-
VPIntrinsic &VPI) {
226+
bool CachingVPExpander::expandPredicationInBinaryOperator(IRBuilder<> &Builder,
227+
VPIntrinsic &VPI) {
233228
assert((maySpeculateLanes(VPI) || VPI.canIgnoreVectorLengthParam()) &&
234229
"Implicitly dropping %evl in non-speculatable operator!");
235230

@@ -261,25 +256,25 @@ CachingVPExpander::expandPredicationInBinaryOperator(IRBuilder<> &Builder,
261256
Value *NewBinOp = Builder.CreateBinOp(OC, Op0, Op1, VPI.getName());
262257

263258
replaceOperation(*NewBinOp, VPI);
264-
return NewBinOp;
259+
return true;
265260
}
266261

267-
Value *CachingVPExpander::expandPredicationToIntCall(IRBuilder<> &Builder,
268-
VPIntrinsic &VPI) {
262+
bool CachingVPExpander::expandPredicationToIntCall(IRBuilder<> &Builder,
263+
VPIntrinsic &VPI) {
269264
std::optional<unsigned> FID = VPI.getFunctionalIntrinsicID();
270265
if (!FID)
271-
return nullptr;
266+
return false;
272267
SmallVector<Value *, 2> Argument;
273268
for (unsigned i = 0; i < VPI.getNumOperands() - 3; i++) {
274269
Argument.push_back(VPI.getOperand(i));
275270
}
276271
Value *NewOp = Builder.CreateIntrinsic(FID.value(), {VPI.getType()}, Argument,
277272
/*FMFSource=*/nullptr, VPI.getName());
278273
replaceOperation(*NewOp, VPI);
279-
return NewOp;
274+
return true;
280275
}
281276

282-
Value *CachingVPExpander::expandPredicationToFPCall(
277+
bool CachingVPExpander::expandPredicationToFPCall(
283278
IRBuilder<> &Builder, VPIntrinsic &VPI, unsigned UnpredicatedIntrinsicID) {
284279
assert((maySpeculateLanes(VPI) || VPI.canIgnoreVectorLengthParam()) &&
285280
"Implicitly dropping %evl in non-speculatable operator!");
@@ -297,7 +292,7 @@ Value *CachingVPExpander::expandPredicationToFPCall(
297292
UnpredicatedIntrinsicID, {VPI.getType()}, Argument,
298293
/*FMFSource=*/nullptr, VPI.getName());
299294
replaceOperation(*NewOp, VPI);
300-
return NewOp;
295+
return true;
301296
}
302297
case Intrinsic::fma:
303298
case Intrinsic::fmuladd:
@@ -315,11 +310,11 @@ Value *CachingVPExpander::expandPredicationToFPCall(
315310
else
316311
NewOp = Builder.CreateCall(Fn, {Op0, Op1, Op2}, VPI.getName());
317312
replaceOperation(*NewOp, VPI);
318-
return NewOp;
313+
return true;
319314
}
320315
}
321316

322-
return nullptr;
317+
return false;
323318
}
324319

325320
static Value *getNeutralReductionElement(const VPReductionIntrinsic &VPI,
@@ -331,9 +326,8 @@ static Value *getNeutralReductionElement(const VPReductionIntrinsic &VPI,
331326
return getReductionIdentity(RdxID, EltTy, FMF);
332327
}
333328

334-
Value *
335-
CachingVPExpander::expandPredicationInReduction(IRBuilder<> &Builder,
336-
VPReductionIntrinsic &VPI) {
329+
bool CachingVPExpander::expandPredicationInReduction(
330+
IRBuilder<> &Builder, VPReductionIntrinsic &VPI) {
337331
assert((maySpeculateLanes(VPI) || VPI.canIgnoreVectorLengthParam()) &&
338332
"Implicitly dropping %evl in non-speculatable operator!");
339333

@@ -391,11 +385,11 @@ CachingVPExpander::expandPredicationInReduction(IRBuilder<> &Builder,
391385
}
392386

393387
replaceOperation(*Reduction, VPI);
394-
return Reduction;
388+
return true;
395389
}
396390

397-
Value *CachingVPExpander::expandPredicationToCastIntrinsic(IRBuilder<> &Builder,
398-
VPIntrinsic &VPI) {
391+
bool CachingVPExpander::expandPredicationToCastIntrinsic(IRBuilder<> &Builder,
392+
VPIntrinsic &VPI) {
399393
Intrinsic::ID VPID = VPI.getIntrinsicID();
400394
unsigned CastOpcode = VPIntrinsic::getFunctionalOpcodeForVP(VPID).value();
401395
assert(Instruction::isCast(CastOpcode));
@@ -404,12 +398,11 @@ Value *CachingVPExpander::expandPredicationToCastIntrinsic(IRBuilder<> &Builder,
404398
VPI.getType(), VPI.getName());
405399

406400
replaceOperation(*CastOp, VPI);
407-
return CastOp;
401+
return true;
408402
}
409403

410-
Value *
411-
CachingVPExpander::expandPredicationInMemoryIntrinsic(IRBuilder<> &Builder,
412-
VPIntrinsic &VPI) {
404+
bool CachingVPExpander::expandPredicationInMemoryIntrinsic(IRBuilder<> &Builder,
405+
VPIntrinsic &VPI) {
413406
assert(VPI.canIgnoreVectorLengthParam());
414407

415408
const auto &DL = VPI.getDataLayout();
@@ -469,11 +462,11 @@ CachingVPExpander::expandPredicationInMemoryIntrinsic(IRBuilder<> &Builder,
469462

470463
assert(NewMemoryInst);
471464
replaceOperation(*NewMemoryInst, VPI);
472-
return NewMemoryInst;
465+
return true;
473466
}
474467

475-
Value *CachingVPExpander::expandPredicationInComparison(IRBuilder<> &Builder,
476-
VPCmpIntrinsic &VPI) {
468+
bool CachingVPExpander::expandPredicationInComparison(IRBuilder<> &Builder,
469+
VPCmpIntrinsic &VPI) {
477470
assert((maySpeculateLanes(VPI) || VPI.canIgnoreVectorLengthParam()) &&
478471
"Implicitly dropping %evl in non-speculatable operator!");
479472

@@ -487,7 +480,7 @@ Value *CachingVPExpander::expandPredicationInComparison(IRBuilder<> &Builder,
487480
auto *NewCmp = Builder.CreateCmp(Pred, Op0, Op1);
488481

489482
replaceOperation(*NewCmp, VPI);
490-
return NewCmp;
483+
return true;
491484
}
492485

493486
bool CachingVPExpander::discardEVLParameter(VPIntrinsic &VPI) {
@@ -516,14 +509,14 @@ bool CachingVPExpander::discardEVLParameter(VPIntrinsic &VPI) {
516509
return true;
517510
}
518511

519-
std::pair<Value *, bool> CachingVPExpander::foldEVLIntoMask(VPIntrinsic &VPI) {
512+
bool CachingVPExpander::foldEVLIntoMask(VPIntrinsic &VPI) {
520513
LLVM_DEBUG(dbgs() << "Folding vlen for " << VPI << '\n');
521514

522515
IRBuilder<> Builder(&VPI);
523516

524517
// Ineffective %evl parameter and so nothing to do here.
525518
if (VPI.canIgnoreVectorLengthParam())
526-
return {&VPI, false};
519+
return false;
527520

528521
// Only VP intrinsics can have an %evl parameter.
529522
Value *OldMaskParam = VPI.getMaskParam();
@@ -555,10 +548,10 @@ std::pair<Value *, bool> CachingVPExpander::foldEVLIntoMask(VPIntrinsic &VPI) {
555548
"transformation did not render the evl param ineffective!");
556549

557550
// Reassess the modified instruction.
558-
return {&VPI, true};
551+
return true;
559552
}
560553

561-
Value *CachingVPExpander::expandPredication(VPIntrinsic &VPI) {
554+
bool CachingVPExpander::expandPredication(VPIntrinsic &VPI) {
562555
LLVM_DEBUG(dbgs() << "Lowering to unpredicated op: " << VPI << '\n');
563556

564557
IRBuilder<> Builder(&VPI);
@@ -575,9 +568,8 @@ Value *CachingVPExpander::expandPredication(VPIntrinsic &VPI) {
575568
if (auto *VPCmp = dyn_cast<VPCmpIntrinsic>(&VPI))
576569
return expandPredicationInComparison(Builder, *VPCmp);
577570

578-
if (VPCastIntrinsic::isVPCast(VPI.getIntrinsicID())) {
571+
if (VPCastIntrinsic::isVPCast(VPI.getIntrinsicID()))
579572
return expandPredicationToCastIntrinsic(Builder, VPI);
580-
}
581573

582574
switch (VPI.getIntrinsicID()) {
583575
default:
@@ -622,10 +614,10 @@ Value *CachingVPExpander::expandPredication(VPIntrinsic &VPI) {
622614
}
623615

624616
if (auto CID = VPI.getConstrainedIntrinsicID())
625-
if (Value *Call = expandPredicationToFPCall(Builder, VPI, *CID))
626-
return Call;
617+
if (expandPredicationToFPCall(Builder, VPI, *CID))
618+
return true;
627619

628-
return &VPI;
620+
return false;
629621
}
630622

631623
//// } CachingVPExpander
@@ -682,8 +674,7 @@ CachingVPExpander::expandVectorPredication(VPIntrinsic &VPI) {
682674
Changed = VPExpansionDetails::IntrinsicUpdated;
683675
break;
684676
case VPLegalization::Convert:
685-
if (auto [NewVPI, Folded] = foldEVLIntoMask(VPI); Folded) {
686-
(void)NewVPI;
677+
if (foldEVLIntoMask(VPI)) {
687678
Changed = VPExpansionDetails::IntrinsicUpdated;
688679
++NumFoldedVL;
689680
}
@@ -697,7 +688,7 @@ CachingVPExpander::expandVectorPredication(VPIntrinsic &VPI) {
697688
case VPLegalization::Discard:
698689
llvm_unreachable("Invalid strategy for operators.");
699690
case VPLegalization::Convert:
700-
if (Value *V = expandPredication(VPI); V != &VPI) {
691+
if (expandPredication(VPI)) {
701692
++NumLoweredVPOps;
702693
Changed = VPExpansionDetails::IntrinsicReplaced;
703694
}

0 commit comments

Comments
 (0)