build_range_check explicitly allows LOW and HIGH to be a different type from EXP, so we need to use w::to_widest when comparing a value based on HIGH with a value based on EXP's type.
Tested on powerpc64le-linux-gnu and installed as obvious. Richard 2017-10-04 Richard Sandiford <richard.sandif...@linaro.org> gcc/ PR tree-optimization/82413 * fold-const.c (build_range_check): Use widest_int when comparing the maximum ETYPE value with HIGH. gcc/testsuite/ PR tree-optimization/82413 * g++.dg/pr82413.C: New test. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c 2017-10-04 11:43:11.653350269 +0100 +++ gcc/fold-const.c 2017-10-04 11:43:49.030813918 +0100 @@ -4851,7 +4851,7 @@ build_range_check (location_t loc, tree { int prec = TYPE_PRECISION (etype); - if (wi::mask (prec - 1, false, prec) == high) + if (wi::mask <widest_int> (prec - 1, false) == wi::to_widest (high)) { if (TYPE_UNSIGNED (etype)) { Index: gcc/testsuite/g++.dg/pr82413.C =================================================================== --- /dev/null 2017-10-04 10:21:58.939451407 +0100 +++ gcc/testsuite/g++.dg/pr82413.C 2017-10-04 11:43:49.030813918 +0100 @@ -0,0 +1,3 @@ +bool a; +int b; +void c() { b &&a <= 0; }