User account creation filtered due to spam.

Bug 71947 - [6 Regression] x ^ y not folded to 0 if x == y by DOM
Summary: [6 Regression] x ^ y not folded to 0 if x == y by DOM
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 7.0
: P2 normal
Target Milestone: 6.5
Assignee: Jeffrey A. Law
URL:
Keywords: missed-optimization
: 77647 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-07-20 12:56 UTC by prathamesh3492
Modified: 2017-07-04 08:47 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work: 5.4.0
Known to fail:
Last reconfirmed: 2016-07-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description prathamesh3492 2016-07-20 12:56:54 UTC
Hi,
For the following case:
int f(int x, int y)
{
  int ret;
  if (x == y)
    ret = x ^ y;
  else
    ret = 1;

  return ret;
}

x ^ y does not get folded to 0.

From the discussion in:
https://gcc.gnu.org/ml/gcc-patches/2016-07/msg00385.html
r233207 must have regressed this test-case.

Thanks,
Prathamesh
Comment 1 Richard Biener 2016-07-20 15:37:28 UTC
Confirmed.
Comment 2 Richard Biener 2016-07-21 08:29:47 UTC
I have a fix that makes this folded at -O2 by VRP.  At -O1 we only have DOM which
was optimizing this in GCC 5.
Comment 3 Richard Biener 2016-07-21 13:01:03 UTC
Author: rguenth
Date: Thu Jul 21 13:00:32 2016
New Revision: 238591

URL: https://gcc.gnu.org/viewcvs?rev=238591&root=gcc&view=rev
Log:
2016-07-21  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/71947
	* tree-vrp.c (extract_range_from_assert): Singleton symbolic
	ranges have useful limit_vr information.

	* gcc.dg/tree-ssa/vrp102.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/vrp102.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vrp.c
Comment 4 Richard Biener 2016-07-21 13:57:05 UTC
Now the testcase is optimized at -O2 by VRP but still not at -O1.
Comment 5 Richard Biener 2016-08-22 08:29:36 UTC
GCC 6.2 is being released, adjusting target milestone.
Comment 6 Richard Biener 2016-08-22 08:30:48 UTC
GCC 6.2 is being released, adjusting target milestone.
Comment 7 Richard Biener 2016-08-22 08:51:22 UTC
GCC 6.2 is being released, adjusting target milestone.
Comment 8 Richard Biener 2016-08-22 08:52:46 UTC
GCC 6.2 is being released, adjusting target milestone.
Comment 9 Jeffrey A. Law 2016-10-05 19:41:23 UTC
This ought to be fixable in DOM.  Probably not worth backporting to gcc-6 though.
Comment 10 Jeffrey A. Law 2016-10-05 19:47:47 UTC
*** Bug 77647 has been marked as a duplicate of this bug. ***
Comment 11 Jeffrey A. Law 2016-10-10 19:26:26 UTC
So I don't like the pain of trying to fold at each propagation step.  Specifically, the structure of the gimple statement can change, which invalidates the operand cache.  And the canonicalization of operands based on their SSA_NAME_VERSIONs means it's possible to get cycles.  While I've got something that appears to work, I'm not at all happy with it.

So I started looking at a different approach.  Just keep a record of copy propagated objects and if we've already propagated A for B, don't copy propagate B for A in the same statement.  We can do this with a bitmap, but that's a lot of overhead, even when lazily initialized.  I suspect this matters so rarely in practice that a single entry "this was the last thing copy propagated" is sufficient.
Comment 12 Jeffrey A. Law 2016-10-10 20:41:31 UTC
Author: law
Date: Mon Oct 10 20:40:59 2016
New Revision: 240947

URL: https://gcc.gnu.org/viewcvs?rev=240947&root=gcc&view=rev
Log:
        PR tree-optimization/71947
	* tree-ssa-dom.c (cprop_into_stmt): Avoid replacing A with B, then
	B with A within a single statement.

	PR tree-optimization/71947
	* gcc.dg/tree-ssa/pr71947-1.c: New test.
	* gcc.dg/tree-ssa/pr71947-2.c: New test.
	* gcc.dg/tree-ssa/pr71947-3.c: New test.
	* gcc.dg/tree-ssa/pr71947-4.c: New test.
	* gcc.dg/tree-ssa/pr71947-5.c: New test.
	* gcc.dg/tree-ssa/pr71947-6.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr71947-1.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr71947-2.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr71947-3.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr71947-4.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr71947-5.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr71947-6.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-dom.c
Comment 13 Jeffrey A. Law 2016-10-21 20:42:06 UTC
Author: law
Date: Fri Oct 21 20:41:34 2016
New Revision: 241429

URL: https://gcc.gnu.org/viewcvs?rev=241429&root=gcc&view=rev
Log:
	* PR tree-optimization/71947
	* gcc.dg/tree-ssa/pr71947-4.c: Avoid x86 opcode.
	* gcc.dg/tree-ssa/pr71947-5.c: Likewise.
	* gcc.dg/tree-ssa/pr71947-6.c: Make it opt-in rather than opt-out.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr71947-4.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr71947-5.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr71947-6.c
Comment 14 Jakub Jelinek 2016-12-21 10:57:15 UTC
GCC 6.3 is being released, adjusting target milestone.
Comment 15 Richard Biener 2017-07-04 08:47:08 UTC
GCC 6.4 is being released, adjusting target milestone.