[llvm] VectorCombine: refactor foldShuffleToIdentity (NFC) (PR #92766)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Tue May 21 15:04:36 PDT 2024
================
@@ -1668,6 +1668,86 @@ bool VectorCombine::foldShuffleOfShuffles(Instruction &I) {
return true;
}
+using InstLane = std::pair<Value *, int>;
+
+static InstLane lookThroughShuffles(Value *V, int Lane) {
+ while (auto *SV = dyn_cast<ShuffleVectorInst>(V)) {
+ unsigned NumElts =
+ cast<FixedVectorType>(SV->getOperand(0)->getType())->getNumElements();
+ int M = SV->getMaskValue(Lane);
+ if (M < 0)
+ return {nullptr, PoisonMaskElem};
+ if (static_cast<unsigned>(M) < NumElts) {
+ V = SV->getOperand(0);
+ Lane = M;
+ } else {
+ V = SV->getOperand(1);
+ Lane = M - NumElts;
+ }
+ }
+ return InstLane{V, Lane};
+}
+
+static SmallVector<InstLane>
+generateInstLaneVectorFromOperand(ArrayRef<InstLane> Item, int Op) {
+ SmallVector<InstLane> NItem;
+ for (InstLane IL : Item) {
+ auto [V, Lane] = IL;
+ InstLane OpLane =
+ V ? lookThroughShuffles(cast<Instruction>(V)->getOperand(Op), Lane)
+ : InstLane{nullptr, PoisonMaskElem};
+ NItem.emplace_back(OpLane);
+ }
+ return NItem;
+}
+
+static Value *generateNewInstTree(ArrayRef<InstLane> Item, FixedVectorType *Ty,
+ const SmallPtrSet<Value *, 4> &IdentityLeafs,
+ const SmallPtrSet<Value *, 4> &SplatLeafs,
+ IRBuilder<> &Builder) {
+ auto [FrontV, FrontLane] = Item.front();
+
+ if (IdentityLeafs.contains(FrontV) &&
+ all_of(drop_begin(enumerate(Item)), [Item](const auto &E) {
+ Value *FrontV = Item.front().first;
----------------
davemgreen wrote:
What do you mean by 'destructed'? Is it not a pointer?
https://github.com/llvm/llvm-project/pull/92766
More information about the llvm-commits
mailing list