[PATCH] D102404: [InstCombine] Add instcombine fold for extractelement + splat for scalable vectors

Sander de Smalen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 1 07:41:11 PDT 2021


sdesmalen added inline comments.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4492
     // For fixed-length vector, fold into undef if index is out of bounds.
-    if (isa<FixedVectorType>(VecVTy) &&
-        IdxC->getValue().uge(cast<FixedVectorType>(VecVTy)->getNumElements()))
+    unsigned NumElts =
+        cast<VectorType>(VecVTy)->getElementCount().getKnownMinValue();
----------------
nit: MinNumElts


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4493
+    unsigned NumElts =
+        cast<VectorType>(VecVTy)->getElementCount().getKnownMinValue();
+    if (isa<FixedVectorType>(VecVTy) && IdxC->getValue().uge(NumElts))
----------------
This cast is redundant, because VecVTy is already a VectorType, see line 4475.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4499-4502
+    if (auto *SE = dyn_cast<ShuffleVectorInst>(Vec))
+      if (isSplatValue(SE) && IdxC->getValue().ult(NumElts))
+        if (auto *IE = dyn_cast<InsertElementInst>(SE->getOperand(0)))
+          return IE->getOperand(1);
----------------
Why not just rely on `llvm::getSplatValue` here?

  unsigned MinNumElts = VecVTy->getElementCount().getKnownMinValue();
  if (IdxC->getValue().ult(NumElts))
    if (auto *Splat = getSplatValue(Vec))
      return Splat;

  


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102404/new/

https://reviews.llvm.org/D102404



More information about the llvm-commits mailing list