[PATCH] xtensa: Fix buffer overflow

2022-06-21 Thread Takayuki 'January June' Suwa via Gcc-patches
Fortify buffer overflow message reported. (see https://github.com/earlephilhower/esp-quick-toolchain/issues/36) gcc/ChangeLog: * config/xtensa/xtensa.md (bswapsi2_internal): Enlarge the buffer that is obviously smaller than the template string given to sprintf(). ---

[PATCH 1/2] xtensa: Apply a few minor fixes

2022-06-19 Thread Takayuki 'January June' Suwa via Gcc-patches
No functional changes. gcc/ChangeLog: * config/xtensa/xtensa.cc (xtensa_emit_move_sequence): Use can_create_pseudo_p(), instead of using individual reload_in_progress and reload_completed. (xtensa_expand_block_set_small_loop): Use xtensa_simm8x256(), the

[PATCH 2/2] xtensa: Fix RTL insn cost estimation about relaxed MOVI instructions

2022-06-19 Thread Takayuki 'January June' Suwa via Gcc-patches
These instructions will all be converted to L32R ones with litpool entries by the assembler. gcc/ChangeLog: * config/xtensa/xtensa.cc (xtensa_is_insn_L32R_p): Consider relaxed MOVI instructions as L32R. --- gcc/config/xtensa/xtensa.cc | 22 ++ 1 file changed,

Re: [PATCH] xtensa: Defer storing integer constants into litpool until reload

2022-06-17 Thread Takayuki 'January June' Suwa via Gcc-patches
erratum: - extern unsigned int value; + extern unsigned short value; On 2022/06/17 22:47, Takayuki 'January June' Suwa via Gcc-patches wrote: > Storing integer constants into litpool in the early stage of compilation > hinders some integer optimizations. In fact, such i

[PATCH] xtensa: Defer storing integer constants into litpool until reload

2022-06-17 Thread Takayuki 'January June' Suwa via Gcc-patches
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

[PATCH v2 2/5] xtensa: Add support for sibling call optimization

2022-06-15 Thread Takayuki 'January June' Suwa via Gcc-patches
On 2022/06/15 5:17, Max Filippov wrote: > Hi Suwa-san, hi! > This change results in a bunch of new regression test failures: > The code generated for e.g. gcc.c-torture/execute/921208-2.c looks like this: oh, PICed... indirect (incl. via function pointer, virtual functions and of course PIC ones

[PATCH 5/5] xtensa: Eliminate [DS]Cmode hard register clobber that is immediately followed by whole overwrite the register

2022-06-13 Thread Takayuki 'January June' Suwa via Gcc-patches
RTL expansion of substitution to [DS]Cmode hard register includes obstructive register clobber. A simplest example: double _Complex test(double _Complex c) { return c; } will be converted to: (set (reg:DF 42 [ c ]) (reg:DF 2 a2)) (set (reg:DF 43 [ c+8 ]) (reg:DF 4 a4))

[PATCH 4/5] xtensa: Eliminate unwanted reg-reg moves during DFmode input reloads

2022-06-13 Thread Takayuki 'January June' Suwa via Gcc-patches
When spilled DFmode registers are reloaded in, once loaded into a pair of SImode regs and then copied from that regs. Such unwanted reg-reg moves seems not to be eliminated at the "cprop_hardreg" stage, despite no problem in output reloads. Luckily it is easy to resolve such inefficiencies, with

[PATCH 2/5] xtensa: Add support for sibling call optimization

2022-06-13 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch introduces support for sibling call optimization, when call0 ABI is in effect. gcc/ChangeLog: * config/xtensa/xtensa-protos.h (xtensa_prepare_expand_call, xtensa_emit_sibcall): New prototypes. (xtensa_expand_epilogue): Add new argument that specifies whether

[PATCH 3/5] xtensa: Add some dedicated patterns that correspond to GIMPLE canonicalizations

2022-06-13 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch offers better RTL representations against straightforward derivations from some tree optimizers' canonicalized forms. - rounding up to even, such as '(x + (x & 1))', is canonicalized to '((x + 1) & -2)', but the former is one instruction less than the latter in Xtensa ISA. - signed

[PATCH 1/5] xtensa: Document new -mextra-l32r-costs= Xtensa-specific option

2022-06-13 Thread Takayuki 'January June' Suwa via Gcc-patches
gcc/ChangeLog: * doc/invoke.texi: Document -mextra-l32r-costs= option. --- gcc/doc/invoke.texi | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index b6c0305f198..2a3c638de40 100644 --- a/gcc/doc/invoke.texi +++

[PATCH v2 1/4] xtensa: Improve shift operations more

2022-06-13 Thread Takayuki 'January June' Suwa via Gcc-patches
Changes from v1: (*shift_per_byte_omit_AND_1): changed to be split as early as possible === This patch introduces funnel shifter utilization, and rearranges existing "per-byte shift" insn patterns. gcc/ChangeLog: * config/xtensa/predicates.md (logical_shift_operator,

[PATCH v2 4/4] xtensa: Optimize bitwise AND operation with some specific forms of constants

2022-06-13 Thread Takayuki 'January June' Suwa via Gcc-patches
On 2022/06/13 12:49, Max Filippov wrote: > Hi Suwa-san, hi! > This change produces a bunch of regression test failures in big-endian > configuration: bad news X( that point is what i was a little worried about... > E.g. for the test gcc.c-torture/execute/struct-ini-2.c > the following assembly

Re: [PATCH 2/4] xtensa: Simplify conditional branch/move insn patterns

2022-06-12 Thread Takayuki 'January June' Suwa via Gcc-patches
On 2022/06/12 16:51, Max Filippov wrote: This patch is whitespace-damaged. Please resend. oh, sorry. reposted as zip in attachment due to avoiding damage.<>

[PATCH 4/4] xtensa: Optimize bitwise AND operation with some specific forms of constants

2022-06-12 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch offers several insn-and-split patterns for bitwise AND with register and constant that cannot fit into a "MOVI Ax, simm12" instruction, but can be represented as: i. 1's least significant N bits and the others 0's (17 <= N <= 31) ii. 1's most significant N bits and the others 0's

[PATCH 3/4] xtensa: Make use of BALL/BNALL instructions

2022-06-12 Thread Takayuki 'January June' Suwa via Gcc-patches
In Xtensa ISA, there is no single machine instruction that calculates unary bitwise negation, but a few similar fused instructions are exist: "BALL Ax, Ay, label" // if ((~Ax & Ay) == 0) goto label; "BNALL Ax, Ay, label" // if ((~Ax & Ay) != 0) goto label; These instructions have never

[PATCH 2/4] xtensa: Simplify conditional branch/move insn patterns

2022-06-12 Thread Takayuki 'January June' Suwa via Gcc-patches
No need to describe the "false side" conditional insn patterns anymore. gcc/ChangeLog: * config/xtensa/xtensa-protos.h (xtensa_emit_branch): Remove the first argument. (xtensa_emit_bit_branch): Remove it because now called only from the output statement of

[PATCH 1/4] xtensa: Improve shift operations more

2022-06-12 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch introduces funnel shifter utilization, and rearranges existing "per-byte shift" insn patterns. gcc/ChangeLog: * config/xtensa/predicates.md (logical_shift_operator, xtensa_shift_per_byte_operator): New predicates. * config/xtensa/xtensa-protos.h

[PATCH v3 4/4] xtensa: Improve constant synthesis for both integer and floating-point

2022-06-11 Thread Takayuki 'January June' Suwa via Gcc-patches
thanks for your report. On 2022/06/11 18:05, Max Filippov wrote: It prints (symbol_ref/f:SI ("*.LC1") [flags 0x2] ) ah, i understand it... that is Pmode (synonym of SImode) of a memory address that points to 'u.f'. thus, the correct handling is to fail the split pattern. ---

Re: [PATCH v2 4/4] xtensa: Improve constant synthesis for both integer and floating-point

2022-06-11 Thread Takayuki 'January June' Suwa via Gcc-patches
On 2022/06/11 16:58, Max Filippov wrote: Hi Suwa-san, hi! this change results in a bunch of ICEs in the tests like this: during RTL pass: split2 gcc/gcc/testsuite/gcc.c-torture/compile/20120727-1.c: In function 'f': gcc/gcc/testsuite/gcc.c-torture/compile/20120727-1.c:13:1: internal compiler

Re: [PATCH 2/4] xtensa: Consider the Loop Option when setmemsi is expanded to small loop

2022-06-10 Thread Takayuki 'January June' Suwa via Gcc-patches
On 2022/06/11 9:12, Max Filippov wrote: Hi Suwa-san, hi! This change results in a bunch of ICEs in tests that look like this: gcc/gcc/testsuite/gcc.c-torture/compile/memtst.c: In function 'main': gcc/gcc/testsuite/gcc.c-torture/compile/memtst.c:28:1: error: unrecognizable insn: (insn 7 6 8 2

[PATCH v2 4/4] xtensa: Improve constant synthesis for both integer and floating-point

2022-06-10 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch revises the previous implementation of constant synthesis. First, changed to use define_split machine description pattern and to run after reload pass, in order not to interfere some optimizations such as the loop invariant motion. Second, not only integer but floating-point is

[PATCH 4/4] xtensa: Improve constant synthesis for both integer and floating-point

2022-06-09 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch revises the previous implementation of constant synthesis. First, changed to use define_split machine description pattern and to run after reload pass, in order not to interfere some optimizations such as the loop invariant motion. Second, not only integer but floating-point is

[PATCH 2/4] xtensa: Consider the Loop Option when setmemsi is expanded to small loop

2022-06-09 Thread Takayuki 'January June' Suwa via Gcc-patches
Now apply to almost any size of aligned block under such circumstances. gcc/ChangeLog: * config/xtensa/xtensa.cc (xtensa_expand_block_set_small_loop): Pass through the block length / loop count conditions if zero-overhead looping is configured and active, ---

[PATCH 3/4] xtensa: Improve instruction cost estimation and suggestion

2022-06-09 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch implements a new target-specific relative RTL insn cost function because of suboptimal cost estimation by default, and fixes several "length" insn attributes (related to the cost estimation). And also introduces a new machine-dependent option "-mextra-l32r-costs=" that tells

[PATCH 1/4] xtensa: Tweak some widen multiplications

2022-06-09 Thread Takayuki 'January June' Suwa via Gcc-patches
umulsidi3 is faster than umuldi3 even if library call, and is also prerequisite for fast constant division by multiplication. gcc/ChangeLog: * config/xtensa/xtensa.md (mulsidi3, umulsidi3): Split into individual signedness, in order to use libcall "__umulsidi3" but not

[PATCH] expr.cc: Optimize if char array initialization consists of all zeros

2022-05-30 Thread Takayuki 'January June' Suwa via Gcc-patches
Hi all, In some targets, initialization code for char array may be split into two parts even if the initialization consists of all zeros: /* example */ extern void foo(char*); void test(void) { char a[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; foo(a); } ;; Xtensa (xtensa-lx106) .LC0:

[PATCH 4/4] xtensa: Add clrsbsi2 insn pattern

2022-05-29 Thread Takayuki 'January June' Suwa via Gcc-patches
> (clrsb:m x) > Represents the number of redundant leading sign bits in x, represented > as an integer of mode m, starting at the most significant bit position. This explanation is just what the NSA instruction (not ever emitted before) calculates in Xtensa ISA. gcc/ChangeLog: *

[PATCH 2/4] xtensa: Make one_cmplsi2 optimizer-friendly

2022-05-29 Thread Takayuki 'January June' Suwa via Gcc-patches
In Xtensa ISA, there is no single machine instruction that calculates unary bitwise negation. But a few optimizers assume that bitwise negation can be done by a single insn. As a result, '((x < 0) ? ~x : x)' cannot be optimized to '(x ^ (x >> 31))' ever before, for example. This patch relaxes

[PATCH 3/4] xtensa: Optimize '(~x & y)' to '((x & y) ^ y)'

2022-05-29 Thread Takayuki 'January June' Suwa via Gcc-patches
In Xtensa ISA, there is no single machine instruction that calculates unary bitwise negation. gcc/ChangeLog: * config/xtensa/xtensa.md (*andsi3_bitcmpl): New insn_and_split pattern. gcc/testsuite/ChangeLog: * gcc.target/xtensa/check_zero_byte.c: New. ---

[PATCH 1/4] xtensa: Implement bswaphi2 insn pattern

2022-05-29 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch adds bswaphi2 insn pattern that is one instruction less than the default expansion. gcc/ChangeLog: * config/xtensa/xtensa.md (bswaphi2): New insn pattern. --- gcc/config/xtensa/xtensa.md | 10 ++ 1 file changed, 10 insertions(+) diff --git

Re: [PATCH v3 4/5] xtensa: Add setmemsi insn pattern

2022-05-27 Thread Takayuki 'January June' Suwa via Gcc-patches
On 2022/05/27 12:00, Takayuki 'January June' Suwa via Gcc-patches wrote: On 2022/05/27 1:57, Max Filippov wrote: is that something that can be addressed in this patch? seems hard to resolve, because the RTL-generation pass passes only 68 bytes in that case: the culprit is here, but i don't

Re: [PATCH v3 4/5] xtensa: Add setmemsi insn pattern

2022-05-26 Thread Takayuki 'January June' Suwa via Gcc-patches
On 2022/05/27 1:57, Max Filippov wrote: is that something that can be addressed in this patch? seems hard to resolve, because the RTL-generation pass passes only 68 bytes in that case: void f(char *p); void g(void) { char c[72] = {0}; f(c); } without this patch, we would

[PATCH v3 4/5] xtensa: Add setmemsi insn pattern

2022-05-23 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch introduces setmemsi insn pattern of two kinds, unrolled loop and small loop, for fixed small length and constant initialization value. gcc/ChangeLog: * gcc/config/xtensa/xtensa-protos.h (xtensa_expand_block_set_unrolled_loop,

[PATCH v2 4/5] xtensa: Add setmemsi insn pattern

2022-05-17 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch introduces setmemsi insn pattern of two kinds, unrolled loop and small loop, for fixed small length and constant initialization value. gcc/ChangeLog: * gcc/config/xtensa/xtensa-protos.h (xtensa_expand_block_set_unrolled_loop,

[PATCH 5/5] xtensa: Improve bswap[sd]i2 insn patterns

2022-05-13 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch makes bswap[sd]i2 better register allocation, and reconstructs bswapsi2 in order to take advantage of GIMPLE manual byte-swapping recognition. gcc/ChangeLog: * gcc/config/xtensa/xtensa.md (bswapsi2): New expansion pattern. (bswapsi2_internal): Revise the template and

[PATCH 4/5] xtensa: Add setmemsi insn pattern

2022-05-13 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch introduces setmemsi insn pattern of two kinds, unrolled loop and small loop, for fixed small length and constant initialization value. gcc/ChangeLog: * gcc/config/xtensa/xtensa-protos.h (xtensa_expand_block_set_unrolled_loop,

[PATCH 3/5] xtensa: Fix instruction counting regarding block move expansion

2022-05-13 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch makes counting the number of instructions of the remainder (modulo 4) part more accurate. gcc/ChangeLog: * gcc/config/xtensa/xtensa.cc (xtensa_expand_block_move): Make instruction counting more accurate, and simplify emitting insns. --- gcc/config/xtensa/xtensa.cc |

[PATCH 2/5] xtensa: Make use of IN_RANGE macro where appropriate

2022-05-13 Thread Takayuki 'January June' Suwa via Gcc-patches
No functional changes. gcc/ChangeLog: * gcc/config/xtensa/constraints.md (M, O): Use the macro. * gcc/config/xtensa/predicates.md (addsubx_operand, extui_fldsz_operand, sext_fldsz_operand): Ditto. * gcc/config/xtensa/xtensa.cc (xtensa_simm8, xtensa_simm8x256,

[PATCH 1/5] xtensa: Simplify EXTUI instruction maskimm validations

2022-05-13 Thread Takayuki 'January June' Suwa via Gcc-patches
No functional changes. gcc/ChangeLog: * gcc/config/xtensa/predicates.md (extui_fldsz_operand): Simplify. * gcc/config/xtensa/xtensa.cc (xtensa_mask_immediate, print_operand): Ditto. --- gcc/config/xtensa/predicates.md | 2 +- gcc/config/xtensa/xtensa.cc | 24

[PATCH 1/2] xtensa: Rename deprecated extv/extzv insn patterns to extvsi/extzvsi

2022-05-06 Thread Takayuki 'January June' Suwa via Gcc-patches
These patterns were deprecated since GCC 4.8. gcc/ChangeLog: * config/xtensa/xtensa.md (extvsi, extvsi_internal, extzvsi, extzvsi_internal): Rename from extv, extv_internal, extzv and extzv_internal, respectively. --- gcc/config/xtensa/xtensa.md | 16 1

[PATCH 2/2] xtensa: Reflect the 32-bit Integer Divide Option

2022-05-06 Thread Takayuki 'January June' Suwa via Gcc-patches
On Espressif's ESP8266 (based on Tensilica LX106, no hardware divider), this patch reduces the size of each: __moddi3() @ libgcc.a : 969 -> 301 (saves 668) __divmoddi4() : -> 426 (saves 685) __udivmoddi4(): 1043 -> 319 (saves 724) in bytes, respectively.

<    1   2