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.