Bug 81588 - [7/8 Regression] Wrong code at -O2
Summary: [7/8 Regression] Wrong code at -O2
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 8.0
: P2 normal
Target Milestone: 7.2
Assignee: Jakub Jelinek
URL:
Keywords: wrong-code
Depends on:
Blocks: yarpgen
  Show dependency treegraph
 
Reported: 2017-07-27 17:46 UTC by Dmitry Babokin
Modified: 2021-11-01 23:07 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-07-27 00:00:00


Attachments
gcc8-pr81588.patch (1.59 KB, patch)
2017-07-29 07:46 UTC, Jakub Jelinek
Details | Diff
gcc8-pr81588.patch (1.54 KB, patch)
2017-07-31 11:40 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Babokin 2017-07-27 17:46:38 UTC
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
Comment 1 Martin Liška 2017-07-27 19:35:21 UTC
Confirmed, started with r240858.
Comment 2 Jakub Jelinek 2017-07-29 07:46:25 UTC
Created attachment 41860 [details]
gcc8-pr81588.patch

Untested fix.
Comment 3 Jakub Jelinek 2017-07-31 11:40:22 UTC
Created attachment 41872 [details]
gcc8-pr81588.patch

Untested fix - second attempt.
Comment 4 Jakub Jelinek 2017-08-01 08:33:09 UTC
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
Comment 5 Jakub Jelinek 2017-08-01 08:44:17 UTC
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
Comment 6 Jakub Jelinek 2017-08-01 08:53:29 UTC
Fixed.
Comment 7 Jakub Jelinek 2017-08-02 10:27:56 UTC
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
Comment 8 Jakub Jelinek 2017-08-03 09:42:28 UTC
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
Comment 9 Christophe Lyon 2017-08-30 13:14:04 UTC
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.
Comment 10 Christophe Lyon 2017-09-06 13:47:30 UTC
(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
Comment 11 Aldy Hernandez 2017-09-13 16:11:30 UTC
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
Comment 12 Aldy Hernandez 2017-09-13 16:25:32 UTC
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