Bug 42617 - TARGET_MEM_REF and plain INDIRECT_REFs are not handled by the RTL oracle
TARGET_MEM_REF and plain INDIRECT_REFs are not handled by the RTL oracle
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: rtl-optimization
4.5.0
: P3 enhancement
: 4.6.0
Assigned To: Richard Biener
: alias, missed-optimization
: 22031 (view as bug list)
Depends on:
Blocks: 4.6
  Show dependency treegraph
 
Reported: 2010-01-04 22:58 UTC by Matt Hargett
Modified: 2010-04-07 12:15 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-01-19 16:29:50


Attachments
tentative fix (3.29 KB, patch)
2010-01-19 17:02 UTC, Richard Biener
Details | Diff
patch #0 (1.84 KB, patch)
2010-01-22 14:06 UTC, Richard Biener
Details | Diff
patch #1 (2.66 KB, patch)
2010-01-22 14:07 UTC, Richard Biener
Details | Diff
patch #2 (1.21 KB, patch)
2010-01-22 15:21 UTC, Richard Biener
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Hargett 2010-01-04 22:58:53 UTC
http://gcc.gnu.org/ml/gcc/2009-12/msg00169.html

From: Jianzhang Peng <jianzhangpeng at gmail dot com>

I unroll the following code one times in a gimpile pass.

for(i=0; i< N ; i++)
  a[i] = b[i] + c[i];

And then I create the loops's ddg using build_intra_loop_deps ( ) in
an RTL pass;
I found the data dependence information:  insn 54 TRUE_DEPENDENCE insn 53.

insn 50  (set (reg:SF 243)  (mem/s:SF (reg:SI 236 [ ivtmp.46 ])     //
reg243 <-b[i]

insn 51 (set (reg:SF 244)   (mem/s:SF (reg:SI 235 [ ivtmp.49 ])     //
reg244 <-c[i]
insn 52 (set (reg:SF 245)
             (plus:SF (reg:SF 243)  (reg:SF 244)))
//reg245 <- reg243 + reg244

insn 53 (set (mem/s:SF (reg:SI 234 [ ivtmp.51 ])  (reg:SF 245))
//reg245->a[i]

insn 54 (set (reg:SF 246)
// reg246 <-b[i+1]
              (mem/s:SF (plus:SI (reg:SI 236 [ ivtmp.46 ])
                                  (const_int 4 [0x4]))

insn 55 (set (reg:SF 247)
             (mem/s:SF (plus:SI (reg:SI 235 [ ivtmp.49 ])
// reg247 <- c[i+ 1]
                        (const_int 4 [0x4]))

insn 56 (set (reg:SF 248)
//reg248 <- reg246 + reg247
              (plus:SF (reg:SF 246)
                       (reg:SF 247)))

insn 57 (set (mem/s:SF (plus:SI (reg:SI 234 [ ivtmp.51 ])
// reg248 -> a[i + 1]
                                 (const_int 4 [0x4])) [2 a S4 A32])
              (reg:SF 248))

...
===========================

(insn 50 49 51 3 loop.c:14 (set (reg:SF 243)
        (mem/s:SF (reg:SI 236 [ ivtmp.46 ]) [2 b S4 A32])) 320
{*movsf_hardfloat} (nil))

(insn 51 50 52 3 loop.c:14 (set (reg:SF 244)
        (mem/s:SF (reg:SI 235 [ ivtmp.49 ]) [2 c S4 A32])) 320
{*movsf_hardfloat} (nil))

(insn 52 51 53 3 loop.c:14 (set (reg:SF 245)
        (plus:SF (reg:SF 243)
            (reg:SF 244))) 7 {addsf3} (expr_list:REG_DEAD (reg:SF 244)
        (expr_list:REG_DEAD (reg:SF 243)
            (nil))))

(insn 53 52 54 3 loop.c:14 (set (mem/s:SF (reg:SI 234 [ ivtmp.51 ]) [2
a S4 A32])
        (reg:SF 245)) 320 {*movsf_hardfloat} (expr_list:REG_DEAD (reg:SF 245)
        (nil)))

(insn 54 53 55 3 loop.c:14 (set (reg:SF 246)
        (mem/s:SF (plus:SI (reg:SI 236 [ ivtmp.46 ])
                (const_int 4 [0x4])) [2 b S4 A32])) 320
{*movsf_hardfloat} (nil))

(insn 55 54 56 3 loop.c:14 (set (reg:SF 247)
        (mem/s:SF (plus:SI (reg:SI 235 [ ivtmp.49 ])
                (const_int 4 [0x4])) [2 c S4 A32])) 320
{*movsf_hardfloat} (nil))

(insn 56 55 57 3 loop.c:14 (set (reg:SF 248)
        (plus:SF (reg:SF 246)
            (reg:SF 247))) 7 {addsf3} (expr_list:REG_DEAD (reg:SF 247)
        (expr_list:REG_DEAD (reg:SF 246)
            (nil))))

(insn 57 56 58 3 loop.c:14 (set (mem/s:SF (plus:SI (reg:SI 234 [ ivtmp.51 ])
                (const_int 4 [0x4])) [2 a S4 A32])
        (reg:SF 248)) 320 {*movsf_hardfloat} (expr_list:REG_DEAD (reg:SF 248)
        (nil)))
(insn 58 57 61 3 loop.c:7 (set (reg/v:SI 241 [ i ])
        (plus:SI (reg/v:SI 241 [ i ])
            (const_int 2 [0x2]))) 10 {*addsi3} (nil))

(insn 61 58 62 3 loop.c:7 (set (reg:SI 240 [ ivtmp.29 ])
        (minus:SI (reg:SI 258)
            (reg/v:SI 241 [ i ]))) 23 {subsi3} (expr_list:REG_EQUAL
(minus:SI (const_int 10240 [0x2800])
            (reg/v:SI 241 [ i ]))
        (nil)))


(insn 62 61 63 3 loop.c:7 (set (reg:SI 236 [ ivtmp.46 ])
        (plus:SI (reg:SI 236 [ ivtmp.46 ])
            (const_int 8 [0x8]))) 10 {*addsi3} (nil))

(insn 63 62 64 3 loop.c:7 (set (reg:SI 235 [ ivtmp.49 ])
        (plus:SI (reg:SI 235 [ ivtmp.49 ])
            (const_int 8 [0x8]))) 10 {*addsi3} (nil))

(insn 64 63 67 3 loop.c:7 (set (reg:SI 234 [ ivtmp.51 ])
        (plus:SI (reg:SI 234 [ ivtmp.51 ])
            (const_int 8 [0x8]))) 10 {*addsi3} (nil))

(jump_insn 67 64 68 3 loop.c:7 (set (pc)
        (if_then_else (ne (reg/v:SI 241 [ i ])
                (reg:SI 259))
            (label_ref:SI 116)
            (pc))) 415 {*branch_equalitysi} (expr_list:REG_EQUAL
(if_then_else (ne (reg/v:SI 241 [ i ])
                (const_int 10238 [0x27fe]))
            (label_ref:SI 116)
            (pc))
        (expr_list:REG_BR_PROB (const_int 9800 [0x2648])
            (nil))))
Comment 1 Richard Biener 2010-01-04 23:25:08 UTC
See http://gcc.gnu.org/ml/gcc-patches/2009-11/msg00463.html for a half-way working
patch.  Somebody needs to dive into var-tracking.c and fix the fallout.
Comment 2 Richard Biener 2010-01-19 16:29:50 UTC
Mine anyway.
Comment 3 Richard Biener 2010-01-19 17:02:11 UTC
Created attachment 19658 [details]
tentative fix

Patch for testing, should work for all cases (fingers crossing).
Comment 4 Richard Biener 2010-01-22 14:06:12 UTC
Created attachment 19691 [details]
patch #0

Fix INDIRECT_REFs.
Comment 5 Richard Biener 2010-01-22 14:07:21 UTC
Created attachment 19692 [details]
patch #1

Don't throw away points-to information needlessly.

Remaining: expand TARGET_MEM_REFs in a more meaningful way.
Comment 6 Richard Biener 2010-01-22 15:21:14 UTC
Created attachment 19694 [details]
patch #2

Fix for expanding TARGET_MEM_REFs.

The patch series is queued for early GCC 4.6 because of its side-effects to
the C++ standard library, see PR42834 and PR42832.
Comment 7 Richard Biener 2010-01-22 15:24:10 UTC
With these patches I get for

void foo(int * __restrict__ a, int * __restrict__ b, int * __restrict__ c,
         int N)
{
  int i;
  for (i = 0; i < N; ++i)
    a[i] = b[i] + c[i];
}

and -O2 -funroll-all-loops all stores scheduled to the bottom of the loop
and all adds to the top of the loop.
Comment 8 Steven Bosscher 2010-02-08 18:45:01 UTC
FWIW, bootstrap+regtest succeeds on ia64-unknown-linux-gnu with the patch set applied.
Comment 9 Richard Biener 2010-04-07 10:13:42 UTC
Subject: Bug 42617

Author: rguenth
Date: Wed Apr  7 10:13:25 2010
New Revision: 158045

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158045
Log:
2010-04-07  Richard Guenther  <rguenther@suse.de>

	PR middle-end/42617
	* emit-rtl.c (set_mem_attributes_minus_bitpos): Do not
	discard plain indirect references.
	* fold-const.c (operand_equal_p): Guard against NULL_TREE
	type.
	* tree.c (tree_nop_conversion): Likewise.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/emit-rtl.c
    trunk/gcc/fold-const.c
    trunk/gcc/tree.c

Comment 10 Richard Biener 2010-04-07 10:14:29 UTC
Subject: Bug 42617

Author: rguenth
Date: Wed Apr  7 10:14:17 2010
New Revision: 158046

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158046
Log:
2010-04-07  Richard Guenther  <rguenther@suse.de>

	PR middle-end/42617
	* alias.c (ao_ref_from_mem): Without MEM_OFFSET or MEM_SIZE
	preserve points-to related information.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/alias.c

Comment 11 Richard Biener 2010-04-07 10:15:22 UTC
Subject: Bug 42617

Author: rguenth
Date: Wed Apr  7 10:15:05 2010
New Revision: 158048

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158048
Log:
2010-04-07  Richard Guenther  <rguenther@suse.de>

	PR middle-end/42617
	* expr.c (expand_expr_real_1): For TARGET_MEM_REFs with
	pointer bases build simple mem attributes to retain
	points-to information.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/expr.c

Comment 12 Richard Biener 2010-04-07 10:16:17 UTC
Fixed.
Comment 13 Richard Biener 2010-04-07 12:15:46 UTC
*** Bug 22031 has been marked as a duplicate of this bug. ***