This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gcse fails in this simple case


Hi,

I have the follwing code to test the implemenation of
GCSE optimization in GCC.

0: int a, b;
1:
2: int fun(int ii, int jj)
3: {
4:   int sum1, sum2;
5:   sum1 = sum2 = 0;
6:
7:   if ( ii > jj )
8:     sum1 = a + b;
9:   else
10:   sum2 = a + b;
11:
12:  return sum1+sum2;
13: }

However, GCC cannot find the common subexpression
at Line 8 and 10. From the *.gcse debug dump,
I found GCC consider the expression a+b as two different
expressions at RTL level. The following RTL codes
are from *.gcse dump:


insn 22 57 24 (set (reg:SI 63)
        (mem/f:SI (symbol_ref:SI ("a")) [2 a+0 S4 A32])) 45 {*movsi_1}
...

(insn 24 22 26 (set (reg:SI 64)
        (mem/f:SI (symbol_ref:SI ("b")) [2 b+0 S4 A32])) 45 {*movsi_1} ...

(insn 26 24 27 (parallel[               <= a+b at Line 8
            (set (reg/v:SI 61)
                (plus:SI (reg:SI 63)
                    (reg:SI 64)))
            (clobber (reg:CC 17 flags))
        ] ) 207 {*addsi_1} (nil)
    (nil))


...
(insn 32 58 34 (set (reg:SI 65)
        (mem/f:SI (symbol_ref:SI ("a")) [2 a+0 S4 A32])) 45 {*movsi_1}
...
(insn 34 32 36 (set (reg:SI 66)
        (mem/f:SI (symbol_ref:SI ("b")) [2 b+0 S4 A32])) 45 {*movsi_1}
....

(insn 36 34 37 (parallel[            <= a + b at Line 10
            (set (reg/v:SI 62)
                (plus:SI (reg:SI 65)
                    (reg:SI 66)))
            (clobber (reg:CC 17 flags))
        ] ) 207 {*addsi_1} (nil)
    (nil))

From the above codes, we see gcse fails to eliminate
the common loads of "a" and "b", and then fails to eliminate "a+b".


I think it is a bug, or I miss something.

My GCC compiler:
> gcc -v
> Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.2/specs
> Configured with: ../gcc/configure --disable-libgcj
> Thread model: posix
> gcc version 3.2


Qiong








Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]