[Bug target/69008] gcc emits unneeded memory access when passing trivial structs by value (ARM)

2016-01-14 Thread renlin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69008

Renlin Li  changed:

   What|Removed |Added

 CC||renlin at gcc dot gnu.org

--- Comment #2 from Renlin Li  ---
This relate to the strict alignment for aarch32 target. The structure is
treated as BLKmode and will be stored in the stack first.

However, I believe that this actually can be optimized by DSE pass, which will
forward the value to the ADD operation directly eliminate the store. However,
It seems it's unable to recognize the opportunities here. 

For example the following modified test case:

struct Trivial {
short i1;
short i2;
};

int foo(Trivial t)
{
return t.i1 + t.i2;
}

The expand will emits the following code, which still stores the structure into
stack first. However, DSE can optimized it and remove insn 2.

(insn 2 4 3 2 (set (mem/c:SI (plus:SI (reg/f:SI 105 virtual-stack-vars)
(const_int -4 [0xfffc])) [1  S4 A32])
(reg:SI 0 r0)) test.c:7 -1
 (nil))
(note 3 2 6 2 NOTE_INSN_FUNCTION_BEG)
(insn 6 3 7 2 (set (reg:SI 116)
(sign_extend:SI (mem/c:HI (plus:SI (reg/f:SI 105 virtual-stack-vars)
(const_int -4 [0xfffc])) [2 t.i1+0 S2 A32])))
test.c:8 -1
 (nil))
(insn 7 6 8 2 (set (reg:SI 117)
(sign_extend:SI (mem/c:HI (plus:SI (reg/f:SI 105 virtual-stack-vars)
(const_int -2 [0xfffe])) [2 t.i2+0 S2 A16])))
test.c:8 -1
 (nil))
(insn 8 7 9 2 (set (reg:SI 115)
(plus:SI (reg:SI 116)
(reg:SI 117))) test.c:8 -1
 (nil))


On the other hand, if the original test case is compiled with -mabi=apcs-gnu,
it will produce exactly the same code-gen as clang does.
"-mabi=apcs-gnu" will change the target BIGGEST_ALIGNMENT macro to 32.
In this case, the structure will be treated as scalar DImode. It will no longer
stored on the stack any more. The expand will emit different code from the very
beginning.

(insn 6 3 7 2 (set (reg:SI 114)
(plus:SI (subreg:SI (reg/v:DI 113 [ t ]) 0)
(subreg:SI (reg/v:DI 113 [ t ]) 4))) new.c:8 -1
 (nil))
(insn 7 6 11 2 (set (reg:SI 112 [  ])
(reg:SI 114)) new.c:8 -1
 (nil))
(insn 11 7 12 2 (set (reg/i:SI 0 r0)
(reg:SI 112 [  ])) new.c:9 -1
 (nil))
(insn 12 11 0 2 (use (reg/i:SI 0 r0)) new.c:9 -1
 (nil))

[Bug target/69008] gcc emits unneeded memory access when passing trivial structs by value (ARM)

2015-12-22 Thread ktkachov at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69008

ktkachov at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2015-12-22
 CC||ktkachov at gcc dot gnu.org
 Ever confirmed|0   |1
  Known to fail||4.8.5, 4.9.4, 5.3.1, 6.0

--- Comment #1 from ktkachov at gcc dot gnu.org ---
Confirmed on all versions that I have access to.
The expander emits:
(insn 2 5 3 2 (set (reg:SI 113)
(plus:SI (reg/f:SI 105 virtual-stack-vars)
(const_int -8 [0xfff8]))) missed.c:7 -1
 (nil))
(insn 3 2 4 2 (parallel [
(set (mem/c:SI (reg:SI 113) [1 t+0 S4 A32])
(reg:SI 0 r0))
(set (mem/c:SI (plus:SI (reg:SI 113)
(const_int 4 [0x4])) [1 t+4 S4 A32])
(reg:SI 1 r1))
]) missed.c:7 -1
 (nil))
(note 4 3 7 2 NOTE_INSN_FUNCTION_BEG)
(insn 7 4 8 2 (set (reg:SI 115)
(mem/c:SI (plus:SI (reg/f:SI 105 virtual-stack-vars)
(const_int -8 [0xfff8])) [2 t.i1+0 S4 A32]))
missed.c:8 -1
 (nil))
(insn 8 7 9 2 (set (reg:SI 116)
(mem/c:SI (plus:SI (reg/f:SI 105 virtual-stack-vars)
(const_int -4 [0xfffc])) [2 t.i2+0 S4 A32]))
missed.c:8 -1
 (nil))
(insn 9 8 10 2 (set (reg:SI 114)
(plus:SI (reg:SI 115)
(reg:SI 116))) missed.c:8 -1
 (nil))

[Bug target/69008] gcc emits unneeded memory access when passing trivial structs by value (ARM)

2015-12-21 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69008

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||missed-optimization
 Target||arm*-*-*
  Component|c++ |target
   Severity|normal  |enhancement