public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3190] Add op1_range for __builtin_signbit. Date: Mon, 10 Oct 2022 09:40:09 +0000 (GMT) [thread overview] Message-ID: <20221010094009.BDDEC3858435@sourceware.org> (raw) https://gcc.gnu.org/g:98ad452728f51d6f44c7ff71e3d20c6c1dca20fd commit r13-3190-g98ad452728f51d6f44c7ff71e3d20c6c1dca20fd Author: Aldy Hernandez <aldyh@redhat.com> Date: Wed Oct 5 20:23:15 2022 +0200 Add op1_range for __builtin_signbit. This is the op1_range range-op entry for __builtin_signbit. It allows us to wind back through a call to signbit. For example, on the true side of if (__builtin_signbit(x_5) != 0) we can crop down the range of x_5 to: [frange] float [-Inf, -0.0 (-0x0.0p+0)] -NAN Similarly on the false side, we can crop to: [frange] float [0.0 (0x0.0p+0), +Inf] +NAN Tested on x86-64 Linux. gcc/ChangeLog: * gimple-range-op.cc: Add op1_range entry for __builtin_signbit. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/vrp-float-signbit-3.c: New test. Diff: --- gcc/gimple-range-op.cc | 20 ++++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-3.c | 15 +++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 42ebc7d6ce5..abc33e7af0c 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -306,6 +306,7 @@ class cfn_signbit : public range_operator_float { public: using range_operator_float::fold_range; + using range_operator_float::op1_range; virtual bool fold_range (irange &r, tree type, const frange &lh, const irange &, relation_kind) const { @@ -320,6 +321,25 @@ public: } return false; } + virtual bool op1_range (frange &r, tree type, const irange &lhs, + const frange &, relation_kind) const override + { + if (lhs.zero_p ()) + { + r.set (type, dconst0, frange_val_max (type)); + r.update_nan (false); + return true; + } + if (!lhs.contains_p (build_zero_cst (lhs.type ()))) + { + REAL_VALUE_TYPE dconstm0 = dconst0; + dconstm0.sign = 1; + r.set (type, frange_val_min (type), dconstm0); + r.update_nan (true); + return true; + } + return false; + } } op_cfn_signbit; // Implement range operator for CFN_BUILT_IN_TOUPPER and CFN_BUILT_IN_TOLOWER. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-3.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-3.c new file mode 100644 index 00000000000..182a33fca6e --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-3.c @@ -0,0 +1,15 @@ +// { dg-do compile } +// { dg-options "-O2 -ffinite-math-only -fdump-tree-evrp" } + +void link_error(); + +void foo(float x) +{ + if (__builtin_signbit (x)) + { + if (x > 0.0) + link_error(); + } +} + +// { dg-final { scan-tree-dump-not "link_error" "evrp" } }
reply other threads:[~2022-10-10 9:40 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221010094009.BDDEC3858435@sourceware.org \ --to=aldyh@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).