From 334d46c82420b40682d224b62f2930eb7d77af75 Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Sat, 2 Jun 2007 19:41:33 +0000 Subject: [PATCH] * src/mcs51/gen.c (outBitC, genRet): used IS_OP_RUONLY, (genNot, genXor): used toCarry, also fixes a bug for c = bit ^ val * src/mcs51/ralloc.c: removed IS_OP_RUONLY + some cosmetic changes * src/SDCCast.c (resultTypePropagate): propagate for '!', (decorateType): also optimize comparisons with RESULT_TYPE_BIT, bugfix: only use newBoolLink for bit result type * src/SDCCicode.c (geniCodeLogic): added param tree, bugfix: use newBoolLink if tree is bit type, bug appears when ruonly, (geniCodeLogicAndOr): use IS_BIT, (geniCodeJumpTable, geniCodeSwitch): added NULL param to geniCodeLogic, (ast2iCode): added tree param to geniCodeLogic for comparisons * src/SDCCsymt.h: added IS_OP_RUONLY and IS_OP_ACCUSE * support/regression/tests/bug1723128.c: added test NotZero git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4829 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 18 +++++++++- src/SDCCast.c | 9 ++--- src/SDCCicode.c | 22 ++++++------ src/SDCCsymt.h | 7 ++-- src/mcs51/gen.c | 23 +++--------- src/mcs51/ralloc.c | 51 +++++++++++++-------------- support/regression/tests/bug1723128.c | 12 +++++-- 7 files changed, 76 insertions(+), 66 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6920c321..603bcd92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2007-06-02 Maarten Brock + + * src/mcs51/gen.c (outBitC, genRet): used IS_OP_RUONLY, + (genNot, genXor): used toCarry, also fixes a bug for c = bit ^ val + * src/mcs51/ralloc.c: removed IS_OP_RUONLY + some cosmetic changes + * src/SDCCast.c (resultTypePropagate): propagate for '!', + (decorateType): also optimize comparisons with RESULT_TYPE_BIT, + bugfix: only use newBoolLink for bit result type + * src/SDCCicode.c (geniCodeLogic): added param tree, + bugfix: use newBoolLink if tree is bit type, bug appears when ruonly, + (geniCodeLogicAndOr): use IS_BIT, + (geniCodeJumpTable, geniCodeSwitch): added NULL param to geniCodeLogic, + (ast2iCode): added tree param to geniCodeLogic for comparisons + * src/SDCCsymt.h: added IS_OP_RUONLY and IS_OP_ACCUSE + * support/regression/tests/bug1723128.c: added test NotZero + 2007-06-01 Borut Razem * SDCPP synchronized with GCC CPP release version 4.2.0, @@ -98,7 +114,7 @@ * src/regression/Makefile, * src/regression/pcodeopt.c: regression test for the above fix -2007-05-08 Maarten Brock +2007-05-11 Maarten Brock * src/SDCCpeeph.c (labelIsUncondJump): ignore identical labels for jumps to self, fixed bug 1717281 diff --git a/src/SDCCast.c b/src/SDCCast.c index d48f3c00..84bbdd8f 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -2280,6 +2280,7 @@ resultTypePropagate (ast *tree, RESULT_TYPE resultType) { case AND_OP: case OR_OP: + case '!': return resultType; case '=': case '?': @@ -4153,7 +4154,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) if (IS_LITERAL(RTYPE(tree)) && floatFromVal (valFromType (RETYPE (tree))) == 0 && tree->opval.op == EQ_OP && - resultType == RESULT_TYPE_IFX) + (resultType == RESULT_TYPE_IFX || resultType == RESULT_TYPE_BIT)) { tree->opval.op = '!'; tree->right = NULL; @@ -4208,7 +4209,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) } LRVAL (tree) = RRVAL (tree) = 1; - TTYPE (tree) = TETYPE (tree) = newBoolLink (); + TTYPE (tree) = TETYPE (tree) = (resultType == RESULT_TYPE_BIT) ? newBoolLink() :newCharLink(); /* condition transformations */ { @@ -5757,8 +5758,8 @@ optimizeCompare (ast * root) root->right->opval.val : NULL); /* if left is a BITVAR in BITSPACE */ - /* and right is a LITERAL then opt- */ - /* imize else do nothing */ + /* and right is a LITERAL then */ + /* optimize else do nothing */ if (vleft && vright && IS_BITVAR (vleft->etype) && IN_BITSPACE (SPEC_OCLS (vleft->etype)) && diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 04a3e055..7e397fcd 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -2038,7 +2038,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) /* This seems very dangerous to me, since there are several */ /* optimizations (for example, gcse) that don't notice the */ - /* cast hidden in this assignement and may simplify an */ + /* cast hidden in this assignment and may simplify an */ /* iCode to use the original (uncasted) operand. */ /* Unfortunately, other things break when this cast is */ /* made explicit. Need to fix this someday. */ @@ -2733,7 +2733,7 @@ geniCodePreDec (operand * op, bool lvalue) /*-----------------------------------------------------------------*/ -/* geniCodeBitwise - gen int code for bitWise operators */ +/* geniCodeBitwise - gen int code for bitWise operators */ /*-----------------------------------------------------------------*/ operand * geniCodeBitwise (operand * left, operand * right, @@ -2947,10 +2947,10 @@ geniCodeRightShift (operand * left, operand * right) /* geniCodeLogic- logic code */ /*-----------------------------------------------------------------*/ static operand * -geniCodeLogic (operand * left, operand * right, int op) +geniCodeLogic (operand * left, operand * right, int op, ast *tree) { iCode *ic; - sym_link *ctype; + sym_link *ctype, *ttype; sym_link *rtype = operandType (right); sym_link *ltype = operandType (left); @@ -3017,7 +3017,9 @@ geniCodeLogic (operand * left, operand * right, int op) ctype = usualBinaryConversions (&left, &right, RESULT_TYPE_BIT, 0); ic = newiCode (op, left, right); - IC_RESULT (ic) = newiTempOperand (newCharLink (), 1); + /* store 0 or 1 in result */ + ttype = (tree && IS_BIT (tree->ftype)) ? newBoolLink() : newCharLink(); + IC_RESULT (ic) = newiTempOperand (ttype, 1); /* if comparing float and not a '==' || '!=' || '&&' || '||' (these @@ -3088,7 +3090,7 @@ geniCodeLogicAndOr (ast *tree, int lvl) ADDTOCHAIN (ic); /* store 0 or 1 in result */ - type = (SPEC_NOUN(tree->ftype) == V_BIT) ? newBoolLink() : newCharLink(); + type = (IS_BIT (tree->ftype)) ? newBoolLink() : newCharLink(); result = newiTempOperand (type, 1); geniCodeLabel (falseLabel); @@ -3761,13 +3763,13 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree) the condition is unsigned & minimum value is zero */ if (!(min == 0 && IS_UNSIGNED (cetype))) { - boundary = geniCodeLogic (cond, operandFromLit (min), '<'); + boundary = geniCodeLogic (cond, operandFromLit (min), '<', NULL); ic = newiCodeCondition (boundary, falseLabel, NULL); ADDTOCHAIN (ic); } /* now for upper bounds */ - boundary = geniCodeLogic (cond, operandFromLit (max), '>'); + boundary = geniCodeLogic (cond, operandFromLit (max), '>', NULL); ic = newiCodeCondition (boundary, falseLabel, NULL); ADDTOCHAIN (ic); } @@ -3848,7 +3850,7 @@ geniCodeSwitch (ast * tree,int lvl) operand *compare = geniCodeLogic (cond, operandFromValue (caseVals), - EQ_OP); + EQ_OP, NULL); SNPRINTF (buffer, sizeof(buffer), "_case_%d_%d", tree->values.switchVals.swNum, @@ -4293,7 +4295,7 @@ ast2iCode (ast * tree,int lvl) leftOp = geniCodeRValue (left , FALSE); rightOp = geniCodeRValue (right, FALSE); - return geniCodeLogic (leftOp, rightOp, tree->opval.op); + return geniCodeLogic (leftOp, rightOp, tree->opval.op, tree); } case '?': return geniCodeConditional (tree,lvl); diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 10778f32..79230277 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -156,7 +156,7 @@ typedef struct specifier unsigned b_signed:1; /* just for sanity checks only*/ unsigned b_static:1; /* 1=static keyword found */ unsigned b_extern:1; /* 1=extern found */ - unsigned b_inline:1; /* inline function requested */ + unsigned b_inline:1; /* inline function requested */ unsigned b_absadr:1; /* absolute address specfied */ unsigned b_volatile:1; /* is marked as volatile */ unsigned b_const:1; /* is a constant */ @@ -329,7 +329,7 @@ typedef struct symbol struct iCode *fuse; /* furthest use */ struct iCode *rematiCode; /* rematerialise with which instruction */ struct operand *reqv; /* register equivalent of a local variable */ - struct symbol *prereqv; /* symbol before register equiv. substituion */ + struct symbol *prereqv; /* symbol before register equiv. substitution */ struct symbol *psbase; /* if pseudo symbol, the symbol it is based on */ union { @@ -367,6 +367,9 @@ extern sym_link *validateLink(sym_link *l, const char *file, unsigned line); /* Easy Access Macros */ +#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly) +#define IS_OP_ACCUSE(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->accuse) + #define DCL_TYPE(l) validateLink(l, "DCL_TYPE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.dcl_type #define DCL_ELEM(l) validateLink(l, "DCL_ELEM", #l, DECLARATOR, __FILE__, __LINE__)->select.d.num_elem #define DCL_PTR_CONST(l) validateLink(l, "DCL_PTR_CONST", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_const diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 39a01cbe..957d58dc 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -66,8 +66,6 @@ static char *accUse[] = static unsigned short rbank = -1; -#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly) - #define REG_WITH_INDEX mcs51_regWithIdx #define AOP(op) op->aop @@ -1854,7 +1852,7 @@ outBitC (operand * result) /* if the result is bit */ if (AOP_TYPE (result) == AOP_CRY) { - if (!OP_SYMBOL (result)->ruonly) + if (!IS_OP_RUONLY (result)) aopPut (result, "c", 0); } else @@ -2008,7 +2006,7 @@ genNot (iCode * ic) } else { - emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir); + toCarry (IC_LEFT (ic)); emitcode ("cpl", "c"); outBitC (IC_RESULT (ic)); } @@ -4055,7 +4053,7 @@ genRet (iCode * ic) if (IS_BIT(_G.currentFunc->etype)) { - if (!(IS_SYMOP (IC_LEFT (ic)) && OP_SYMBOL (IC_LEFT (ic))->ruonly)) + if (!IS_OP_RUONLY (IC_LEFT (ic))) toCarry (IC_LEFT (ic)); } else @@ -7454,21 +7452,8 @@ genXor (iCode * ic, iCode * ifx) } else { - int sizer = AOP_SIZE (right); // c = bit ^ val - // if val>>1 != 0, result = 1 - emitcode ("setb", "c"); - while (sizer) - { - MOVA (aopGet (right, sizer - 1, FALSE, FALSE)); - if (sizer == 1) - // test the msb of the lsb - emitcode ("anl", "a,#0xfe"); - emitcode ("jnz", "%05d$", tlbl->key + 100); - sizer--; - } - // val = (0,1) - emitcode ("rrc", "a"); + toCarry (right); } emitcode ("jnb", "%s,%05d$", AOP (left)->aopu.aop_dir, (tlbl->key + 100)); emitcode ("cpl", "c"); diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index 54af801e..833c70e1 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -2114,10 +2114,10 @@ packRegsForAssign (iCode * ic, eBBlock * ebp) /* Don't move an assignment out of a critical block */ if (dic->op == CRITICAL) - { - dic = NULL; - break; - } + { + dic = NULL; + break; + } if (SKIP_IC2 (dic)) continue; @@ -2442,8 +2442,6 @@ packRegsForSupport (iCode * ic, eBBlock * ebp) return 0; } -#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly) - /*-----------------------------------------------------------------*/ /* packRegsForOneuse : - will reduce some registers for single Use */ @@ -2521,25 +2519,25 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp) } else { - /* otherwise check that the definition does - not contain any symbols in far space */ - if (isOperandInFarSpace (IC_LEFT (dic)) || - isOperandInFarSpace (IC_RIGHT (dic)) || - IS_OP_RUONLY (IC_LEFT (ic)) || - IS_OP_RUONLY (IC_RIGHT (ic))) - { - return NULL; - } + /* otherwise check that the definition does + not contain any symbols in far space */ + if (isOperandInFarSpace (IC_LEFT (dic)) || + isOperandInFarSpace (IC_RIGHT (dic)) || + IS_OP_RUONLY (IC_LEFT (ic)) || + IS_OP_RUONLY (IC_RIGHT (ic))) + { + return NULL; + } - /* if pointer set then make sure the pointer - is one byte */ - if (POINTER_SET (dic) && - !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE))) - return NULL; + /* if pointer set then make sure the pointer + is one byte */ + if (POINTER_SET (dic) && + !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE))) + return NULL; - if (POINTER_GET (dic) && - !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE))) - return NULL; + if (POINTER_GET (dic) && + !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE))) + return NULL; } /* Make sure no overlapping liverange is already assigned to DPTR */ @@ -2770,7 +2768,7 @@ packRegsForAccUse (iCode * ic) getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1) return; - /* if the usage is not is an assignment + /* if the usage is not an assignment or an arithmetic / bitwise / shift operation then not */ if (uic->op != '=' && !IS_ARITHMETIC_OP (uic) && @@ -3050,8 +3048,7 @@ packRegisters (eBBlock ** ebpp, int blockno) if (POINTER_SET (ic)) OP_SYMBOL (IC_RESULT (ic))->uptr = 1; - if (POINTER_GET (ic) && - IS_SYMOP(IC_LEFT (ic))) + if (POINTER_GET (ic) && IS_SYMOP(IC_LEFT (ic))) OP_SYMBOL (IC_LEFT (ic))->uptr = 1; if (!SKIP_IC2 (ic)) @@ -3259,7 +3256,7 @@ mcs51_assignRegisters (ebbIndex * ebbi) } else { - mcs51_nRegs = 8; + mcs51_nRegs = 8; } _G.allBitregs = findAllBitregs (); diff --git a/support/regression/tests/bug1723128.c b/support/regression/tests/bug1723128.c index 2565011b..e140e39b 100644 --- a/support/regression/tests/bug1723128.c +++ b/support/regression/tests/bug1723128.c @@ -72,12 +72,18 @@ bool VerifyCRC(void) for (i=0; i<(rx_index-1); i++) crc = crc_table[rx_buffer[i] ^ crc] ; - return (crc == rx_buffer[rx_index-1]) ; + return (crc == rx_buffer[rx_index-1]) ; +} + +bool NotZero(unsigned int t) +{ + return (t != 0); } void testBug(void) { - rx_index = 1; - ASSERT (VerifyCRC()); + rx_index = 1; + ASSERT (VerifyCRC()); + ASSERT (NotZero(300)); } -- 2.30.2