Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc: xtensa: Backport patches from upstream/master (v3) #50

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 184 additions & 0 deletions patches/gcc10.1/gcc-xtensa-0078-fix-PR-target-108919.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
From 15990e92b92f65aa5951d1f53d39d15cbde6c0cd Mon Sep 17 00:00:00 2001
From: Max Filippov <[email protected]>
Date: Wed, 22 Feb 2023 14:17:11 -0800
Subject: [PATCH] gcc: xtensa: fix PR target/108919

gcc/
PR target/108919

* config/xtensa/xtensa-protos.h
(xtensa_prepare_expand_call): Rename to xtensa_expand_call.
* config/xtensa/xtensa.c (xtensa_prepare_expand_call): Rename
to xtensa_expand_call.
(xtensa_expand_call): Emit the call and add a clobber expression
for the static chain to it in case of windowed ABI.
* config/xtensa/xtensa.md (call, call_value, sibcall)
(sibcall_value): Call xtensa_expand_call and complete expansion
right after that call.

gcc/testsuite/
* gcc.target/xtensa/pr108919.c: New test.
---
gcc/config/xtensa/xtensa-protos.h | 2 +-
gcc/config/xtensa/xtensa.c | 25 +++++++++++-
gcc/config/xtensa/xtensa.md | 12 ++++--
gcc/testsuite/gcc.target/xtensa/pr108919.c | 46 ++++++++++++++++++++++
4 files changed, 79 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/xtensa/pr108919.c

diff --git a/gcc/config/xtensa/xtensa-protos.h b/gcc/config/xtensa/xtensa-protos.h
index 39d5a5825..74a5d93a0 100644
--- a/gcc/config/xtensa/xtensa-protos.h
+++ b/gcc/config/xtensa/xtensa-protos.h
@@ -53,7 +53,7 @@ extern void xtensa_expand_atomic (enum rtx_code, rtx, rtx, rtx, bool);
extern void xtensa_emit_loop_end (rtx_insn *, rtx *);
extern char *xtensa_emit_branch (bool, rtx *);
extern char *xtensa_emit_movcc (bool, bool, bool, rtx *);
-extern void xtensa_prepare_expand_call (int, rtx *);
+extern void xtensa_expand_call (int, rtx *);
extern char *xtensa_emit_call (int, rtx *);
extern char *xtensa_emit_sibcall (int, rtx *);
extern bool xtensa_tls_referenced_p (rtx);
diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
index 6aea625d9..1e0820d4f 100644
--- a/gcc/config/xtensa/xtensa.c
+++ b/gcc/config/xtensa/xtensa.c
@@ -2173,8 +2173,10 @@ xtensa_emit_movcc (bool inverted, bool isfp, bool isbool, rtx *operands)


void
-xtensa_prepare_expand_call (int callop, rtx *operands)
+xtensa_expand_call (int callop, rtx *operands)
{
+ rtx call;
+ rtx_insn *call_insn;
rtx addr = XEXP (operands[callop], 0);

if (flag_pic && SYMBOL_REF_P (addr)
@@ -2192,6 +2194,27 @@ xtensa_prepare_expand_call (int callop, rtx *operands)
Pmode);
XEXP (operands[callop], 0) = reg;
}
+
+ call = gen_rtx_CALL (VOIDmode, operands[callop], operands[callop + 1]);
+
+ if (callop)
+ call = gen_rtx_SET (operands[0], call);
+
+ call_insn = emit_call_insn (call);
+
+ if (TARGET_WINDOWED_ABI)
+ {
+ /*
+ * Windowed xtensa ABI specifies that static chain pointer is passed
+ * in memory below the caller's stack pointer, which means that the
+ * callee may clobber it if it's a non-leaf function.
+ * Add the clobber expression for the static chain to the function call
+ * expression list so that it is not assumed to be live across the call.
+ */
+ rtx clob = gen_rtx_CLOBBER (Pmode, xtensa_static_chain (NULL, false));
+ CALL_INSN_FUNCTION_USAGE (call_insn) =
+ gen_rtx_EXPR_LIST (Pmode, clob, CALL_INSN_FUNCTION_USAGE (call_insn));
+ }
}


diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 628b27b32..30e4022ca 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -2338,7 +2338,8 @@
(match_operand 1 "" ""))]
""
{
- xtensa_prepare_expand_call (0, operands);
+ xtensa_expand_call (0, operands);
+ DONE;
})

(define_insn "call_internal"
@@ -2358,7 +2359,8 @@
(match_operand 2 "" "")))]
""
{
- xtensa_prepare_expand_call (1, operands);
+ xtensa_expand_call (1, operands);
+ DONE;
})

(define_insn "call_value_internal"
@@ -2378,7 +2380,8 @@
(match_operand 1 "" ""))]
"!TARGET_WINDOWED_ABI"
{
- xtensa_prepare_expand_call (0, operands);
+ xtensa_expand_call (0, operands);
+ DONE;
})

(define_insn "sibcall_internal"
@@ -2398,7 +2401,8 @@
(match_operand 2 "" "")))]
"!TARGET_WINDOWED_ABI"
{
- xtensa_prepare_expand_call (1, operands);
+ xtensa_expand_call (1, operands);
+ DONE;
})

(define_insn "sibcall_value_internal"
diff --git a/gcc/testsuite/gcc.target/xtensa/pr108919.c b/gcc/testsuite/gcc.target/xtensa/pr108919.c
new file mode 100644
index 000000000..300b6fd10
--- /dev/null
+++ b/gcc/testsuite/gcc.target/xtensa/pr108919.c
@@ -0,0 +1,46 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+
+#ifdef __XTENSA_CALL0_ABI__
+void __xtensa_libgcc_window_spill (void)
+{
+}
+#else
+void __xtensa_libgcc_window_spill (void);
+#endif
+
+__attribute__((noinline)) void h (void)
+{
+ __xtensa_libgcc_window_spill ();
+}
+
+int f (int u, int v)
+{
+ int a = u;
+ int s;
+
+ __attribute__((noinline,pure)) int nested1 (int b)
+ {
+ h();
+ return a + b;
+ }
+
+ __attribute__((noinline,pure)) int nested2 (int b)
+ {
+ h();
+ return a - b;
+ }
+
+ s = nested1 (v);
+ s += nested2 (v);
+ return s;
+}
+
+int main (void)
+{
+ int u = 0x12345678;
+ int v = 1;
+
+ return f (u, v) == 2 * u ? 0 : 1;
+}
--
2.30.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
From e0a5a834dc034c239ae7f319d0287fb24db13744 Mon Sep 17 00:00:00 2001
From: Takayuki 'January June' Suwa <[email protected]>
Date: Mon, 27 Feb 2023 02:27:42 +0900
Subject: [PATCH] xtensa: Make use of CLAMPS instruction if configured

This patch introduces the use of CLAMPS instruction when the instruction
is configured.

/* example */
int test(int a) {
if (a < -512)
return -512;
if (a > 511)
return 511;
return a;
}

;; prereq: TARGET_CLAMPS
test:
clamps a2, a2, 9
ret.n

gcc/ChangeLog:

* config/xtensa/xtensa-protos.h (xtensa_match_CLAMPS_imms_p):
New prototype.
* config/xtensa/xtensa.c (xtensa_match_CLAMPS_imms_p):
New function.
* config/xtensa/xtensa.h (TARGET_CLAMPS): New macro definition.
* config/xtensa/xtensa.md (*xtensa_clamps): New insn pattern.
---
gcc/config/xtensa/xtensa-protos.h | 1 +
gcc/config/xtensa/xtensa.c | 13 +++++++++++
gcc/config/xtensa/xtensa.h | 1 +
gcc/config/xtensa/xtensa.md | 37 +++++++++++++++++++++++++++++++
4 files changed, 52 insertions(+)

diff --git a/gcc/config/xtensa/xtensa-protos.h b/gcc/config/xtensa/xtensa-protos.h
index 74a5d93a0..59e5cd1bb 100644
--- a/gcc/config/xtensa/xtensa-protos.h
+++ b/gcc/config/xtensa/xtensa-protos.h
@@ -60,6 +60,7 @@ extern bool xtensa_tls_referenced_p (rtx);
extern enum rtx_code xtensa_shlrd_which_direction (rtx, rtx);
extern bool xtensa_split1_finished_p (void);
extern void xtensa_split_DI_reg_imm (rtx *);
+extern bool xtensa_match_CLAMPS_imms_p (rtx, rtx);

#ifdef TREE_CODE
extern void init_cumulative_args (CUMULATIVE_ARGS *, int);
diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
index 1e0820d4f..a62665d6b 100644
--- a/gcc/config/xtensa/xtensa.c
+++ b/gcc/config/xtensa/xtensa.c
@@ -2602,6 +2602,19 @@ xtensa_emit_add_imm (rtx dst, rtx src, HOST_WIDE_INT imm, rtx scratch,
}


+/* Return true if the constants used in the application of smin() following
+ smax() meet the specifications of the CLAMPS machine instruction. */
+bool
+xtensa_match_CLAMPS_imms_p (rtx cst_max, rtx cst_min)
+{
+ int max, min;
+
+ return IN_RANGE (max = exact_log2 (-INTVAL (cst_max)), 7, 22)
+ && IN_RANGE (min = exact_log2 (INTVAL (cst_min) + 1), 7, 22)
+ && max == min;
+}
+
+
/* Implement TARGET_CANNOT_FORCE_CONST_MEM. */

static bool
diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
index ef7f9e5d5..19d35f20a 100644
--- a/gcc/config/xtensa/xtensa.h
+++ b/gcc/config/xtensa/xtensa.h
@@ -50,6 +50,7 @@ along with GCC; see the file COPYING3. If not see
#define TARGET_NSA XCHAL_HAVE_NSA
#define TARGET_MINMAX XCHAL_HAVE_MINMAX
#define TARGET_SEXT XCHAL_HAVE_SEXT
+#define TARGET_CLAMPS XCHAL_HAVE_CLAMPS
#define TARGET_BOOLEANS XCHAL_HAVE_BOOLEANS
#define TARGET_HARD_FLOAT XCHAL_HAVE_FP
#define TARGET_HARD_FLOAT_DIV XCHAL_HAVE_FP_DIV
diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 30e4022ca..8fd3e006a 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -446,6 +446,43 @@
(set_attr "mode" "SI")
(set_attr "length" "3")])

+
+;; Signed clamp.
+
+(define_insn_and_split "*xtensa_clamps"
+ [(set (match_operand:SI 0 "register_operand" "=a")
+ (smax:SI (smin:SI (match_operand:SI 1 "register_operand" "r")
+ (match_operand:SI 2 "const_int_operand" "i"))
+ (match_operand:SI 3 "const_int_operand" "i")))]
+ "TARGET_CLAMPS
+ && xtensa_match_CLAMPS_imms_p (operands[3], operands[2])"
+ "#"
+ "&& 1"
+ [(set (match_dup 0)
+ (smin:SI (smax:SI (match_dup 1)
+ (match_dup 3))
+ (match_dup 2)))]
+ ""
+ [(set_attr "type" "arith")
+ (set_attr "mode" "SI")
+ (set_attr "length" "3")])
+
+(define_insn "*xtensa_clamps"
+ [(set (match_operand:SI 0 "register_operand" "=a")
+ (smin:SI (smax:SI (match_operand:SI 1 "register_operand" "r")
+ (match_operand:SI 2 "const_int_operand" "i"))
+ (match_operand:SI 3 "const_int_operand" "i")))]
+ "TARGET_CLAMPS
+ && xtensa_match_CLAMPS_imms_p (operands[2], operands[3])"
+{
+ static char result[64];
+ sprintf (result, "clamps\t%%0, %%1, %d", floor_log2 (-INTVAL (operands[2])));
+ return result;
+}
+ [(set_attr "type" "arith")
+ (set_attr "mode" "SI")
+ (set_attr "length" "3")])
+

;; Count redundant leading sign bits and leading/trailing zeros,
;; and find first bit.
--
2.30.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From f90cf6b4d8328a771cff1db3078ab2062cf95085 Mon Sep 17 00:00:00 2001
From: Takayuki 'January June' Suwa <[email protected]>
Date: Sun, 12 Mar 2023 23:14:13 +0900
Subject: [PATCH] xtensa: Remove REG_OK_STRICT and its derivatives

Because GO_IF_LEGITIMATE_ADDRESS was deprecated a long time ago
(see commit c6c3dba931548987c78719180e30ebc863404b89).

gcc/ChangeLog:

* config/xtensa/xtensa.h (REG_OK_STRICT, REG_OK_FOR_INDEX_P,
REG_OK_FOR_BASE_P): Remove.
---
gcc/config/xtensa/xtensa.h | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
index 19d35f20a..fb06b6141 100644
--- a/gcc/config/xtensa/xtensa.h
+++ b/gcc/config/xtensa/xtensa.h
@@ -591,19 +591,10 @@ typedef struct xtensa_args
/* C expressions that are nonzero if X (assumed to be a `reg' RTX) is
valid for use as a base or index register. */

-#ifdef REG_OK_STRICT
-#define REG_OK_STRICT_FLAG 1
-#else
-#define REG_OK_STRICT_FLAG 0
-#endif
-
#define BASE_REG_P(X, STRICT) \
- ((!(STRICT) && REGNO (X) >= FIRST_PSEUDO_REGISTER) \
+ ((!(STRICT) && ! HARD_REGISTER_P (X)) \
|| REGNO_OK_FOR_BASE_P (REGNO (X)))

-#define REG_OK_FOR_INDEX_P(X) 0
-#define REG_OK_FOR_BASE_P(X) BASE_REG_P (X, REG_OK_STRICT_FLAG)
-
/* Maximum number of registers that can appear in a valid memory address. */
#define MAX_REGS_PER_ADDRESS 1

--
2.30.2

Loading