public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-131] rewrite undefined overflow to defined in ifcombine Date: Thu, 5 May 2022 10:11:44 +0000 (GMT) [thread overview] Message-ID: <20220505101144.684FB3858434@sourceware.org> (raw) https://gcc.gnu.org/g:c2a0d2e6f636c6ad7da44256b6bea7470d895100 commit r13-131-gc2a0d2e6f636c6ad7da44256b6bea7470d895100 Author: Richard Biener <rguenther@suse.de> Date: Mon Apr 4 11:29:14 2022 +0200 rewrite undefined overflow to defined in ifcombine When we make stmts to execute unconditionally in ifcombine we have to make sure to rewrite stmts that can invoke undefined behavior on overflow into a form with defined overflow. That's possible for all but signed division for which we have to avoid the transform. 2022-04-04 Richard Biener <rguenther@suse.de> * tree-ssa-ifcombine.cc (bb_no_side_effects_p): Avoid executing divisions with undefined overflow unconditionally. (pass_tree_ifcombine::execute): Rewrite stmts with undefined overflow to defined. Diff: --- gcc/tree-ssa-ifcombine.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc index 3a4ab694b71..cb86cc1ea5f 100644 --- a/gcc/tree-ssa-ifcombine.cc +++ b/gcc/tree-ssa-ifcombine.cc @@ -125,10 +125,26 @@ bb_no_side_effects_p (basic_block bb) if (is_gimple_debug (stmt)) continue; + gassign *ass; + enum tree_code rhs_code; if (gimple_has_side_effects (stmt) || gimple_uses_undefined_value_p (stmt) || gimple_could_trap_p (stmt) || gimple_vuse (stmt) + /* We need to rewrite stmts with undefined overflow to use + unsigned arithmetic but cannot do so for signed division. */ + || ((ass = dyn_cast <gassign *> (stmt)) + && INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_lhs (ass))) + && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (gimple_assign_lhs (ass))) + && ((rhs_code = gimple_assign_rhs_code (ass)), true) + && (rhs_code == TRUNC_DIV_EXPR + || rhs_code == CEIL_DIV_EXPR + || rhs_code == FLOOR_DIV_EXPR + || rhs_code == ROUND_DIV_EXPR) + /* We cannot use expr_not_equal_to since we'd have to restrict + flow-sensitive info to whats known at the outer if. */ + && (TREE_CODE (gimple_assign_rhs2 (ass)) != INTEGER_CST + || !integer_minus_onep (gimple_assign_rhs2 (ass)))) /* const calls don't match any of the above, yet they could still have some side-effects - they could contain gimple_could_trap_p statements, like floating point @@ -847,6 +863,19 @@ pass_tree_ifcombine::execute (function *fun) /* Clear range info from all stmts in BB which is now executed conditional on a always true/false condition. */ reset_flow_sensitive_info_in_bb (bb); + for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi); + gsi_next (&gsi)) + { + gassign *ass = dyn_cast <gassign *> (gsi_stmt (gsi)); + if (!ass) + continue; + tree lhs = gimple_assign_lhs (ass); + if ((INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + || POINTER_TYPE_P (TREE_TYPE (lhs))) + && arith_code_with_undefined_signed_overflow + (gimple_assign_rhs_code (ass))) + rewrite_to_defined_overflow (ass, true); + } cfg_changed |= true; } }
reply other threads:[~2022-05-05 10:11 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=20220505101144.684FB3858434@sourceware.org \ --to=rguenth@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).