Skip to content

Commit 2967815

Browse files
authored
[VPlan] Don't emit VPBlendRecipes with only one incoming value. NFC (#171804)
We can just directly use the incoming value. These single value blends would get optimized later on in simplifyBlends, but by doing it early it removes the notion of an "immediately normalized" blend, and simplifies an upcoming patch.
1 parent 693a987 commit 2967815

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,7 @@ class LLVM_ABI_FOR_TEST VPBlendRecipe : public VPSingleDefRecipe {
25172517
/// all other incoming values are merged into it.
25182518
VPBlendRecipe(PHINode *Phi, ArrayRef<VPValue *> Operands, DebugLoc DL)
25192519
: VPSingleDefRecipe(VPDef::VPBlendSC, Operands, Phi, DL) {
2520-
assert(Operands.size() > 0 && "Expected at least one operand!");
2520+
assert(Operands.size() >= 2 && "Expected at least two operands!");
25212521
}
25222522

25232523
VPBlendRecipe *clone() override {

llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,16 @@ void VPPredicator::convertPhisToBlends(VPBasicBlock *VPBB) {
240240
// be duplications since this is a simple recursive scan, but future
241241
// optimizations will clean it up.
242242

243+
if (all_equal(PhiR->incoming_values())) {
244+
PhiR->replaceAllUsesWith(PhiR->getIncomingValue(0));
245+
PhiR->eraseFromParent();
246+
continue;
247+
}
248+
243249
SmallVector<VPValue *, 2> OperandsWithMask;
244250
for (const auto &[InVPV, InVPBB] : PhiR->incoming_values_and_blocks()) {
245251
OperandsWithMask.push_back(InVPV);
246-
VPValue *EdgeMask = getEdgeMask(InVPBB, VPBB);
247-
if (!EdgeMask) {
248-
assert(all_equal(PhiR->incoming_values()) &&
249-
"Distinct incoming values with one having a full mask");
250-
break;
251-
}
252-
253-
OperandsWithMask.push_back(EdgeMask);
252+
OperandsWithMask.push_back(getEdgeMask(InVPBB, VPBB));
254253
}
255254
PHINode *IRPhi = cast_or_null<PHINode>(PhiR->getUnderlyingValue());
256255
auto *Blend =

llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ TEST_F(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
103103
auto *CanIV = new VPCanonicalIVPHIRecipe(Zero, {});
104104
VPInstruction *BranchOnCond =
105105
new VPInstruction(VPInstruction::BranchOnCond, {CanIV});
106-
auto *Blend = new VPBlendRecipe(Phi, {DefI}, {});
106+
auto *Blend = new VPBlendRecipe(Phi, {DefI, Plan.getTrue()}, {});
107107

108108
VPBasicBlock *VPBB1 = Plan.getEntry();
109109
VPBasicBlock *VPBB2 = Plan.createVPBasicBlock("");

0 commit comments

Comments
 (0)