HLSL output: Fix nested dynamic indexing in an l-value

This fixes cases where a matrix is indexed and then the resulting
vector is indexed in the same expression inside an l-value.

BUG=angleproject:1672
TEST=angle_end2end_tests

Change-Id: Ia0593d75da67e0aa582003e1c381f2a1c89f948c
Reviewed-on: https://chromium-review.googlesource.com/427938
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/RemoveDynamicIndexing.cpp b/src/compiler/translator/RemoveDynamicIndexing.cpp
index b51ffa5..d439235 100644
--- a/src/compiler/translator/RemoveDynamicIndexing.cpp
+++ b/src/compiler/translator/RemoveDynamicIndexing.cpp
@@ -433,6 +433,18 @@
                     mRemoveIndexSideEffectsInSubtree = true;
                     return true;
                 }
+
+                TIntermBinary *leftBinary = node->getLeft()->getAsBinaryNode();
+                if (leftBinary != nullptr &&
+                    IntermNodePatternMatcher::IsDynamicIndexingOfVectorOrMatrix(leftBinary))
+                {
+                    // This is a case like:
+                    // mat2 m;
+                    // m[a][b]++;
+                    // Process the child node m[a] first.
+                    return true;
+                }
+
                 // TODO(oetuaho@nvidia.com): This is not optimal if the expression using the value
                 // only writes it and doesn't need the previous value. http://anglebug.com/1116