[vm/compiler] Fix aliasing of typed data view indexed accesses

When calculating an alias for an indexed access to a typed data
view X[i], pick a more generic alias *[i] as it may potentially
alias another typed data indexed access.

TEST=lib/typed_data/typed_data_load2_test
(in vm-aot-optimization-level-linux-release-x64 configuration)

Fixes https://github.com/dart-lang/sdk/issues/55493

Change-Id: I44b494cd40d0c8b8f93fac92f042081b818cb1de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363401
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
diff --git a/runtime/vm/compiler/backend/redundancy_elimination.cc b/runtime/vm/compiler/backend/redundancy_elimination.cc
index c001277..851635c 100644
--- a/runtime/vm/compiler/backend/redundancy_elimination.cc
+++ b/runtime/vm/compiler/backend/redundancy_elimination.cc
@@ -325,17 +325,21 @@
   //    - for places that depend on an instance X.f, X.@offs, X[i], X[C]
   //      we drop X if X is not an allocation because in this case X does not
   //      possess an identity obtaining aliases *.f, *.@offs, *[i] and *[C]
-  //      respectively;
+  //      respectively; also drop instance of X[i] for typed data view
+  //      allocations as they may alias other indexed accesses.
   //    - for non-constant indexed places X[i] we drop information about the
   //      index obtaining alias X[*].
   //    - we drop information about representation, but keep element size
   //      if any.
   //
   Place ToAlias() const {
+    Definition* alias_instance = nullptr;
+    if (DependsOnInstance() && IsAllocation(instance()) &&
+        ((kind() != kIndexed) || !IsTypedDataViewAllocation(instance()))) {
+      alias_instance = instance();
+    }
     return Place(RepresentationBits::update(kNoRepresentation, flags_),
-                 (DependsOnInstance() && IsAllocation(instance())) ? instance()
-                                                                   : nullptr,
-                 (kind() == kIndexed) ? 0 : raw_selector_);
+                 alias_instance, (kind() == kIndexed) ? 0 : raw_selector_);
   }
 
   bool DependsOnInstance() const {
@@ -516,6 +520,17 @@
                                   defn->AsStaticCall()->IsRecognizedFactory()));
   }
 
+  static bool IsTypedDataViewAllocation(Definition* defn) {
+    if (defn != nullptr) {
+      if (auto* alloc = defn->AsAllocateObject()) {
+        auto const cid = alloc->cls().id();
+        return IsTypedDataViewClassId(cid) ||
+               IsUnmodifiableTypedDataViewClassId(cid);
+      }
+    }
+    return false;
+  }
+
  private:
   Place(uword flags, Definition* instance, intptr_t selector)
       : flags_(flags), instance_(instance), raw_selector_(selector), id_(0) {}