public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/98028] [8/9/10/11 Regression] __builtin_sub_overflow_p not folded to const when some constraints are known Date: Fri, 12 Feb 2021 13:41:33 +0000 [thread overview] Message-ID: <bug-98028-4-dTdYB2mrbL@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-98028-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98028 --- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Note, for unsigned f1(unsigned i, unsigned j) { if (j != i) __builtin_unreachable(); return i - j; } this is already optimized through: if (vr->varying_p () && (code == PLUS_EXPR || code == MINUS_EXPR) && TREE_CODE (op1) == SSA_NAME && vr0.kind () == VR_RANGE && symbolic_range_based_on_p (&vr0, op1)) { const bool minus_p = (code == MINUS_EXPR); value_range n_vr1; /* Try with VR0 and [-INF, OP1]. */ if (is_gimple_min_invariant (minus_p ? vr0.max () : vr0.min ())) n_vr1.set (vrp_val_min (expr_type), op1); /* Try with VR0 and [OP1, +INF]. */ else if (is_gimple_min_invariant (minus_p ? vr0.min () : vr0.max ())) n_vr1.set (op1, vrp_val_max (expr_type)); /* Try with VR0 and [OP1, OP1]. */ else n_vr1.set (op1, op1); range_fold_binary_expr (vr, code, expr_type, &vr0, &n_vr1); } (and matching if below for the other range/operand pair) + the symbolic handling in range_fold_binary_symbolics_p -> extract_range_from_plus_minus_expr. And that is also able to optimize unsigned f1(unsigned i, unsigned j, unsigned *r) { if (j >= i) __builtin_unreachable(); return __builtin_sub_overflow (i, j, r); } *r setting to 0. But we don't have any such support for symbolics in check_for_binary_op_overflow. I guess it could be added even for GCC 11, the question is if it would be then usable even for GCC 12 with smbolic ranges in ranger, or not.
next prev parent reply other threads:[~2021-02-12 13:41 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-27 10:50 [Bug tree-optimization/98028] New: " denis.campredon at gmail dot com 2020-11-27 11:12 ` [Bug tree-optimization/98028] [8/9/10/11 Regression] " jakub at gcc dot gnu.org 2021-01-14 9:49 ` rguenth at gcc dot gnu.org 2021-01-14 14:23 ` amacleod at redhat dot com 2021-02-12 13:41 ` jakub at gcc dot gnu.org [this message] 2021-02-12 14:43 ` amacleod at redhat dot com 2021-05-14 9:54 ` [Bug tree-optimization/98028] [9/10/11/12 " jakub at gcc dot gnu.org 2021-06-01 8:19 ` rguenth at gcc dot gnu.org 2022-05-27 9:44 ` [Bug tree-optimization/98028] [10/11/12/13 " rguenth at gcc dot gnu.org 2022-06-28 10:42 ` jakub at gcc dot gnu.org 2023-07-07 10:38 ` [Bug tree-optimization/98028] [11/12/13/14 " rguenth at gcc dot gnu.org
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=bug-98028-4-dTdYB2mrbL@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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).