[PATCH] D137537: [SLP] Extend reordering data of tree entry to support PHI nodes

Alexey Bataev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 7 06:26:35 PST 2022


ABataev added inline comments.


================
Comment at: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:289-304
 static Optional<unsigned> getInsertIndex(const Value *InsertInst,
                                          unsigned Offset = 0) {
   int Index = Offset;
   if (const auto *IE = dyn_cast<InsertElementInst>(InsertInst)) {
     if (const auto *CI = dyn_cast<ConstantInt>(IE->getOperand(2))) {
-      auto *VT = cast<FixedVectorType>(IE->getType());
-      if (CI->getValue().uge(VT->getNumElements()))
+      if (const auto *VT = dyn_cast<FixedVectorType>(IE->getType())) {
+        if (CI->getValue().uge(VT->getNumElements()))
----------------
Could precommit this change as a separate NFC change?


================
Comment at: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:292-302
   if (const auto *IE = dyn_cast<InsertElementInst>(InsertInst)) {
     if (const auto *CI = dyn_cast<ConstantInt>(IE->getOperand(2))) {
-      auto *VT = cast<FixedVectorType>(IE->getType());
-      if (CI->getValue().uge(VT->getNumElements()))
+      if (const auto *VT = dyn_cast<FixedVectorType>(IE->getType())) {
+        if (CI->getValue().uge(VT->getNumElements()))
+          return None;
+        Index *= VT->getNumElements();
+        Index += CI->getZExtValue();
----------------
Could you rework this to reduce structured complexity?


================
Comment at: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:301
+      } else
         return None;
     }
----------------
No need for `else` and `return ` substatement here.


================
Comment at: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3800-3801
 
+/// Check if two insertelement instructions are from the same buildvector.
+static bool areTwoInsertFromSameBuildVector(
+    InsertElementInst *VU, InsertElementInst *V,
----------------
Could precommit this change as a separate NFC change?


================
Comment at: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3910-3911
+    auto PHICompare = [](llvm::Value *V1, llvm::Value *V2) {
+      if (V1->user_empty() || V2->user_empty())
+        return false;
+      if (!V1->hasOneUse() || !V2->hasOneUse())
----------------
you can remove this check, since immediately after you check for exactly one use.


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

https://reviews.llvm.org/D137537



More information about the llvm-commits mailing list