On Fri, Jun 17, 2022 at 6:48 AM Takayuki 'January June' Suwa
<jjsuwa_sys3...@yahoo.co.jp> wrote:
>
> Storing integer constants into litpool in the early stage of compilation
> hinders some integer optimizations.  In fact, such integer constants are
> not subject to the constant folding process.
>
> For example:
>
>     extern unsigned int value;
>     extern void foo(void);
>     void test(void) {
>       if (value == 30001)
>         foo();
>     }
>
>         .literal_position
>         .literal .LC0, value
>         .literal .LC1, 30001
>     test:
>         l32r    a3, .LC0
>         l32r    a2, .LC1
>         l16ui   a3, a3, 0
>         extui   a2, a2, 0, 16  // runtime zero-extension despite constant
>         bne     a3, a2, .L1
>         j.l     foo, a9
>     .L1:
>         ret.n
>
> This patch defers the placement of integer constants into litpool until
> the start of reload:
>
>         .literal_position
>         .literal .LC0, value
>         .literal .LC1, 30001
>     test:
>         l32r    a3, .LC0
>         l32r    a2, .LC1
>         l16ui   a3, a3, 0
>         bne     a3, a2, .L1
>         j.l     foo, a9
>     .L1:
>         ret.n
>
> gcc/ChangeLog:
>
>         * config/xtensa/constraints.md (Y):
>         Change to include integer constants until reload begins.
>         * config/xtensa/predicates.md (move_operand): Ditto.
>         * config/xtensa/xtensa.cc (xtensa_emit_move_sequence):
>         Change to allow storing integer constants into litpool only after
>         reload begins.
> ---
>  gcc/config/xtensa/constraints.md | 6 ++++--
>  gcc/config/xtensa/predicates.md  | 5 +++--
>  gcc/config/xtensa/xtensa.cc      | 3 ++-
>  3 files changed, 9 insertions(+), 5 deletions(-)

Regtested for target=xtensa-linux-uclibc, no new regressions.
Folded in the description correction and committed to master.

-- 
Thanks.
-- Max

Reply via email to