[llvm] [SLP] no need to generate extract for in-tree uses for original scala… (PR #76077)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 26 09:22:52 PST 2023


================
@@ -11947,13 +11912,25 @@ Value *BoUpSLP::vectorizeTree(
       VectorToInsertElement.try_emplace(Vec, IE);
       return Vec;
     };
-    // If User == nullptr, the Scalar is used as extra arg. Generate
-    // ExtractElement instruction and update the record for this scalar in
-    // ExternallyUsedValues.
+    // If User == nullptr, the Scalar remains as scalar in vectorized
+    // instructions or is used as extra arg. Generate ExtractElement instruction
+    // and update the record for this scalar in ExternallyUsedValues.
     if (!User) {
-      assert(ExternallyUsedValues.count(Scalar) &&
-             "Scalar with nullptr as an external user must be registered in "
-             "ExternallyUsedValues map");
+      if (!ScalarsWithNullptrUser.insert(Scalar).second)
+        continue;
+      assert((ExternallyUsedValues.count(Scalar) ||
+              any_of(Scalar->users(),
+                     [this, Scalar](llvm::User *U) {
+                       TreeEntry *UseEntry = getTreeEntry(U);
+                       return UseEntry &&
----------------
alexey-bataev wrote:

```suggestion
                       return UseEntry && UseEntry->State != TreeEntry::Vectorize &&
```

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


More information about the llvm-commits mailing list