Skip to content

Commit

Permalink
[SLP]Fix getSpillCost functions.
Browse files Browse the repository at this point in the history
There are several issues in the current implementation. The instructions
are not properly ordered, if they are placed in different basic blocks,
need to reverse the order of blocks. Also, need to exclude
non-vectorizable nodes and check for CallBase, not CallInst, otherwise
invoke calls are not handled correctly.
  • Loading branch information
alexey-bataev committed May 26, 2023
1 parent 9b9e9ab commit 95b6311
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8094,6 +8094,8 @@ InstructionCost BoUpSLP::getSpillCost() const {
// are grouped together. Using dominance ensures a deterministic order.
SmallVector<Instruction *, 16> OrderedScalars;
for (const auto &TEPtr : VectorizableTree) {
if (TEPtr->State != TreeEntry::Vectorize)
continue;
Instruction *Inst = dyn_cast<Instruction>(TEPtr->Scalars[0]);
if (!Inst)
continue;
Expand All @@ -8107,7 +8109,7 @@ InstructionCost BoUpSLP::getSpillCost() const {
assert((NodeA == NodeB) == (NodeA->getDFSNumIn() == NodeB->getDFSNumIn()) &&
"Different nodes should have different DFS numbers");
if (NodeA != NodeB)
return NodeA->getDFSNumIn() < NodeB->getDFSNumIn();
return NodeA->getDFSNumIn() > NodeB->getDFSNumIn();
return B->comesBefore(A);
});

Expand Down Expand Up @@ -8166,7 +8168,7 @@ InstructionCost BoUpSLP::getSpillCost() const {
};

// Debug information does not impact spill cost.
if (isa<CallInst>(&*PrevInstIt) && !NoCallIntrinsic(&*PrevInstIt) &&
if (isa<CallBase>(&*PrevInstIt) && !NoCallIntrinsic(&*PrevInstIt) &&
&*PrevInstIt != PrevInst)
NumCalls++;

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/SLPVectorizer/AArch64/landing_pad.ll
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
; YAML-NEXT: Function: foo
; YAML-NEXT: Args:
; YAML-NEXT: - String: 'SLP vectorized with cost '
; YAML-NEXT: - Cost: '-3'
; YAML-NEXT: - Cost: '1'
; YAML-NEXT: - String: ' and with tree size '
; YAML-NEXT: - TreeSize: '9'

Expand Down

0 comments on commit 95b6311

Please sign in to comment.