[llvm] [VectorCombine] Combine scalar fneg with insert/extract to vector fneg when length is different (PR #115209)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 06:59:29 PST 2024


================
@@ -665,9 +665,10 @@ bool VectorCombine::foldInsExtFNeg(Instruction &I) {
                        m_ExtractElt(m_Value(SrcVec), m_SpecificInt(Index))))))
     return false;
 
-  // TODO: We could handle this with a length-changing shuffle.
   auto *VecTy = cast<FixedVectorType>(I.getType());
-  if (SrcVec->getType() != VecTy)
+  auto *SrcVecTy = cast<FixedVectorType>(SrcVec->getType());
+  auto *ScalarTy = SrcVecTy->getScalarType();
+  if (ScalarTy != VecTy->getScalarType())
----------------
RKSimon wrote:

We can't guarantee that SrcVec is a FixedVectorType, you're probably safer doing this:
```cpp
auto *ScalarTy = VecTy->getScalarType();
auto *SrcVecTy = dyn_cast<FixedVectorType>(SrcVec->getType());
if (!SrcVecTy || ScalarTy != SrcVecTy->getScalarType())
```

https://github.com/llvm/llvm-project/pull/115209


More information about the llvm-commits mailing list