https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64130
--- Comment #10 from kugan at gcc dot gnu.org --- (In reply to Marc Glisse from comment #6) > (In reply to kugan from comment #5) > > I think it should be in from front-end? > > ? Sorry for the confusing terminology. for the case int fsigned(int a) { return 0xffffffffffffffL / a == 0; } 004t.gimple has: int D.4228; long long int D.4229; long long int D.4230; _Bool D.4231; D.4229 = (long long int) a; D.4230 = 72057594037927935 / D.4229; D.4231 = D.4230 == 0; So based on the "x >= maxval(typeof(a)), x / a cannot be 0" the maxval(typeof(a)) is now maxval(long long int) in the case of ARM. Thats why I was asking if it is to be done before gimple is generated. As I see, the above statement does not rely on value ranges. > > > Tried fixing it in VRP like: > > You don't seem to use ranges at all. This might be the right place to > implement the suggestion from comment #2 (though if it does not use ranges, > match.pd would be better), but for the original optimization, what you want > to improve is the computation of the range of a division. When a has range > [0, 4294967295] we compute for 2305843009213693951 / a the range [0, > 2305843009213693951] which is not optimal, the left bound should be > 536870912 not 0. If the good interval is computed, VRP will automatically > fold == 0 to false without extra code. We already get this right when a has > range [1, 4294967295]. How about something like this: --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -3158,7 +3158,14 @@ extract_range_from_binary_expr_1 (value_range_t *vr, type = VR_VARYING; cmp = compare_values (vr0.min, zero); if (cmp == 1) - min = zero; + { + if (vr1.type == VR_RANGE + && !symbolic_range_p (&vr0) + && !symbolic_range_p (&vr1)) + min = int_const_binop (code, vr0.min, vr1.max); + else + min = zero; + } else if (cmp == 0 || cmp == -1) min = vr0.min; else