Skip to content

Commit 44a0799

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-compute-iv-end-values
2 parents 18b8e8c + 734a204 commit 44a0799

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8354,11 +8354,12 @@ createWidenInductionRecipes(PHINode *Phi, Instruction *PhiOrTrunc,
83548354
vputils::getOrCreateVPValueForSCEVExpr(Plan, IndDesc.getStep(), SE);
83558355
if (auto *TruncI = dyn_cast<TruncInst>(PhiOrTrunc)) {
83568356
return new VPWidenIntOrFpInductionRecipe(Phi, Start, Step, &Plan.getVF(),
8357-
IndDesc, TruncI);
8357+
IndDesc, TruncI,
8358+
TruncI->getDebugLoc());
83588359
}
83598360
assert(isa<PHINode>(PhiOrTrunc) && "must be a phi node here");
83608361
return new VPWidenIntOrFpInductionRecipe(Phi, Start, Step, &Plan.getVF(),
8361-
IndDesc);
8362+
IndDesc, Phi->getDebugLoc());
83628363
}
83638364

83648365
VPHeaderPHIRecipe *VPRecipeBuilder::tryToOptimizeInductionPHI(

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,17 +2108,18 @@ class VPWidenIntOrFpInductionRecipe : public VPHeaderPHIRecipe {
21082108

21092109
public:
21102110
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step,
2111-
VPValue *VF, const InductionDescriptor &IndDesc)
2112-
: VPHeaderPHIRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start), IV(IV),
2113-
Trunc(nullptr), IndDesc(IndDesc) {
2111+
VPValue *VF, const InductionDescriptor &IndDesc,
2112+
DebugLoc DL)
2113+
: VPHeaderPHIRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start, DL),
2114+
IV(IV), Trunc(nullptr), IndDesc(IndDesc) {
21142115
addOperand(Step);
21152116
addOperand(VF);
21162117
}
21172118

21182119
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step,
21192120
VPValue *VF, const InductionDescriptor &IndDesc,
2120-
TruncInst *Trunc)
2121-
: VPHeaderPHIRecipe(VPDef::VPWidenIntOrFpInductionSC, Trunc, Start),
2121+
TruncInst *Trunc, DebugLoc DL)
2122+
: VPHeaderPHIRecipe(VPDef::VPWidenIntOrFpInductionSC, Trunc, Start, DL),
21222123
IV(IV), Trunc(Trunc), IndDesc(IndDesc) {
21232124
addOperand(Step);
21242125
addOperand(VF);
@@ -2127,8 +2128,9 @@ class VPWidenIntOrFpInductionRecipe : public VPHeaderPHIRecipe {
21272128
~VPWidenIntOrFpInductionRecipe() override = default;
21282129

21292130
VPWidenIntOrFpInductionRecipe *clone() override {
2130-
return new VPWidenIntOrFpInductionRecipe(
2131-
IV, getStartValue(), getStepValue(), getVFValue(), IndDesc, Trunc);
2131+
return new VPWidenIntOrFpInductionRecipe(IV, getStartValue(),
2132+
getStepValue(), getVFValue(),
2133+
IndDesc, Trunc, getDebugLoc());
21322134
}
21332135

21342136
VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,14 +1733,14 @@ void VPWidenIntOrFpInductionRecipe::execute(VPTransformState &State) {
17331733
// factor. The last of those goes into the PHI.
17341734
PHINode *VecInd = PHINode::Create(SteppedStart->getType(), 2, "vec.ind");
17351735
VecInd->insertBefore(State.CFG.PrevBB->getFirstInsertionPt());
1736-
VecInd->setDebugLoc(EntryVal->getDebugLoc());
1736+
VecInd->setDebugLoc(getDebugLoc());
17371737
State.set(this, VecInd);
17381738

17391739
Instruction *LastInduction = cast<Instruction>(
17401740
Builder.CreateBinOp(AddOp, VecInd, SplatVF, "vec.ind.next"));
17411741
if (isa<TruncInst>(EntryVal))
17421742
State.addMetadata(LastInduction, EntryVal);
1743-
LastInduction->setDebugLoc(EntryVal->getDebugLoc());
1743+
LastInduction->setDebugLoc(getDebugLoc());
17441744

17451745
VecInd->addIncoming(SteppedStart, VectorPH);
17461746
// Add induction update using an incorrect block temporarily. The phi node

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ void VPlanTransforms::VPInstructionsToVPRecipes(
6161
VPValue *Start = Plan->getOrAddLiveIn(II->getStartValue());
6262
VPValue *Step =
6363
vputils::getOrCreateVPValueForSCEVExpr(*Plan, II->getStep(), SE);
64-
NewRecipe = new VPWidenIntOrFpInductionRecipe(Phi, Start, Step,
65-
&Plan->getVF(), *II);
64+
NewRecipe = new VPWidenIntOrFpInductionRecipe(
65+
Phi, Start, Step, &Plan->getVF(), *II, Ingredient.getDebugLoc());
6666
} else {
6767
assert(isa<VPInstruction>(&Ingredient) &&
6868
"only VPInstructions expected here");

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,11 +1628,16 @@ bool VectorCombine::foldPermuteOfBinops(Instruction &I) {
16281628
}
16291629

16301630
/// Try to convert "shuffle (binop), (binop)" into "binop (shuffle), (shuffle)".
1631+
/// TODO: Handle "shuffle (cmp), (cmp)" into "cmp (shuffle), (shuffle)".
16311632
bool VectorCombine::foldShuffleOfBinops(Instruction &I) {
1632-
BinaryOperator *B0, *B1;
16331633
ArrayRef<int> OldMask;
1634-
if (!match(&I, m_Shuffle(m_OneUse(m_BinOp(B0)), m_OneUse(m_BinOp(B1)),
1635-
m_Mask(OldMask))))
1634+
Instruction *LHS, *RHS;
1635+
if (!match(&I, m_Shuffle(m_OneUse(m_Instruction(LHS)),
1636+
m_OneUse(m_Instruction(RHS)), m_Mask(OldMask))))
1637+
return false;
1638+
1639+
BinaryOperator *B0, *B1;
1640+
if (!match(LHS, m_BinOp(B0)) || !match(RHS, m_BinOp(B1)))
16361641
return false;
16371642

16381643
// Don't introduce poison into div/rem.
@@ -1645,15 +1650,15 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {
16451650
return false;
16461651

16471652
auto *ShuffleDstTy = dyn_cast<FixedVectorType>(I.getType());
1648-
auto *BinOpTy = dyn_cast<FixedVectorType>(B0->getType());
1653+
auto *BinOpTy = dyn_cast<FixedVectorType>(LHS->getType());
16491654
if (!ShuffleDstTy || !BinOpTy)
16501655
return false;
16511656

16521657
unsigned NumSrcElts = BinOpTy->getNumElements();
16531658

16541659
// If we have something like "add X, Y" and "add Z, X", swap ops to match.
1655-
Value *X = B0->getOperand(0), *Y = B0->getOperand(1);
1656-
Value *Z = B1->getOperand(0), *W = B1->getOperand(1);
1660+
Value *X = LHS->getOperand(0), *Y = LHS->getOperand(1);
1661+
Value *Z = RHS->getOperand(0), *W = RHS->getOperand(1);
16571662
if (BinaryOperator::isCommutative(Opcode) && X != Z && Y != W &&
16581663
(X == W || Y == Z))
16591664
std::swap(X, Y);
@@ -1681,10 +1686,10 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {
16811686

16821687
// Try to replace a binop with a shuffle if the shuffle is not costly.
16831688
InstructionCost OldCost =
1684-
TTI.getArithmeticInstrCost(B0->getOpcode(), BinOpTy, CostKind) +
1685-
TTI.getArithmeticInstrCost(B1->getOpcode(), BinOpTy, CostKind) +
1689+
TTI.getInstructionCost(LHS, CostKind) +
1690+
TTI.getInstructionCost(RHS, CostKind) +
16861691
TTI.getShuffleCost(TargetTransformInfo::SK_PermuteTwoSrc, BinOpTy,
1687-
OldMask, CostKind, 0, nullptr, {B0, B1}, &I);
1692+
OldMask, CostKind, 0, nullptr, {LHS, RHS}, &I);
16881693

16891694
InstructionCost NewCost =
16901695
TTI.getShuffleCost(SK0, BinOpTy, NewMask0, CostKind, 0, nullptr, {X, Z}) +
@@ -1703,8 +1708,8 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {
17031708

17041709
// Intersect flags from the old binops.
17051710
if (auto *NewInst = dyn_cast<Instruction>(NewBO)) {
1706-
NewInst->copyIRFlags(B0);
1707-
NewInst->andIRFlags(B1);
1711+
NewInst->copyIRFlags(LHS);
1712+
NewInst->andIRFlags(RHS);
17081713
}
17091714

17101715
Worklist.pushValue(Shuf0);

0 commit comments

Comments
 (0)