Message ID | CAFULd4ana5uk0Xkmn=6rok+-uMpCsGwC8=i2mxHXGd+vNr0V5g@mail.gmail.com |
---|---|
State | New |
Headers | show |
Series | Introduce VIRTUAL_REGISTER_P and VIRTUAL_REGISTER_NUM_P predicates | expand |
On 4/17/23 15:27, Uros Bizjak via Gcc-patches wrote: > These two predicates are similar to existing HARD_REGISTER_P and > HARD_REGISTER_NUM_P predicates and return 1 if the given register > corresponds to a virtual register. > > gcc/ChangeLog: > > * rtl.h (VIRTUAL_REGISTER_P): New predicate. > (VIRTUAL_REGISTER_NUM_P): Ditto. > (REGNO_PTR_FRAME_P): Use VIRTUAL_REGISTER_NUM_P predicate. > * expr.cc (force_operand): Use VIRTUAL_REGISTER_P predicate. > * function.cc (instantiate_decl_rtl): Ditto. > * rtlanal.cc (rtx_addr_can_trap_p_1): Ditto. > (nonzero_address_p): Ditto. > (refers_to_regno_p): Use VIRTUAL_REGISTER_NUM_P predicate. > > Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. > > OK for master? OK. Jeff
On Mon, Apr 17, 2023 at 11:27:28PM +0200, Uros Bizjak via Gcc-patches wrote: > --- a/gcc/rtl.h > +++ b/gcc/rtl.h > @@ -1972,6 +1972,13 @@ set_regno_raw (rtx x, unsigned int regno, unsigned int nregs) > /* 1 if the given register number REG_NO corresponds to a hard register. */ > #define HARD_REGISTER_NUM_P(REG_NO) ((REG_NO) < FIRST_PSEUDO_REGISTER) > > +/* 1 if the given register REG corresponds to a virtual register. */ > +#define VIRTUAL_REGISTER_P(REG) (VIRTUAL_REGISTER_NUM_P (REGNO (REG))) > + > +/* 1 if the given register number REG_NO corresponds to a virtual register. */ > +#define VIRTUAL_REGISTER_NUM_P(REG_NO) \ > + (IN_RANGE (REG_NO, FIRST_VIRTUAL_REGISTER, LAST_VIRTUAL_REGISTER)) Why the ()s around both definitions? IN_RANGE adds its own and anything on top of that is just superfluous. Jakub
On Tue, Apr 18, 2023 at 7:20 PM Jakub Jelinek <jakub@redhat.com> wrote: > > On Mon, Apr 17, 2023 at 11:27:28PM +0200, Uros Bizjak via Gcc-patches wrote: > > --- a/gcc/rtl.h > > +++ b/gcc/rtl.h > > @@ -1972,6 +1972,13 @@ set_regno_raw (rtx x, unsigned int regno, unsigned int nregs) > > /* 1 if the given register number REG_NO corresponds to a hard register. */ > > #define HARD_REGISTER_NUM_P(REG_NO) ((REG_NO) < FIRST_PSEUDO_REGISTER) > > > > +/* 1 if the given register REG corresponds to a virtual register. */ > > +#define VIRTUAL_REGISTER_P(REG) (VIRTUAL_REGISTER_NUM_P (REGNO (REG))) > > + > > +/* 1 if the given register number REG_NO corresponds to a virtual register. */ > > +#define VIRTUAL_REGISTER_NUM_P(REG_NO) \ > > + (IN_RANGE (REG_NO, FIRST_VIRTUAL_REGISTER, LAST_VIRTUAL_REGISTER)) > > Why the ()s around both definitions? > IN_RANGE adds its own and anything on top of that is just superfluous. Mainly to imitate the surrounding code (e.g. HARD_REGISTER_P) that is quite generous with brackets. I can remove external brackets from both definitions, but I'd remove them also from the HARD_REGISTER_P definition. Uros,
On Wed, Apr 19, 2023 at 08:53:42AM +0200, Uros Bizjak wrote: > On Tue, Apr 18, 2023 at 7:20 PM Jakub Jelinek <jakub@redhat.com> wrote: > > > > On Mon, Apr 17, 2023 at 11:27:28PM +0200, Uros Bizjak via Gcc-patches wrote: > > > --- a/gcc/rtl.h > > > +++ b/gcc/rtl.h > > > @@ -1972,6 +1972,13 @@ set_regno_raw (rtx x, unsigned int regno, unsigned int nregs) > > > /* 1 if the given register number REG_NO corresponds to a hard register. */ > > > #define HARD_REGISTER_NUM_P(REG_NO) ((REG_NO) < FIRST_PSEUDO_REGISTER) > > > > > > +/* 1 if the given register REG corresponds to a virtual register. */ > > > +#define VIRTUAL_REGISTER_P(REG) (VIRTUAL_REGISTER_NUM_P (REGNO (REG))) > > > + > > > +/* 1 if the given register number REG_NO corresponds to a virtual register. */ > > > +#define VIRTUAL_REGISTER_NUM_P(REG_NO) \ > > > + (IN_RANGE (REG_NO, FIRST_VIRTUAL_REGISTER, LAST_VIRTUAL_REGISTER)) > > > > Why the ()s around both definitions? > > IN_RANGE adds its own and anything on top of that is just superfluous. > > Mainly to imitate the surrounding code (e.g. HARD_REGISTER_P) that is > quite generous with brackets. > > I can remove external brackets from both definitions, but I'd remove > them also from the HARD_REGISTER_P definition. Please do. HARD_REGISTER_NUM_P obviously needs to keep it. Jakub
diff --git a/gcc/expr.cc b/gcc/expr.cc index f8f5cc5a6ca..758dda9ec68 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -8178,8 +8178,7 @@ force_operand (rtx value, rtx target) if (code == PLUS && CONST_INT_P (op2) && GET_CODE (XEXP (value, 0)) == PLUS && REG_P (XEXP (XEXP (value, 0), 0)) - && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER - && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER) + && VIRTUAL_REGISTER_P (XEXP (XEXP (value, 0), 0))) { rtx temp = expand_simple_binop (GET_MODE (value), code, XEXP (XEXP (value, 0), 0), op2, diff --git a/gcc/function.cc b/gcc/function.cc index edf0b2ec6cf..f0ae641512d 100644 --- a/gcc/function.cc +++ b/gcc/function.cc @@ -1838,8 +1838,7 @@ instantiate_decl_rtl (rtx x) addr = XEXP (x, 0); if (CONSTANT_P (addr) || (REG_P (addr) - && (REGNO (addr) < FIRST_VIRTUAL_REGISTER - || REGNO (addr) > LAST_VIRTUAL_REGISTER))) + && !VIRTUAL_REGISTER_P (addr))) return; instantiate_virtual_regs_in_rtx (&XEXP (x, 0)); diff --git a/gcc/rtl.h b/gcc/rtl.h index 60852aeecd8..2f27490444b 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -1972,6 +1972,13 @@ set_regno_raw (rtx x, unsigned int regno, unsigned int nregs) /* 1 if the given register number REG_NO corresponds to a hard register. */ #define HARD_REGISTER_NUM_P(REG_NO) ((REG_NO) < FIRST_PSEUDO_REGISTER) +/* 1 if the given register REG corresponds to a virtual register. */ +#define VIRTUAL_REGISTER_P(REG) (VIRTUAL_REGISTER_NUM_P (REGNO (REG))) + +/* 1 if the given register number REG_NO corresponds to a virtual register. */ +#define VIRTUAL_REGISTER_NUM_P(REG_NO) \ + (IN_RANGE (REG_NO, FIRST_VIRTUAL_REGISTER, LAST_VIRTUAL_REGISTER)) + /* For a CONST_INT rtx, INTVAL extracts the integer. */ #define INTVAL(RTX) XCWINT (RTX, 0, CONST_INT) #define UINTVAL(RTX) ((unsigned HOST_WIDE_INT) INTVAL (RTX)) @@ -4078,8 +4085,7 @@ PUT_MODE (rtx x, machine_mode mode) || (REGNUM) == FRAME_POINTER_REGNUM \ || (REGNUM) == HARD_FRAME_POINTER_REGNUM \ || (REGNUM) == ARG_POINTER_REGNUM \ - || ((REGNUM) >= FIRST_VIRTUAL_REGISTER \ - && (REGNUM) <= LAST_VIRTUAL_POINTER_REGISTER)) + || VIRTUAL_REGISTER_NUM_P (REGNUM)) /* REGNUM never really appearing in the INSN stream. */ #define INVALID_REGNUM (~(unsigned int) 0) diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc index e69d2e8a9f5..c96a88cebf1 100644 --- a/gcc/rtlanal.cc +++ b/gcc/rtlanal.cc @@ -643,8 +643,7 @@ rtx_addr_can_trap_p_1 (const_rtx x, poly_int64 offset, poly_int64 size, return 1; } /* All of the virtual frame registers are stack references. */ - if (REGNO (x) >= FIRST_VIRTUAL_REGISTER - && REGNO (x) <= LAST_VIRTUAL_REGISTER) + if (VIRTUAL_REGISTER_P (x)) return 0; return 1; @@ -733,8 +732,7 @@ nonzero_address_p (const_rtx x) || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM])) return true; /* All of the virtual frame registers are stack references. */ - if (REGNO (x) >= FIRST_VIRTUAL_REGISTER - && REGNO (x) <= LAST_VIRTUAL_REGISTER) + if (VIRTUAL_REGISTER_P (x)) return true; return false; @@ -1769,7 +1767,7 @@ refers_to_regno_p (unsigned int regno, unsigned int endregno, const_rtx x, || (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && x_regno == ARG_POINTER_REGNUM) || x_regno == FRAME_POINTER_REGNUM) - && regno >= FIRST_VIRTUAL_REGISTER && regno <= LAST_VIRTUAL_REGISTER) + && VIRTUAL_REGISTER_NUM_P (regno)) return true; return endregno > x_regno && regno < END_REGNO (x);