gcc trunk, rev250630, x86_64. > cat f.cpp #include <stdio.h> long int var_34 = 5011877430933453486L; unsigned short var_82 = 24847; long int var_58 = 1; void foo() { if (var_82 > var_34 ^ true + (var_34 < 0)) var_58 = 0; } int main() { foo(); printf("%ld\n", var_58); return 0; } > g++ -O0 f.cpp -o out; ./out 0 > g++ -O2 f.cpp -o out; ./out 1
Confirmed, started with r240858.
Created attachment 41860 [details] gcc8-pr81588.patch Untested fix.
Created attachment 41872 [details] gcc8-pr81588.patch Untested fix - second attempt.
Author: jakub Date: Tue Aug 1 08:32:37 2017 New Revision: 250760 URL: https://gcc.gnu.org/viewcvs?rev=250760&root=gcc&view=rev Log: PR tree-optimization/81588 * tree-ssa-reassoc.c (optimize_range_tests_var_bound): If ranges[i].in_p, invert comparison code ccode. For >/>=, swap rhs1 and rhs2 and comparison code unconditionally, for </<= don't do that. Don't swap rhs1/rhs2 again if ranges[i].in_p, instead invert comparison code ccode if opcode or oe->rank is BIT_IOR_EXPR. * gcc.dg/tree-ssa/pr81588.c: New test. * gcc.dg/pr81588.c: New test. * gcc.c-torture/execute/pr81588.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr81588.c trunk/gcc/testsuite/gcc.dg/pr81588.c trunk/gcc/testsuite/gcc.dg/tree-ssa/pr81588.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-ssa-reassoc.c
Author: jakub Date: Tue Aug 1 08:43:45 2017 New Revision: 250761 URL: https://gcc.gnu.org/viewcvs?rev=250761&root=gcc&view=rev Log: PR tree-optimization/81588 * tree-ssa-reassoc.c (optimize_range_tests_var_bound): If ranges[i].in_p, invert comparison code ccode. For >/>=, swap rhs1 and rhs2 and comparison code unconditionally, for </<= don't do that. Don't swap rhs1/rhs2 again if ranges[i].in_p, instead invert comparison code ccode if opcode or oe->rank is BIT_IOR_EXPR. * gcc.dg/tree-ssa/pr81588.c: New test. * gcc.dg/pr81588.c: New test. * gcc.c-torture/execute/pr81588.c: New test. Added: branches/gcc-7-branch/gcc/testsuite/gcc.c-torture/execute/pr81588.c branches/gcc-7-branch/gcc/testsuite/gcc.dg/pr81588.c branches/gcc-7-branch/gcc/testsuite/gcc.dg/tree-ssa/pr81588.c Modified: branches/gcc-7-branch/gcc/ChangeLog branches/gcc-7-branch/gcc/testsuite/ChangeLog branches/gcc-7-branch/gcc/tree-ssa-reassoc.c
Fixed.
Author: jakub Date: Wed Aug 2 10:27:24 2017 New Revision: 250819 URL: https://gcc.gnu.org/viewcvs?rev=250819&root=gcc&view=rev Log: PR tree-optimization/81655 PR tree-optimization/81588 * gcc.dg/tree-ssa/pr81588.c: Use -mbranch-cost=2 where possible, don't run the test on branch-cost=1 targets. Modified: branches/gcc-7-branch/gcc/testsuite/ChangeLog branches/gcc-7-branch/gcc/testsuite/gcc.dg/tree-ssa/pr81588.c
Author: jakub Date: Thu Aug 3 09:41:55 2017 New Revision: 250849 URL: https://gcc.gnu.org/viewcvs?rev=250849&root=gcc&view=rev Log: PR tree-optimization/81655 PR tree-optimization/81588 * tree-ssa-reassoc.c (optimize_range_tests_var_bound): Handle also the case when ranges[i].low and high are 1 for unsigned type with precision 1. Modified: trunk/gcc/ChangeLog trunk/gcc/tree-ssa-reassoc.c
I've noticed that the new testcase (gcc.dg/tree-ssa/pr81588.c) fails on the gcc-7 branch (r251446) on arm-linux-gnueabihf --with-cpu=cortex-a5 --with-fpu=vfpv3-d16-fp16.
(In reply to Christophe Lyon from comment #9) > I've noticed that the new testcase (gcc.dg/tree-ssa/pr81588.c) fails on the > gcc-7 branch (r251446) on arm-linux-gnueabihf --with-cpu=cortex-a5 > --with-fpu=vfpv3-d16-fp16. Thomas has just created a new bug report for this: bug #82120 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82120
Author: aldyh Date: Wed Sep 13 16:10:58 2017 New Revision: 252208 URL: https://gcc.gnu.org/viewcvs?rev=252208&root=gcc&view=rev Log: PR tree-optimization/81588 * tree-ssa-reassoc.c (optimize_range_tests_var_bound): If ranges[i].in_p, invert comparison code ccode. For >/>=, swap rhs1 and rhs2 and comparison code unconditionally, for </<= don't do that. Don't swap rhs1/rhs2 again if ranges[i].in_p, instead invert comparison code ccode if opcode or oe->rank is BIT_IOR_EXPR. * gcc.dg/tree-ssa/pr81588.c: New test. * gcc.dg/pr81588.c: New test. * gcc.c-torture/execute/pr81588.c: New test. Added: branches/range-gen2/gcc/testsuite/gcc.c-torture/execute/pr81588.c branches/range-gen2/gcc/testsuite/gcc.dg/pr81588.c branches/range-gen2/gcc/testsuite/gcc.dg/tree-ssa/pr81588.c Modified: branches/range-gen2/gcc/ChangeLog branches/range-gen2/gcc/testsuite/ChangeLog branches/range-gen2/gcc/tree-ssa-reassoc.c
Author: aldyh Date: Wed Sep 13 16:25:00 2017 New Revision: 252273 URL: https://gcc.gnu.org/viewcvs?rev=252273&root=gcc&view=rev Log: PR tree-optimization/81655 PR tree-optimization/81588 * tree-ssa-reassoc.c (optimize_range_tests_var_bound): Handle also the case when ranges[i].low and high are 1 for unsigned type with precision 1. Modified: branches/range-gen2/gcc/ChangeLog branches/range-gen2/gcc/tree-ssa-reassoc.c