GCC依赖分析不准确

10 views
Skip to first unread message

Jianzhang Peng

unread,
Dec 13, 2009, 9:23:09 PM12/13/09
to hell...@googlegroups.com
Hi,

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))))


--
Jianzhang Peng



--
Jianzhang Peng

Amker.Cheng

unread,
Dec 13, 2009, 9:37:21 PM12/13/09
to hell...@googlegroups.com
2009/12/14 Jianzhang Peng <pengji...@gmail.com>:

> Hi,
>
> 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.
>
这里b[i+1]是不是就应该依赖于a[i]?毕竟gcc无法知道a[i]与b[i+1]是否引用同一块内存,
不知道对数组引用gcc是不是做了好的别名分析。


--
Best Regards.

Jianzhang Peng

unread,
Dec 13, 2009, 10:11:31 PM12/13/09
to hell...@googlegroups.com
在我的代码中,a,b,c的确不同。
在build_intra_loop_deps中有段注释
414       /* If this insn modifies memory, add an edge to all insns that access
415       memory.  */
真是失望啊!


#define N       10240

float a[N];
float b[N];
float c[N];

float  test()
{
        int i,j;
        float x = 0;


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

        }

        return x;
}


2009/12/14 Amker.Cheng <amker...@gmail.com>

--

您收到此邮件是因为您订阅了 Google 网上论坛的“HelloGcc Workshop”论坛。
要向此网上论坛发帖,请发送电子邮件至 hell...@googlegroups.com
要取消订阅此网上论坛,请发送电子邮件至 hellogcc+u...@googlegroups.com
若有更多问题,请通过 http://groups.google.com/group/hellogcc?hl=zh-CN 访问此网上论坛。





--
Jianzhang Peng

Jianzhang Peng

unread,
Dec 13, 2009, 10:14:07 PM12/13/09
to hell...@googlegroups.com
请问GCC有没有可以做得比较好的依赖分析的函数。自己去做依赖分析,别名分析,可能会bug比较多。

谢谢!

2009/12/14 Jianzhang Peng <pengji...@gmail.com>



--
Jianzhang Peng

Amker.Cheng

unread,
Dec 13, 2009, 10:21:45 PM12/13/09
to hell...@googlegroups.com
当前内存别名分析应该比较困难吧,估计也是没有办法,对于例子程序中abc三个数组
只有它们是局部变量才有足够的信息保证它们彼此不会引用同一块内存吧。
好像别名分析有个专门的分支,不知道怎么样。

了解不多,盼大牛出来说法 :(

--
Best Regards.

Eric Fisher

unread,
Dec 13, 2009, 10:47:59 PM12/13/09
to hell...@googlegroups.com
你的gcc版本是多少? 别名分析在GCC 4.5有一些改进,不知道效果如何。

2009/12/14 Amker.Cheng <amker...@gmail.com>:

Jianzhang Peng

unread,
Dec 13, 2009, 10:50:46 PM12/13/09
to hell...@googlegroups.com
我用4,4

2009/12/14 Eric Fisher <joefo...@gmail.com>



--
Jianzhang Peng

Jianzhang Peng

unread,
Dec 13, 2009, 10:59:24 PM12/13/09
to hell...@googlegroups.com
把数组放到函数内部后,就没有问题了

2009/12/14 Jianzhang Peng <pengji...@gmail.com>



--
Jianzhang Peng
Reply all
Reply to author
Forward
0 new messages