Disable folding in genCreateAddrMode under LB-specific circumstances.
authorPat Gavlin <pagavlin@microsoft.com>
Wed, 26 Jul 2017 22:54:16 +0000 (15:54 -0700)
committerPat Gavlin <pagavlin@microsoft.com>
Wed, 26 Jul 2017 22:54:16 +0000 (15:54 -0700)
If we are calling this function during emit with `fold = true`, then disable
folding iff the value to be used as the index is already in a register.
Not doing so can cause entire address modes to be folded away, which
leads to asserts and potential SBCG.

Fixes VSO 468730.

src/jit/codegencommon.cpp

index 1137207..5caf96f 100644 (file)
@@ -2385,6 +2385,16 @@ FOUND_AM:
 
         /* Special case: constant array index (that is range-checked) */
 
+#if defined(LEGACY_BACKEND)
+        // If we've already placed rv2 in a register, we were probably planning to use it in this addressing mode.
+        // Because the folding below may in fact result in no address mode (e.g. if we had "[mul * rv2 + cns]" that
+        // happens to fold to "[cns2]"), do not fold during code gen.
+        if (mode == -1 && rv2->InReg())
+        {
+            fold = false;
+        }
+#endif
+
         if (fold)
         {
             ssize_t    tmpMul;