* src/SDCCast.c (isLoopCountable): fixed bug #1478316
[fw/sdcc] / src / SDCCpeeph.c
index b227cf0a0a9cd5a52c6865dd66d06dfc6240cd2c..c38627dc2a7e76bfb81779ad823aead57d3c2198 100644 (file)
@@ -238,6 +238,10 @@ FBYNAME (labelIsReturnOnly)
   int len;
   char * retInst;
 
+  /* Don't optimize jumps in a jump table; a more generic test */
+  if (currPl->ic && currPl->ic->op == JUMPTABLE)
+    return FALSE;
+
   label = hTabItemWithKey (vars, 5);
   if (!label) return FALSE;
   len = strlen(label);
@@ -963,6 +967,39 @@ FBYNAME (operandsNotRelated)
 }
 
 
+/*-------------------------------------------------------------------*/
+/* operandsLiteral - returns true of the condition's operands are    */
+/* literals.                                                         */
+/*-------------------------------------------------------------------*/
+FBYNAME (operandsLiteral)
+{
+  set *operands;
+  const char *op;
+
+  operands = setFromConditionArgs (cmdLine, vars);
+
+  if (!operands)
+    {
+      fprintf (stderr,
+               "*** internal error: operandsLiteral peephole restriction"
+               " malformed: %s\n", cmdLine);
+      return FALSE;
+    }
+
+  for (op = setFirstItem (operands); op; op = setNextItem (operands))
+    {
+      if (!isdigit(*op))
+        {
+          deleteSet (&operands);
+          return FALSE;
+        }
+    }
+
+  deleteSet (&operands);
+  return TRUE;
+}
+
+
 /*-----------------------------------------------------------------*/
 /* callFuncByName - calls a function as defined in the table       */
 /*-----------------------------------------------------------------*/
@@ -1046,6 +1083,9 @@ callFuncByName (char *fname,
     {
       "operandsNotRelated", operandsNotRelated
     },
+    {
+      "operandsLiteral", operandsLiteral
+    },
     {
       "labelRefCountChange", labelRefCountChange
     }
@@ -2243,13 +2283,18 @@ initPeepHole ()
   char *s;
 
   /* read in the default rules */
-  readRules (port->peep.default_rules);
+  if (!options.nopeep)
+    {
+      readRules (port->peep.default_rules);
+    }
 
   /* if we have any additional file read it too */
   if (options.peep_file)
     {
       readRules (s = readFileIntoBuffer (options.peep_file));
       setToNull ((void *) &s);
+      /* override nopeep setting, default rules have not been read */
+      options.nopeep = 0;
     }