Operand comparisons were unnecessarily failing in the pCode peep hole optimizer.
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 19 Jun 2002 14:26:10 +0000 (14:26 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 19 Jun 2002 14:26:10 +0000 (14:26 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2025 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/pic/genarith.c
src/pic/pcode.c
src/pic/pcodepeep.c
src/pic/peeph.def

index fb6b94980374aaadcc76acd1d4c10498933a2299..d6e5d7968b29617e066bb14461c9799ea969c073 100644 (file)
@@ -961,7 +961,9 @@ void genPlus (iCode *ic)
        else {
          PIC_OPCODE poc = POC_ADDFW;
 
-         if ((AOP_TYPE(IC_LEFT(ic)) == AOP_PCODE) && AOP(IC_LEFT(ic))->aopu.pcop->type == PO_LITERAL)
+         if ((AOP_TYPE(IC_LEFT(ic)) == AOP_PCODE) && (
+             (AOP(IC_LEFT(ic))->aopu.pcop->type == PO_LITERAL) || 
+             (AOP(IC_LEFT(ic))->aopu.pcop->type == PO_IMMEDIATE)))
            poc = POC_ADDLW;
          emitpcode(poc, popGet(AOP(IC_LEFT(ic)),0));
          if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
index bb3ac5ac077085779b6be6b07e2e4dadcef06423..dce141969717b17f71135c06e06505a114a44b91 100644 (file)
@@ -112,7 +112,7 @@ static void pCodePrintLabel(FILE *of, pCode *pc);
 static void pCodePrintFunction(FILE *of, pCode *pc);
 static void pCodeOpPrint(FILE *of, pCodeOp *pcop);
 static char *get_op_from_instruction( pCodeInstruction *pcc);
-char *get_op( pCodeOp *pcop);
+char *get_op( pCodeOp *pcop,char *buff,int buf_size);
 int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd);
 int pCodePeepMatchRule(pCode *pc);
 void pBlockStats(FILE *of, pBlock *pb);
@@ -1161,6 +1161,7 @@ void SAFE_snprintf(char **str, size_t *size, const  char  *format, ...)
   len = strlen(*str);
   if(len > *size) {
     fprintf(stderr,"WARNING, it looks like %s has overflowed\n",__FUNCTION__);
+    fprintf(stderr,"len = %d is > str size %d\n",len,*size);
   }
 
   *str += len;
@@ -1189,6 +1190,7 @@ void SAFE_snprintf(char **str, size_t *size, const  char  *format, ...)
   len = strlen(buffer);
   if(len > *size) {
     fprintf(stderr,"WARNING, it looks like %s has overflowed\n",__FUNCTION__);
+    fprintf(stderr,"len = %d is > str size %d\n",len,*size);
   }
 
   strcpy(*str, buffer);
@@ -2364,13 +2366,17 @@ void pBlockRegs(FILE *of, pBlock *pb)
 
 /*-----------------------------------------------------------------*/
 /*-----------------------------------------------------------------*/
-char *get_op(pCodeOp *pcop)
+char *get_op(pCodeOp *pcop,char *buffer, int size)
 {
   regs *r;
-  static char buffer[50];
+  static char b[50];
   char *s;
-  int size;
+  //  int size;
 
+  if(!buffer) {
+    buffer = b;
+    size = sizeof(b);
+  } 
 
   if(pcop) {
     switch(pcop->type) {
@@ -2390,7 +2396,7 @@ char *get_op(pCodeOp *pcop)
       //      return PCOR(pcc->pcop)->r)->name;
     case PO_IMMEDIATE:
       s = buffer;
-      size = sizeof(buffer);
+      //size = sizeof(buffer);
       //fprintf(stderr,"PO_IMMEDIATE name = %s  offset = %d\n",pcc->pcop->name,PCOI(pcc->pcop)->offset);
       if(PCOI(pcop)->_const) {
 
@@ -2415,7 +2421,7 @@ char *get_op(pCodeOp *pcop)
 
     case PO_DIR:
       s = buffer;
-      size = sizeof(buffer);
+      //size = sizeof(buffer);
       if( PCOR(pcop)->instance) {
        SAFE_snprintf(&s,&size,"(%s + %d)",
                      pcop->name,
@@ -2442,7 +2448,7 @@ static char *get_op_from_instruction( pCodeInstruction *pcc)
 {
 
   if(pcc )
-    return get_op(pcc->pcop);
+    return get_op(pcc->pcop,NULL,0);
   
   return ("ERROR Null: "__FUNCTION__);
 
index 9083d1b932493c7fe39741f563cbcf20bf5a1210..2ba9fd1f56f3054931a4f42b1703673cb3ba30eb 100644 (file)
@@ -44,7 +44,7 @@ int getpCode(char *mnem,int dest);
 int getpCodePeepCommand(char *cmd);
 void pBlockMergeLabels(pBlock *pb);
 char *pCode2str(char *str, int size, pCode *pc);
-char *get_op( pCodeOp *pcop);
+char *get_op( pCodeOp *pcop,char *buf,int buf_size);
 
 extern pCodeInstruction *pic14Mnemonics[];
 
@@ -1366,6 +1366,8 @@ int pCodeSearchCondition(pCode *pc, unsigned int cond)
       return 0;
 
     if(pc->type == PC_OPCODE) {
+      //fprintf(stderr," checking conditions of: ");
+      //pc->print(stderr,pc);
       if(PCI(pc)->inCond & cond)
        return 1;
       if(PCI(pc)->outCond & cond)
@@ -1385,24 +1387,29 @@ int pCodeSearchCondition(pCode *pc, unsigned int cond)
  *-----------------------------------------------------------------*/
 int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd)
 {
+  char b[50], *n2;
 
   if(!pcops || !pcopd)
     return 0;
-  /*
+/*
   fprintf(stderr," Comparing operands %s",
-         get_op( pcops));
+         get_op( pcops,NULL,0));
 
   fprintf(stderr," to %s\n",
-         get_op( pcopd));
-  */
+         get_op( pcopd,NULL,0));
+*/
 
   if(pcops->type != pcopd->type) {
     //fprintf(stderr,"  - fail - diff types\n");
     return 0;  // different types
   }
 
-  if(!pcops->name ||  !pcopd->name || strcmp(pcops->name,pcopd->name)) {
-    //fprintf(stderr,"  - fail - diff names\n");
+  b[0]=0;
+  get_op(pcops,b,sizeof(b));
+  n2 = get_op(pcopd,NULL,0);
+
+  if( !n2 || strcmp(b,n2)) {
+    //fprintf(stderr,"  - fail - diff names: %s, len=%d,  %s, len=%d\n",b,strlen(b), n2, strlen(n2) );
     return 0;  // different names
   }
 
@@ -1417,7 +1424,7 @@ int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd)
     break;
   }
 
-  //fprintf(stderr,"  - pass\n");
+  //  fprintf(stderr,"  - pass\n");
 
   return 1;
 }
@@ -1915,8 +1922,10 @@ int pCodePeepMatchRule(pCode *pc)
       pct = pct->next;
       //debug:
       //DFPRINTF((stderr,"    matched\n"));
+
       if(!pcin && pct) {
        DFPRINTF((stderr," partial match... no more code\n"));
+       fprintf(stderr," partial match... no more code\n");
        matched = 0; 
       }
       if(!pct) {
@@ -1926,6 +1935,9 @@ int pCodePeepMatchRule(pCode *pc)
 
     if(matched) {
 
+      //pCode *pcr = peepBlock->replace.pb->pcHead;
+      //if(pcr) pcr->print(stderr,pcr);
+      
       /* So far we matched the rule up to the point of the conditions .
        * In other words, all of the opcodes match. Now we need to see
        * if the post conditions are satisfied.
@@ -1938,6 +1950,8 @@ int pCodePeepMatchRule(pCode *pc)
       if (pcin && peepBlock->postFalseCond && 
          (pCodeSearchCondition(pcin,peepBlock->postFalseCond) > 0) )
        matched = 0;
+
+      if(!matched) fprintf(stderr,"failed on conditions\n");
     }
 
     if(matched) {
@@ -1967,7 +1981,7 @@ int pCodePeepMatchRule(pCode *pc)
        pcin->prev = pc->prev;
 
 
-#if 0
+      //#if 0
       {
        /*     DEBUG    */
        /* Converted the deleted pCodes into comments */
@@ -1999,7 +2013,7 @@ int pCodePeepMatchRule(pCode *pc)
        if(pc_cline2)
          pc_cline2->pc.next = NULL;
       }
-#endif
+      //#endif
 
       if(pcin)
        pCodeDeleteChain(pc,pcin);
index e48e6d0da46916e67538690f1a0a60a5a1987fcc..09923399983d64151f94024ef1d9caf26390472f 100644 (file)
@@ -133,54 +133,6 @@ replace restart {
 %3:    %6
 } 
 
-//replace restart {
-//        btfss        %1
-//        goto %2
-//     %3
-//%2:  %4
-//} by {
-//     ;peep 1 - test/jump to test/skip
-//     btfsc   %1
-//     %3
-//%2:  %4
-//}
-//
-//replace restart {
-//        btfsc        %1
-//        goto %2
-//     %3
-//%2:  %4
-//} by {
-//     ;peep 1a - test/jump to test/skip
-//     btfss   %1
-//     %3
-//%2:  %4
-//}
-//
-//replace restart {
-//        btfss        %1
-//        goto %4
-//%2:  %3
-//%4:  %5
-//} by {
-//     ;peep 1b - test/jump to test/skip
-//     btfsc   %1
-//%2:  %3
-//%4:  %5
-//}
-//
-//replace restart {
-//        btfsc        %1
-//        goto %4
-//%2:  %3
-//%4:  %5
-//} by {
-//     ;peep 1c - test/jump to test/skip
-//     btfss   %1
-//%2:  %3
-//%4:  %5
-//}
-
 
 //bogus test for pcode
 //replace restart {