Re: [PATCH] xtensa: Fix for enabling LRA

2023-03-13 Thread Max Filippov via Gcc-patches
Hi Suwa-san,

On Tue, Mar 7, 2023 at 10:04 PM Takayuki 'January June' Suwa
 wrote:
>
> This patch makes LRA well with some exceptions
> (e.g. MI thunk generation due to pretending reload_completed).
>
> gcc/ChangeLog:
>
> * config/xtensa/constraints.md (R, T, U):
> Change define_constraint to define_memory_constraint.
> * config/xtensa/xtensa.cc (xtensa_legitimate_constant_p):
> Add short-circuit path for integer load instructions when
> lra_in_progress.
> * config/xtensa/xtensa.md (movsf):
> Use can_create_pseudo_p() rather reload_in_progress and
> reload_completed.
> ---
>  gcc/config/xtensa/constraints.md | 26 --
>  gcc/config/xtensa/xtensa.cc  |  4 
>  gcc/config/xtensa/xtensa.md  |  2 +-
>  3 files changed, 13 insertions(+), 19 deletions(-)

this change introduces the following build- and runtime regressions
when tested without -mlra:

+FAIL: gcc.c-torture/execute/builtins/sprintf.c execution,  -O1
+FAIL: gcc.c-torture/execute/builtins/sprintf.c execution,  -Og -g
+FAIL: gcc.c-torture/execute/builtins/vsnprintf-chk.c execution,  -O1
+FAIL: gcc.c-torture/execute/builtins/vsprintf-chk.c execution,  -O1
+FAIL: gcc.c-torture/execute/stdarg-1.c   -O2  execution test
+FAIL: gcc.c-torture/execute/stdarg-1.c   -O3 -g  execution test
+FAIL: gcc.c-torture/execute/stdarg-1.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test
+FAIL: gcc.c-torture/execute/strct-stdarg-1.c   -O2  (internal
compiler error: in xtensa_output_integer_literal_parts, at
config/xtensa/xtensa.cc:3201)
+FAIL: gcc.c-torture/execute/strct-stdarg-1.c   -O3
-fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer
-finline-functions  (internal compiler error: in
xtensa_output_integer_literal_parts, at config/xtensa/xtensa.cc:3201)
+FAIL: gcc.c-torture/execute/strct-stdarg-1.c   -O3 -g  (internal
compiler error: in xtensa_output_integer_literal_parts, at
config/xtensa/xtensa.cc:3201)
+FAIL: gcc.c-torture/execute/strct-stdarg-1.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  (internal compiler error:
in xtensa_output_integer_literal_parts, at
config/xtensa/xtensa.cc:3201)
+FAIL: gcc.c-torture/execute/strct-stdarg-1.c   -O2 -flto
-fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error: in
xtensa_output_integer_literal_parts, at config/xtensa/xtensa.cc:3201)
+FAIL: gcc.c-torture/execute/va-arg-pack-1.c   -O2 -flto
-fuse-linker-plugin -fno-fat-lto-objects  execution test
+FAIL: gcc.dg/atomic/c11-atomic-exec-4.c   -O1  execution test
+FAIL: gcc.dg/strcmpopt_6.c execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-14.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-14.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-3.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-3.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-p-14.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-p-14.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test
+FAIL: c-c++-common/torture/builtin-shufflevector-1.c   -O2 -flto
-fuse-linker-plugin -fno-fat-lto-objects  execution test
+FAIL: gcc.dg/torture/vec-cvt-1.c   -O2 -flto -fuse-linker-plugin
-fno-fat-lto-objects  execution test
+FAIL: gcc.dg/tree-ssa/forwprop-39.c (test for excess errors)
+FAIL: gcc.dg/tree-ssa/forwprop-39.c scan-tree-dump-not forwprop1 "COMPLEX_EXPR"
+FAIL: gcc.dg/tree-ssa/forwprop-39.c scan-tree-dump-not optimized
"REALPART_EXPR"
+FAIL: c-c++-common/torture/builtin-arith-overflow-14.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-14.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-3.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-3.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-p-14.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-p-14.c   -O2 -flto
-fno-use-linker-plugin -flto-partition=none  execution test
+FAIL: c-c++-common/torture/builtin-shufflevector-1.c   -O2 -flto
-fuse-linker-plugin -fno-fat-lto-objects  execution test

-- 
Thanks.
-- Max


[PATCH] xtensa: Fix for enabling LRA

2023-03-07 Thread Takayuki 'January June' Suwa via Gcc-patches
This patch makes LRA well with some exceptions
(e.g. MI thunk generation due to pretending reload_completed).

gcc/ChangeLog:

* config/xtensa/constraints.md (R, T, U):
Change define_constraint to define_memory_constraint.
* config/xtensa/xtensa.cc (xtensa_legitimate_constant_p):
Add short-circuit path for integer load instructions when
lra_in_progress.
* config/xtensa/xtensa.md (movsf):
Use can_create_pseudo_p() rather reload_in_progress and
reload_completed.
---
 gcc/config/xtensa/constraints.md | 26 --
 gcc/config/xtensa/xtensa.cc  |  4 
 gcc/config/xtensa/xtensa.md  |  2 +-
 3 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/gcc/config/xtensa/constraints.md b/gcc/config/xtensa/constraints.md
index 53e4d0d8dd1..9b31e162941 100644
--- a/gcc/config/xtensa/constraints.md
+++ b/gcc/config/xtensa/constraints.md
@@ -123,29 +123,19 @@
   (and (match_code "const_int")
   (match_test "! xtensa_split1_finished_p ()"
 
-;; Memory constraints.  Do not use define_memory_constraint here.  Doing so
-;; causes reload to force some constants into the constant pool, but since
-;; the Xtensa constant pool can only be accessed with L32R instructions, it
-;; is always better to just copy a constant into a register.  Instead, use
-;; regular constraints but add a check to allow pseudos during reload.
+;; Memory constraints.
 
-(define_constraint "R"
+(define_memory_constraint "R"
  "Memory that can be accessed with a 4-bit unsigned offset from a register."
- (ior (and (match_code "mem")
-  (match_test "smalloffset_mem_p (op)"))
-  (and (match_code "reg")
-  (match_test "reload_in_progress
-   && REGNO (op) >= FIRST_PSEUDO_REGISTER"
+ (and (match_code "mem")
+  (match_test "smalloffset_mem_p (op)")))
 
-(define_constraint "T"
+(define_memory_constraint "T"
  "Memory in a literal pool (addressable with an L32R instruction)."
  (and (match_code "mem")
   (match_test "!TARGET_CONST16 && constantpool_mem_p (op)")))
 
-(define_constraint "U"
+(define_memory_constraint "U"
  "Memory that is not in a literal pool."
- (ior (and (match_code "mem")
-  (match_test "! constantpool_mem_p (op)"))
-  (and (match_code "reg")
-  (match_test "reload_in_progress
-   && REGNO (op) >= FIRST_PSEUDO_REGISTER"
+ (and (match_code "mem")
+  (match_test "! constantpool_mem_p (op)")))
diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index 7287aa7a258..a500dc2a06e 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -4872,6 +4872,10 @@ xtensa_trampoline_init (rtx m_tramp, tree fndecl, rtx 
chain)
 static bool
 xtensa_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
 {
+  if (lra_in_progress && CONST_INT_P (x))
+return TARGET_AUTO_LITPOOLS || TARGET_CONST16
+  || xtensa_simm12b (INTVAL (x));
+
   return !xtensa_tls_referenced_p (x);
 }
 
diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 3521fa33b47..195515d9427 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -1268,7 +1268,7 @@
   if ((!register_operand (operands[0], SFmode)
&& !register_operand (operands[1], SFmode))
   || (FP_REG_P (xt_true_regnum (operands[0]))
- && !(reload_in_progress | reload_completed)
+ && can_create_pseudo_p ()
  && (constantpool_mem_p (operands[1])
  || CONSTANT_P (operands[1]
 operands[1] = force_reg (SFmode, operands[1]);
-- 
2.30.2