Take the following: char Bool_Glob; void f(void) { Bool_Glob = 0; Bool_Glob = 1; } There should be only one store to Bool_Glob in the last tree dump. The corresponding pointer example works correctly: int f(char *Bool_Glob ) { *Bool_Glob = 0; *Bool_Glob = 1; }
Looks like DSE is not following V_MUST_DEF chains (well since really V_MUST_DEF just became chains I would assume this was not like not before). If we use "--param global-var-threshold=0", DSE removes the store.
Subject: Re: DSE is not doing its job for global variables Note that we're only fixing regressions, and I can't see a way to classify this as a regression since the RTL DSE code ought to catch this. This should be marked as postponed until 4.1. This (untested) code ought to do the trick though:
Created attachment 7706 [details] PPP
Yes I know it is regression only time which is why I filed it and marked it as an enhancement but I should note that I found this while looking into a benchmark.
Subject: Re: DSE is not doing its job for global variables On Wed, 2004-12-08 at 18:03 +0000, pinskia at gcc dot gnu dot org wrote: > ------- Additional Comments From pinskia at gcc dot gnu dot org 2004-12-08 18:03 ------- > Yes I know it is regression only time which is why I filed it and marked it as an > enhancement OK. > but I should note that I found this while looking into a benchmark. Were you looking at the final output, or just the output from the SSA optimizers? As I mentioned, we have a DSE that works on the RTL level which ought to have a reasonable chance of catching this. If you get a chance to play with the patch and benchmark it, that would be great. Jeff ps. What benchmark?
(In reply to comment #5) > Subject: Re: DSE is not doing its job for > global variables > > but I should note that I found this while looking into a benchmark. > Were you looking at the final output, or just the output from the SSA > optimizers? As I mentioned, we have a DSE that works on the RTL level > which ought to have a reasonable chance of catching this. Yes the RTL level one catches it. I just filed it because it would help out on memory usage sometimes. > If you get a chance to play with the patch and benchmark it, that would > be great. I will try after I after I benchmark my tree combine pass which looks like it could improve even the compile time speed as it removes some ifs which can be proved to be always true. > ps. What benchmark? dhrystone 2.0 but it might be a modified version as it was designed to run on DOS and I modified it back to run on UNIX.
*** Bug 19130 has been marked as a duplicate of this bug. ***
I'll have a look at Jeff's patch.
Hmpf, does DSE do anything *at* *all*??? Test cases: --------------------------------------- int x; int f1 (int i, int j, int k) { int *p = k ? &i : &j; i = 3; /* Dead store. */ *p = 5; x = j; } int f2 (int l, int m, int n) { int *q = n ? &l : &m; *q = 3; /* Dead store. */ *q = 5; x = m; } --------------------------------------- .optimized dump at -O2: --------------------------------------- ;; Function f1 (f1) Analyzing Edge Insertions. f1 (i, j, k) { int * p; int j.1; int * iftmp.0; <bb 0>: if (k != 0) goto <L4>; else goto <L3>; <L4>:; p = &i; goto <bb 2> (<L2>); <L3>:; p = &j; <L2>:; i = 3; *p = 5; x = j; return; } ;; Function f2 (f2) Analyzing Edge Insertions. f2 (l, m, n) { int * q; int m.3; int * iftmp.2; <bb 0>: if (n != 0) goto <L4>; else goto <L3>; <L4>:; q = &l; goto <bb 2> (<L2>); <L3>:; q = &m; <L2>:; *q = 3; *q = 5; x = m; return; } ---------------------------------------
Subject: Re: DSE is not doing its job for global variables On Thu, 2005-01-13 at 20:38 +0000, steven at gcc dot gnu dot org wrote: > ------- Additional Comments From steven at gcc dot gnu dot org 2005-01-13 20:38 ------- > Hmpf, does DSE do anything *at* *all*??? Yes. foo( int *a) { *a =5; *a = 3; } >From the .dse1 dump: ;; Function foo (foo) Deleted dead store '*a_1 = 5' foo (a) { # BLOCK 0 # PRED: ENTRY [100.0%] (fallthru) *a_1 = 3; return; # SUCC: EXIT [100.0%] } Your tests fail because of the mixture of V_MUST_DEF and V_MAY_DEFs as well as the aliasing for the references through i and *p in the first test and the aliasing between l & m in the second test. I wouldn't expect my change to handle V_MUST_DEF to fix the first test. Feel free to improve :-) Jeff
Created attachment 7987 [details] Patch to make DSE slightly less useless OK, alright, it *does* do something. But definitely not much. With an unpatched tree-ssa-dse.c, 54 dead stores are deleted in dse1 for a C-only x86-64 bootstrap. That is not nothing, but still not worth the effort IMHO. With the attached patch the number goes up to 89 which is still just lame. Jeff, would you oppose to disabling DSE for GCC 4.0? We can implement a proper DSE pass for GCC 4.1, the existing one just does not seem to be a winner in the work/benefit trade-off.
DSE2 also does almost nothing, so I just went ahead and posted a proposal to just disable DSE: http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01183.html
Subject: Re: DSE is not doing its job for global variables On Wed, 2005-01-19 at 01:34 +0000, steven at gcc dot gnu dot org wrote: > ------- Additional Comments From steven at gcc dot gnu dot org 2005-01-19 01:34 ------- > DSE2 also does almost nothing, so I just went ahead and posted a proposal > to just disable DSE: http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01183.html DSE is reasonably fast. How about we just disable one pass rather than disabling it completely. jeff
Steven's experiments seem to demonstrate that the current DSE implementation is not very effective. GCC 4.0 includes RTL optimizations that will catch most if not all of these cases, so it is not as if this will cause GCC to miss some optimizations. If the concern is performance impact, then I think that we should consider adding adding some aggressive optimizations instead of retaining DSE. Even if DSE is very fast, what does GCC gain by fewer iterations of an optimization pass that has almost no benefit?
Subject: Re: DSE is not doing its job for global variables On Wed, 2005-01-19 at 02:44 +0000, dje at gcc dot gnu dot org wrote: > ------- Additional Comments From dje at gcc dot gnu dot org 2005-01-19 02:44 ------- > Steven's experiments seem to demonstrate that the current DSE implementation is > not very effective. GCC 4.0 includes RTL optimizations that will catch most if > not all of these cases, so it is not as if this will cause GCC to miss some > optimizations. Err, umm, wrong. I checked when I wrote the original code and I just double checked tonight. The tree DSE implementation as is stands right now, today, without any improvements, will catch things which the RTL optimizers will miss. And there are some pretty simple things that can be done to make it more effective, though to be really effective we need better alias analysis. The stuff we have now sucks badly. Jeff
Subject: Re: DSE is not doing its job for global variables Do you happen to have numbers on how many dead stores the RTL dead store elimination (in flow.c, right) catches?
Subject: Re: DSE is not doing its job for global variables On Wed, 2005-01-19 at 09:12 +0000, stevenb at novell dot com wrote: > ------- Additional Comments From stevenb at novell dot com 2005-01-19 09:12 ------- > Subject: Re: DSE is not doing its job for global variables > > > Do you happen to have numbers on how many dead stores the RTL dead > store elimination (in flow.c, right) catches? Unfortunately, no. I doubt I've run those numbers since the original RTL DSE code was installed several years ago. jeff
Let's just leave it as-is and revisit for 4.1.
Steven, what about posting your patch for review?
I am no longer interested in working on this DSE pass.
*** Bug 13799 has been marked as a duplicate of this bug. ***
*** Bug 13796 has been marked as a duplicate of this bug. ***
Fixed.