* device/lib/Makefile.in: remove abspath for PORTDIR, introduced in
[fw/sdcc] / src / SDCCloop.c
index 07d20ecae821e0470fc3c6e40044dc187f63fc3a..6400d1a4f411f7b92dae13451ab6cf31d93bb52a 100644 (file)
@@ -459,11 +459,13 @@ loopInvariants (region * theLoop, ebbIndex * ebbi)
                       elementsInSet (theLoop->exits));
 
       /* find out if we have a function call in this block */
-      for (ic = lBlock->sch, fCallsInBlock=0; ic; ic = ic->next) {
-        if (SKIP_IC(ic)) {
-          fCallsInBlock++;
+      for (ic = lBlock->sch, fCallsInBlock=0; ic; ic = ic->next)
+        {
+          if (SKIP_IC(ic))
+            {
+              fCallsInBlock++;
+            }
         }
-      }
 
       /* now we go thru the instructions of this block and */
       /* collect those instructions with invariant operands */
@@ -477,18 +479,27 @@ loopInvariants (region * theLoop, ebbIndex * ebbi)
              here and the definition, but I am too lazy to do that now */
 
           /* if there are function calls in this block */
-          if (fCallsInBlock) {
+          if (fCallsInBlock)
+            {
+              /* if this is a pointer get */
+              if (POINTER_GET(ic))
+                {
+                  continue;
+                }
 
-            /* if this is a pointer get */
-            if (POINTER_GET(ic)) {
-              continue;
-            }
+              /* if this is an assignment from a global */
+              if (ic->op=='=' && isOperandGlobal(IC_RIGHT(ic)))
+                {
+                  continue;
+                }
 
-            /* if this is an assignment from a global */
-            if (ic->op=='=' && isOperandGlobal(IC_RIGHT(ic))) {
-              continue;
+              /* Bug 1717943, 
+               * if this is an assignment to a global */
+              if (ic->op=='=' && isOperandGlobal(IC_RESULT(ic)))
+                {
+                  continue;
+                }
             }
-          }
 
           if (SKIP_IC (ic) || POINTER_SET (ic) || ic->op == IFX)
             continue;
@@ -518,18 +529,22 @@ loopInvariants (region * theLoop, ebbIndex * ebbi)
           if (ic->op == ADDRESS_OF &&
               IS_SYMOP (IC_LEFT (ic)) &&
               IS_AGGREGATE (operandType (IC_LEFT (ic))))
-            lin++;
-          else {
-            /* check if left operand is an invariant */
-            if ((lin = isOperandInvariant (IC_LEFT (ic), theLoop, lInvars)))
-              /* if this is a pointer get then make sure
-                 that the pointer set does not exist in
-                 any of the blocks */
-              if (POINTER_GET (ic) &&
-                  (applyToSet (theLoop->regBlocks,
-                               pointerAssigned, IC_LEFT (ic))))
-                lin = 0;
-          }
+            {
+              lin++;
+            }
+          else
+            {
+              /* check if left operand is an invariant */
+              if ((lin = isOperandInvariant (IC_LEFT (ic), theLoop, lInvars)) &&
+                /* if this is a pointer get then make sure
+                   that the pointer set does not exist in
+                   any of the blocks */
+                  POINTER_GET (ic) &&
+                  applyToSet (theLoop->regBlocks, pointerAssigned, IC_LEFT (ic)))
+                {
+                  lin = 0;
+                }
+            }
 
           /* do the same for right */
           rin = isOperandInvariant (IC_RIGHT (ic), theLoop, lInvars);