From: Alan T. DeKok Date: Tue, 5 Sep 2023 17:38:34 +0000 (-0400) Subject: more peephole optimizations for logical operations X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2cef72d1c79bdf5ecff4c154c96bfeb6d99c07d;p=thirdparty%2Ffreeradius-server.git more peephole optimizations for logical operations --- diff --git a/src/lib/unlang/xlat_purify.c b/src/lib/unlang/xlat_purify.c index 6492b16276e..c4b14a40a3f 100644 --- a/src/lib/unlang/xlat_purify.c +++ b/src/lib/unlang/xlat_purify.c @@ -254,7 +254,15 @@ static xlat_exp_t *logical_peephole_optimize(xlat_exp_t *lhs, fr_token_t op, xla * lhs->call.args->flags.can_purify |= rhs->flags.can_purify | rhs->flags.pure; * lhs->flags.can_purify = lhs->call.args->flags.can_purify; */ - if (!is_truthy(lhs, &value)) return NULL; + if (!is_truthy(lhs, &value)) { + xlat_exp_t *tmp; + + if (!is_truthy(rhs, &value)) return NULL; + + tmp = lhs; + lhs = rhs; + rhs = tmp; + } /* * 1 && FOO --> FOO diff --git a/src/tests/unit/condition/base.txt b/src/tests/unit/condition/base.txt index 1a9e6d0b29d..78fbb08637b 100644 --- a/src/tests/unit/condition/base.txt +++ b/src/tests/unit/condition/base.txt @@ -649,13 +649,11 @@ match false # # More short-circuit evaluations # -# @todo - peephole - optimise at parse time -# condition (&User-Name == "bob") && (false) -match ((&User-Name == "bob") && false) +match false condition (&User-Name == "bob") || (true) -match ((&User-Name == "bob") || true) +match true # # A && (B || C) is not the same as (A && B) || C, for 0/1/1