[llvm] [VectorCombine] Combine scalar fneg with insert/extract to vector fneg when length is different (PR #115209)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 18 06:27:56 PST 2024
================
@@ -697,14 +696,33 @@ bool VectorCombine::foldInsExtFNeg(Instruction &I) {
TTI.getArithmeticInstrCost(Instruction::FNeg, VecTy, CostKind) +
TTI.getShuffleCost(TargetTransformInfo::SK_Select, VecTy, Mask, CostKind);
+ bool NeedLenChg = SrcVecTy->getNumElements() != NumElts;
+ // If the lengths of the two vectors are not equal,
+ // we need to add a length-change vector. Add this cost.
+ SmallVector<int> SrcMask;
+ if (NeedLenChg) {
+ SrcMask.assign(NumElts, PoisonMaskElem);
+ SrcMask[Index] = Index;
+ NewCost += TTI.getShuffleCost(TargetTransformInfo::SK_PermuteSingleSrc,
+ SrcVecTy, SrcMask, CostKind);
+ }
+
if (NewCost > OldCost)
return false;
- // insertelt DestVec, (fneg (extractelt SrcVec, Index)), Index -->
- // shuffle DestVec, (fneg SrcVec), Mask
+ Value *NewShuf;
+ // insertelt DestVec, (fneg (extractelt SrcVec, Index)), Index
Value *VecFNeg = Builder.CreateFNegFMF(SrcVec, FNeg);
- Value *Shuf = Builder.CreateShuffleVector(DestVec, VecFNeg, Mask);
- replaceValue(I, *Shuf);
+ if (NeedLenChg) {
+ // shuffle DestVec, (shuffle (fneg SrcVec), poison, SrcMask), Mask
+ Value *LenChgShuf = Builder.CreateShuffleVector(SrcVec, SrcMask);
----------------
ParkHanbum wrote:
I'm sorry for my mistake.. Can I send a PR again?
https://github.com/llvm/llvm-project/pull/115209
More information about the llvm-commits
mailing list