From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32558 invoked by alias); 15 Jan 2005 00:22:35 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 31439 invoked by alias); 15 Jan 2005 00:22:05 -0000 Date: Sat, 15 Jan 2005 00:22:00 -0000 Message-ID: <20050115002205.31430.qmail@sourceware.org> From: "dberlin at dberlin dot org" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20050113213834.19431.pinskia@gcc.gnu.org> References: <20050113213834.19431.pinskia@gcc.gnu.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug tree-optimization/19431] missed optimization with ifs and deferencing X-Bugzilla-Reason: CC X-SW-Source: 2005-01/txt/msg01914.txt.bz2 List-Id: ------- Additional Comments From dberlin at gcc dot gnu dot org 2005-01-15 00:22 ------- Subject: Re: New: missed optimization with ifs and deferencing On Thu, 2005-01-13 at 21:38 +0000, pinskia at gcc dot gnu dot org wrote: > I found this while looking into PR 8361 for missed optimization. > The following two programs should produce the same asm: > int f(int k, int i1, int j1) > { > int *f1; > if(k) > f1 = &i1; > else > f1 = &j1; > return *f1; > } The only way you are going to get this to optimize is to make it see we are derefencing a phi whose arguments are all is_gimple_min_invariant, substitute the value in, merge it, and then use the that at the derefence point. This is actually just a special case of noticing that we are really doing *& in both cases, and removing the *& part, while leaving the rest. IE transform it like so Step 0: f (k, i1, j1) { int * f1; int D.1116; : if (k_2 != 0) goto ; else goto ; :; # f1_1 = PHI <&i1(0), &j1(1)>; :; # VUSE ; # VUSE ; D.1116_3 = *f1_1; return D.1116_3; } Step 1 (new blocks added for clarity) f (k, i1, j1) { int * f1; int D.1116; : if (k_2 != 0) goto ; else goto ; :; newtemp_2 = i1; goto L2 newtemp_1 = j1; f1_1 = PHI<&i1(0), &j1(1)> :; # VUSE ; # VUSE ; D.1116_3 = *f1_1; return D.1116_3; } Step 2: f (k, i1, j1) { int * f1; int D.1116; : if (k_2 != 0) goto ; else goto ; :; newtemp_2 = i1; goto L2 newtemp_1 = j1; newphi = PHI :; # VUSE ; # VUSE ; D.1116_3 = *f1_1; return D.1116_3; } Step 3: f (k, i1, j1) { int * f1; int D.1116; : if (k_2 != 0) goto ; else goto ; :; newtemp_2 = i1; goto L2 newtemp_1 = j1; newphi = PHI :; D.1116_3 = newphi; return D.1116_3; } Notice that all i've done is simply match up that the dereference was of a phi node whoes arguments are all &something. In that specific case, we can remove all the addressing operations and the dereference use, and just replace it with the values. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19431