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]

Re: CSE not combining equivalent expressions.


Also this is removed for the case of integers by the CSE pass
IIRC . The problem arises only for the type being a char or a short.

Yes, That is true. With gcc 4.1 one of the 'or's gets eliminated for 'int'. I am putting below two sets of logs. The first just before cse_main and the second just after cse_main has returned but the trivially dead insns have not been deleted yet.

Set 1: Before cse_main

(note 9 6 11 0 [bb 0] NOTE_INSN_BASIC_BLOCK)

(insn 11 9 12 0 (set (reg:SI 1 $c1)
       (const_int 0 [0x0])) 43 {*movsi} (nil)
   (nil))

(call_insn 12 11 13 0 (parallel [
           (set (reg:SI 1 $c1)
               (call (mem:SI (symbol_ref:SI ("gen_T") [flags 0x41]
<function_decl 0xb7d81e00 gen_T>) [0 S4 A32])
                   (const_int 0 [0x0])))
           (use (const_int 0 [0x0]))
           (clobber (reg:SI 31 $link))
       ]) 39 {*call_value_direct} (nil)
   (nil)
   (expr_list:REG_DEP_TRUE (use (reg:SI 1 $c1))
       (nil)))

(insn 13 12 15 0 (set (reg:SI 134 [ D.1214 ])
       (reg:SI 1 $c1)) 43 {*movsi} (nil)
   (nil))

(insn 15 13 16 0 (set (reg:SI 133 [ D.1216 ])
       (ior:SI (reg:SI 134 [ D.1214 ])
           (const_int 1 [0x1]))) 64 {iorsi3} (nil)
   (nil))

(insn 16 15 17 0 (set (reg/f:SI 136)
       (symbol_ref:SI ("a") [flags 0x2] <var_decl 0xb7d8a05c a>)) 43
{*movsi} (nil)
   (nil))

(insn 17 16 19 0 (set (mem/c/i:SI (reg/f:SI 136) [2 a+0 S4 A32])
       (reg:SI 133 [ D.1216 ])) 43 {*movsi} (nil)
   (nil))

<<<Expansion of the if condition>>>>

(note 23 21 25 1 [bb 1] NOTE_INSN_BASIC_BLOCK)

(insn 25 23 26 1 (set (reg/f:SI 139)
       (symbol_ref:SI ("a") [flags 0x2] <var_decl 0xb7d8a05c a>)) 43
{*movsi} (nil)
   (nil))

(insn 26 25 27 1 (set (reg:SI 140)
       (ior:SI (reg:SI 133 [ D.1216 ])
           (const_int 1 [0x1]))) 64 {iorsi3} (nil)
   (nil))

(insn 27 26 29 1 (set (mem/c/i:SI (reg/f:SI 139) [2 a+0 S4 A32])
       (reg:SI 140)) 43 {*movsi} (nil)
   (nil))

(code_label 29 27 30 2 2 ("end") [1 uses])
...... to function end


Set 2: After cse_main (note 9 6 11 0 [bb 0] NOTE_INSN_BASIC_BLOCK)

(insn 11 9 12 0 (set (reg:SI 1 $c1)
       (const_int 0 [0x0])) 43 {*movsi} (nil)
   (nil))

(call_insn 12 11 13 0 (parallel [
           (set (reg:SI 1 $c1)
               (call (mem:SI (symbol_ref:SI ("gen_T") [flags 0x41]
<function_decl 0xb7d81e00 gen_T>) [0 S4 A32])
                   (const_int 0 [0x0])))
           (use (const_int 0 [0x0]))
           (clobber (reg:SI 31 $link))
       ]) 39 {*call_value_direct} (nil)
   (nil)
   (expr_list:REG_DEP_TRUE (use (reg:SI 1 $c1))
       (nil)))

(insn 13 12 15 0 (set (reg:SI 134 [ D.1214 ])
       (reg:SI 1 $c1)) 43 {*movsi} (nil)
   (nil))

(insn 15 13 16 0 (set (reg:SI 133 [ D.1216 ])
       (ior:SI (reg:SI 134 [ D.1214 ])
           (const_int 1 [0x1]))) 64 {iorsi3} (nil)
   (nil))

(insn 16 15 17 0 (set (reg/f:SI 136)
       (symbol_ref:SI ("a") [flags 0x2] <var_decl 0xb7d8a05c a>)) 43
{*movsi} (nil)
   (nil))

(insn 17 16 19 0 (set (mem/c/i:SI (reg/f:SI 136) [2 a+0 S4 A32])
       (reg:SI 133 [ D.1216 ])) 43 {*movsi} (nil)
   (nil))

<<<< Expansion of the If condition >>>>>>

(note 23 21 25 1 [bb 1] NOTE_INSN_BASIC_BLOCK)

(insn 25 23 26 1 (set (reg/f:SI 139)
       (reg/f:SI 136)) 43 {*movsi} (nil)
   (expr_list:REG_EQUAL (symbol_ref:SI ("a") [flags 0x2] <var_decl
0xb7d8a05c a>)
       (nil)))

(insn 26 25 27 1 (set (reg:SI 140)
       (ior:SI (reg:SI 134 [ D.1214 ])
           (const_int 1 [0x1]))) 64 {iorsi3} (nil)
   (nil))

(insn 27 26 29 1 (set (mem/c/i:SI (reg/f:SI 136) [2 a+0 S4 A32])
       (reg:SI 133 [ D.1216 ])) 43 {*movsi} (nil)
   (nil))

(code_label 29 27 30 2 2 ("end") [1 uses])
.... to function end

Therefore as I see it, cse_main has followed the following steps
1) found that the source of the set in insn 26 is equivalent to the
source of the set in insn 15 and replaced the source in insn 26 with
that from insn 15
2) Found the lhs of insn 15 to be equal to that of insn 26 and stored
that instead in insn 27 thus making the result of insn 26 ( reg 140 )
unused ever again ( and insn 26 subsequently gets deleted) .

However for the case of char or short, zero / sign extends are
generated after the 'ior' operations and as a result the source of the
second 'ior' is then not equal to the source of the first 'ior'.


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