xtensa: Simplify the definition of REGNO_OK_FOR_BASE_P() and avoid calling it directly
Commit Message
In recent gcc versions, REGNO_OK_FOR_BASE_P() is not called directly, but
rather via regno_ok_for_base_p() which is a wrapper in gcc/addresses.h.
The wrapper obtains a hard register number from pseudo via reg_renumber
array, so REGNO_OK_FOR_BASE_P() does not need to take this into
consideration.
On the other hand, since there is only one use of REGNO_OK_FOR_BASE_P()
in the target-specific code, it would make more sense to simplify the
definition of REGNO_OK_FOR_BASE_P() and replace its call with that of
regno_ok_for_base_p().
gcc/ChangeLog:
* config/xtensa/xtensa.cc (#include):
Add "addresses.h".
* config/xtensa/xtensa.h (REGNO_OK_FOR_BASE_P):
Simplify to just a call to GP_REG_P().
(BASE_REG_P): Replace REGNO_OK_FOR_BASE_P() with the equivalent
call to regno_ok_for_base_p().
---
gcc/config/xtensa/xtensa.cc | 1 +
gcc/config/xtensa/xtensa.h | 6 +++---
2 files changed, 4 insertions(+), 3 deletions(-)
Comments
On Mon, Sep 15, 2025 at 5:42 PM Takayuki 'January June' Suwa
<jjsuwa_sys3175@yahoo.co.jp> wrote:
>
> In recent gcc versions, REGNO_OK_FOR_BASE_P() is not called directly, but
> rather via regno_ok_for_base_p() which is a wrapper in gcc/addresses.h.
> The wrapper obtains a hard register number from pseudo via reg_renumber
> array, so REGNO_OK_FOR_BASE_P() does not need to take this into
> consideration.
>
> On the other hand, since there is only one use of REGNO_OK_FOR_BASE_P()
> in the target-specific code, it would make more sense to simplify the
> definition of REGNO_OK_FOR_BASE_P() and replace its call with that of
> regno_ok_for_base_p().
>
> gcc/ChangeLog:
>
> * config/xtensa/xtensa.cc (#include):
> Add "addresses.h".
> * config/xtensa/xtensa.h (REGNO_OK_FOR_BASE_P):
> Simplify to just a call to GP_REG_P().
> (BASE_REG_P): Replace REGNO_OK_FOR_BASE_P() with the equivalent
> call to regno_ok_for_base_p().
> ---
> gcc/config/xtensa/xtensa.cc | 1 +
> gcc/config/xtensa/xtensa.h | 6 +++---
> 2 files changed, 4 insertions(+), 3 deletions(-)
Regtested for target=xtensa-linux-uclibc, no new regressions.
Committed to master.
@@ -41,6 +41,7 @@ along with GCC; see the file COPYING3. If not see
#include "diagnostic-core.h"
#include "cfgrtl.h"
#include "output.h"
+#include "addresses.h"
#include "fold-const.h"
#include "stor-layout.h"
#include "calls.h"
@@ -592,15 +592,15 @@ typedef struct xtensa_args
for use as a base or index register in operand addresses. */
#define REGNO_OK_FOR_INDEX_P(NUM) 0
-#define REGNO_OK_FOR_BASE_P(NUM) \
- (GP_REG_P (NUM) || GP_REG_P ((unsigned) reg_renumber[NUM]))
+#define REGNO_OK_FOR_BASE_P(NUM) GP_REG_P (NUM)
/* C expressions that are nonzero if X (assumed to be a `reg' RTX) is
valid for use as a base or index register. */
#define BASE_REG_P(X, STRICT) \
((!(STRICT) && ! HARD_REGISTER_P (X)) \
- || REGNO_OK_FOR_BASE_P (REGNO (X)))
+ || regno_ok_for_base_p (REGNO (X), VOIDmode, ADDR_SPACE_GENERIC, \
+ UNKNOWN, UNKNOWN))
/* Maximum number of registers that can appear in a valid memory address. */
#define MAX_REGS_PER_ADDRESS 1