public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "kugan at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/64130] vrp: handle non zero constant divided by range cannot be zero. Date: Thu, 18 Jun 2015 23:38:00 -0000 [thread overview] Message-ID: <bug-64130-4-cmpiNLxfPA@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-64130-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64130 kugan at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kugan at gcc dot gnu.org --- Comment #5 from kugan at gcc dot gnu.org --- I think it should be in from front-end? Tried fixing it in VRP like: --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -9943,12 +9943,43 @@ simplify_stmt_using_ranges (gimple_stmt_iterator *gsi) { enum tree_code rhs_code = gimple_assign_rhs_code (stmt); tree rhs1 = gimple_assign_rhs1 (stmt); + tree rhs2 = gimple_assign_rhs2 (stmt); switch (rhs_code) { case EQ_EXPR: case NE_EXPR: - /* Transform EQ_EXPR, NE_EXPR into BIT_XOR_EXPR or identity + + /* PR64130. If there is a statement (integer_cst / var == 0) and + integer_cst >= TYPE_MAX (TREE_TYPE (var)) + then (integer_cst / var) cannot be 0. Hence this condition will + be always false. */ + if (rhs_code == EQ_EXPR + && TREE_CODE (rhs1) == SSA_NAME + && integer_zerop (rhs2)) + { + gimple g = SSA_NAME_DEF_STMT (rhs1); + + if (is_gimple_assign (g) + && INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (g))) + && TREE_CODE (gimple_assign_rhs1 (g)) == INTEGER_CST + && TREE_CODE (gimple_assign_rhs2 (g)) == SSA_NAME + && gimple_assign_rhs_code (g) == TRUNC_DIV_EXPR) + { + tree r1 = gimple_assign_rhs1 (g); + tree r2 = gimple_assign_rhs2 (g); + tree max = TYPE_MAX_VALUE (TREE_TYPE (r2)); + if (compare_values (r1, max) == -1 + || compare_values (r1, max) == 0) + { + gimple_assign_set_rhs_with_ops (gsi, NOP_EXPR, rhs2); + update_stmt (stmt); + return true; + } + } + } + + /* Transform EQ_EXPR, NE_EXPR into BIT_XOR_EXPR or identity if the RHS is zero or one, and the LHS are known to be boolean values. */ if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))) But by the time we are in VRP, variable "a" is already promoted to that fits the constant.
next prev parent reply other threads:[~2015-06-18 23:38 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-11-30 20:40 [Bug tree-optimization/64130] New: " andi-gcc at firstfloor dot org 2014-11-30 20:47 ` [Bug tree-optimization/64130] " glisse at gcc dot gnu.org 2014-11-30 20:49 ` pinskia at gcc dot gnu.org 2014-11-30 20:57 ` andi-gcc at firstfloor dot org 2014-12-01 9:30 ` rguenth at gcc dot gnu.org 2015-06-18 23:38 ` kugan at gcc dot gnu.org [this message] 2015-06-19 7:13 ` pinskia at gcc dot gnu.org 2015-06-19 8:05 ` glisse at gcc dot gnu.org 2015-06-19 11:36 ` kugan at gcc dot gnu.org 2015-06-29 0:16 ` kugan at gcc dot gnu.org 2015-06-29 8:39 ` 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-64130-4-cmpiNLxfPA@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).