Avoided generating unnecessary true-case labels in logic AND/OR.

This commit is contained in:
acqn 2020-08-22 11:10:17 +08:00
parent 85ea06687b
commit f289ea6c14

View file

@ -3184,7 +3184,7 @@ static void hieOrPP (ExprDesc *Expr)
static int hieAnd (ExprDesc* Expr, unsigned TrueLab, int* UsedTrueLab) static int hieAnd (ExprDesc* Expr, unsigned* TrueLab, int* TrueLabAllocated)
/* Process "exp && exp". This should only be called within hieOr. /* Process "exp && exp". This should only be called within hieOr.
** Return true if logic AND does occur. ** Return true if logic AND does occur.
*/ */
@ -3275,14 +3275,17 @@ static int hieAnd (ExprDesc* Expr, unsigned TrueLab, int* UsedTrueLab)
/* Last expression */ /* Last expression */
if ((Flags & E_EVAL_UNEVAL) != E_EVAL_UNEVAL) { if ((Flags & E_EVAL_UNEVAL) != E_EVAL_UNEVAL) {
if (HasFalseJump || HasTrueJump) { if (HasFalseJump || HasTrueJump) {
/* In either case we need the true label anyways */ if (*TrueLabAllocated == 0) {
HasTrueJump = 1; /* Get a label that we will use for true expressions */
*TrueLab = GetLocalLabel ();
*TrueLabAllocated = 1;
}
if (!ED_IsConstAbs (&Expr2)) { if (!ED_IsConstAbs (&Expr2)) {
/* Will branch to true and fall to false */ /* Will branch to true and fall to false */
g_truejump (CF_NONE, TrueLab); g_truejump (CF_NONE, *TrueLab);
} else { } else {
/* Will jump away */ /* Will jump away */
g_jump (TrueLab); g_jump (*TrueLab);
} }
/* The result is an rvalue in primary */ /* The result is an rvalue in primary */
ED_FinalizeRValLoad (Expr); ED_FinalizeRValLoad (Expr);
@ -3303,11 +3306,6 @@ static int hieAnd (ExprDesc* Expr, unsigned TrueLab, int* UsedTrueLab)
Expr->Type = type_bool; Expr->Type = type_bool;
} }
/* Tell our caller that we're used the true label */
if (HasTrueJump) {
*UsedTrueLab = 1;
}
/* Tell our caller that we're evaluating a boolean */ /* Tell our caller that we're evaluating a boolean */
return 1; return 1;
} }
@ -3325,20 +3323,13 @@ static void hieOr (ExprDesc *Expr)
unsigned TrueLab; /* Jump to this label if true */ unsigned TrueLab; /* Jump to this label if true */
unsigned DoneLab; unsigned DoneLab;
int HasTrueJump = 0; int HasTrueJump = 0;
int HasNewTrueJump;
CodeMark Start; CodeMark Start;
/* Get a label that we will use for true expressions */
TrueLab = GetLocalLabel ();
/* Call the next level parser */ /* Call the next level parser */
GetCodePos (&Start); GetCodePos (&Start);
AndOp = hieAnd (Expr, TrueLab, &HasNewTrueJump); AndOp = hieAnd (Expr, &TrueLab, &HasTrueJump);
if ((Flags & E_EVAL_UNEVAL) == E_EVAL_UNEVAL) { if ((Flags & E_EVAL_UNEVAL) == E_EVAL_UNEVAL) {
RemoveCode (&Start); RemoveCode (&Start);
} else {
/* Remember the jump */
HasTrueJump = HasNewTrueJump;
} }
/* Any boolean or's? */ /* Any boolean or's? */
@ -3361,8 +3352,11 @@ static void hieOr (ExprDesc *Expr)
/* Get first expr */ /* Get first expr */
LoadExpr (CF_FORCECHAR, Expr); LoadExpr (CF_FORCECHAR, Expr);
/* Remember that the jump is used */ if (HasTrueJump == 0) {
HasTrueJump = 1; /* Get a label that we will use for true expressions */
TrueLab = GetLocalLabel();
HasTrueJump = 1;
}
/* Jump to TrueLab if true */ /* Jump to TrueLab if true */
g_truejump (CF_NONE, TrueLab); g_truejump (CF_NONE, TrueLab);
@ -3385,12 +3379,9 @@ static void hieOr (ExprDesc *Expr)
/* Get rhs subexpression */ /* Get rhs subexpression */
GetCodePos (&Start); GetCodePos (&Start);
AndOp = hieAnd (&Expr2, TrueLab, &HasNewTrueJump); AndOp = hieAnd (&Expr2, &TrueLab, &HasTrueJump);
if ((Flags & E_EVAL_UNEVAL) == E_EVAL_UNEVAL) { if ((Flags & E_EVAL_UNEVAL) == E_EVAL_UNEVAL) {
RemoveCode (&Start); RemoveCode (&Start);
} else {
/* Remember the jump */
HasTrueJump = HasTrueJump || HasNewTrueJump;
} }
/* Check type */ /* Check type */
@ -3405,7 +3396,10 @@ static void hieOr (ExprDesc *Expr)
ED_RequireTest (&Expr2); ED_RequireTest (&Expr2);
LoadExpr (CF_FORCECHAR, &Expr2); LoadExpr (CF_FORCECHAR, &Expr2);
HasTrueJump = 1; if (HasTrueJump == 0) {
TrueLab = GetLocalLabel();
HasTrueJump = 1;
}
g_truejump (CF_NONE, TrueLab); g_truejump (CF_NONE, TrueLab);
} }
} else if (Expr2.IVal != 0) { } else if (Expr2.IVal != 0) {