diff mbox series

[v1] arm: Allow odd register pairs when MVE or CDE is enabled [PR124328]

Message ID bmm.hnuao6x5os.gcc.gcc.azoff.266.1.0@forge-stage.sourceware.org
State New
Headers show
Series [v1] arm: Allow odd register pairs when MVE or CDE is enabled [PR124328] | expand

Commit Message

Torbjörn Svensson via Sourceware Forge Nov. 4, 2026, 7:55 a.m. UTC
From: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>

Enabling MVE or CDE currently restricts multiword values to even register
pairs, even when the instruction does not require one.

Allow multiword values to start at odd registers in Thumb-2. Add Tr
and Tl constraints for even-numbered general and low registers, and
use them in the relevant MVE and CDE patterns.

gcc/ChangeLog:

	    PR target/124328
	    * config/arm/arm.cc (arm_hard_regno_mode_ok): Remove the
	    Thumb-2 even-register restriction for MVE and CDE.
	    * config/arm/constraints.md (Tr, Tl): New register constraints.
	    * config/arm/iterators.md (cde_constraint): New mode attribute.
	    * config/arm/arm.md (arm_cx1<mode>, arm_cx1a<mode>,
	    arm_cx2<mode>, arm_cx2a<mode>, arm_cx3<mode>, arm_cx3a<mode>):
	    Use cde_constraint for the destination.
	    * config/arm/mve.md: Use Tr and Tl where an even register
	    pair is required.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
---
Tested on arm-none-eabi (baseline r17-5743-ge33129b871c302) with no regression.

Ok for trunk and releases/gcc-16?

--



This is a forge pull request published on the gcc-patches mailing list mailing list
as requested by Torbjörn Svensson via Sourceware Forge <forge-bot+azoff@forge-stage.sourceware.org>.
Forge discussion: https://forge.sourceware.org/gcc/gcc/pulls/266

Get it locally using:
```
git fetch forge-upstream "+refs/versioned_pull/266/*:refs/versioned_pull/266/*"
git switch -c "pr-266-v1" "refs/versioned_pull/266/1/head"
```
Or, download the patch at: https://forge.sourceware.org/gcc/gcc/pulls/266.diff
Created on: 2026-11-04 06:52:09+00:00
Latest update: 2026-11-04 07:55:43+00:00
Changes: 5 changed files, 47 additions, 38 deletions
Head revision: azoff/gcc ref pr/asm-hard-reg commit 0790c0777a3aceabf1793c786eb45e1d6c2e63eb 
Base revision: gcc/gcc ref trunk commit e33129b871c30276acfaed2b435ae5b505b73655 r17-5743-ge33129b871c302
Merge base: e33129b871c30276acfaed2b435ae5b505b73655
Requested Reviewers: 

Changed files:
- M: gcc/config/arm/arm.cc
- M: gcc/config/arm/arm.md
- M: gcc/config/arm/constraints.md
- M: gcc/config/arm/iterators.md
- M: gcc/config/arm/mve.md

 gcc/config/arm/arm.cc         | 10 +++----
 gcc/config/arm/arm.md         | 12 ++++-----
 gcc/config/arm/constraints.md | 12 +++++++--
 gcc/config/arm/iterators.md   |  1 +
 gcc/config/arm/mve.md         | 50 +++++++++++++++++------------------
 5 files changed, 47 insertions(+), 38 deletions(-)
diff mbox series

Patch

diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index 940c689b21e0e..1fc60ef177fa9 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -24850,8 +24850,9 @@  arm_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
 
   /* We allow almost any value to be stored in the general registers.
      Restrict doubleword quantities to even register pairs in ARM state
-     so that we can use ldrd. The same restriction applies for MVE
-     in order to support Armv8.1-M Mainline instructions.
+     so that we can use ldrd.  Thumb-2 has no such requirement;
+     instructions that need an even register pair enforce it through
+     their operand constraints instead.
      Do not allow very large Neon structure  opaque modes in general
      registers; they would use too many.  */
   if (regno <= LAST_ARM_REGNUM)
@@ -24859,11 +24860,10 @@  arm_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
       if (ARM_NUM_REGS (mode) > 4)
 	return false;
 
-      if (TARGET_THUMB2 && !(TARGET_HAVE_MVE || TARGET_CDE))
+      if (TARGET_THUMB2)
 	return true;
 
-      return !((TARGET_LDRD || TARGET_CDE)
-	       && GET_MODE_SIZE (mode) > 4 && (regno & 1) != 0);
+      return !TARGET_LDRD || GET_MODE_SIZE (mode) <= 4 || (regno & 1) == 0;
     }
 
   if (regno == FRAME_POINTER_REGNUM
diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
index 785d341aa2aa7..55c8d4e792c10 100644
--- a/gcc/config/arm/arm.md
+++ b/gcc/config/arm/arm.md
@@ -4515,7 +4515,7 @@ 
 
 ;; Custom Datapath Extension insns.
 (define_insn "arm_cx1<mode>"
-   [(set (match_operand:SIDI 0 "s_register_operand" "=r")
+   [(set (match_operand:SIDI 0 "s_register_operand" "=<cde_constraint>")
 	 (unspec:SIDI [(match_operand:SI 1 "const_int_coproc_operand" "i")
 	               (match_operand:SI 2 "const_int_ccde1_operand" "i")]
 	    UNSPEC_CDE))]
@@ -4525,7 +4525,7 @@ 
 )
 
 (define_insn "arm_cx1a<mode>"
-   [(set (match_operand:SIDI 0 "s_register_operand" "=r")
+   [(set (match_operand:SIDI 0 "s_register_operand" "=<cde_constraint>")
 	 (unspec:SIDI [(match_operand:SI 1 "const_int_coproc_operand" "i")
 		       (match_operand:SIDI 2 "s_register_operand" "0")
 	               (match_operand:SI 3 "const_int_ccde1_operand" "i")]
@@ -4536,7 +4536,7 @@ 
 )
 
 (define_insn "arm_cx2<mode>"
-   [(set (match_operand:SIDI 0 "s_register_operand" "=r")
+   [(set (match_operand:SIDI 0 "s_register_operand" "=<cde_constraint>")
 	 (unspec:SIDI [(match_operand:SI 1 "const_int_coproc_operand" "i")
 		       (match_operand:SI 2 "s_register_operand" "r")
 	               (match_operand:SI 3 "const_int_ccde2_operand" "i")]
@@ -4547,7 +4547,7 @@ 
 )
 
 (define_insn "arm_cx2a<mode>"
-   [(set (match_operand:SIDI 0 "s_register_operand" "=r")
+   [(set (match_operand:SIDI 0 "s_register_operand" "=<cde_constraint>")
 	 (unspec:SIDI [(match_operand:SI 1 "const_int_coproc_operand" "i")
 		       (match_operand:SIDI 2 "s_register_operand" "0")
 		       (match_operand:SI 3 "s_register_operand" "r")
@@ -4559,7 +4559,7 @@ 
 )
 
 (define_insn "arm_cx3<mode>"
-   [(set (match_operand:SIDI 0 "s_register_operand" "=r")
+   [(set (match_operand:SIDI 0 "s_register_operand" "=<cde_constraint>")
 	 (unspec:SIDI [(match_operand:SI 1 "const_int_coproc_operand" "i")
 		       (match_operand:SI 2 "s_register_operand" "r")
 		       (match_operand:SI 3 "s_register_operand" "r")
@@ -4571,7 +4571,7 @@ 
 )
 
 (define_insn "arm_cx3a<mode>"
-   [(set (match_operand:SIDI 0 "s_register_operand" "=r")
+   [(set (match_operand:SIDI 0 "s_register_operand" "=<cde_constraint>")
 	 (unspec:SIDI [(match_operand:SI 1 "const_int_coproc_operand" "i")
 		       (match_operand:SIDI 2 "s_register_operand" "0")
 		       (match_operand:SI 3 "s_register_operand" "r")
diff --git a/gcc/config/arm/constraints.md b/gcc/config/arm/constraints.md
index d9ab0e1127b33..8ba14c9f27530 100644
--- a/gcc/config/arm/constraints.md
+++ b/gcc/config/arm/constraints.md
@@ -21,8 +21,8 @@ 
 ;; The following register constraints have been used:
 ;; - in ARM/Thumb-2 state: t, w, x
 ;; - in Thumb state: h, b
-;; - in both states: l, c, k, q, Cs, Ts, US
-;; In ARM state, 'l' is an alias for 'r'
+;; - in both states: l, c, k, q, Cs, Ts, Tl, Tr, US
+;; In ARM state, 'l' is an alias for 'r' and 'Tl' is an alias for 'Tr'
 ;; 'f' and 'v' were previously used for FPA and MAVERICK registers.
 ;; 'y' and 'z' were previously used for iWMMX registers (removed after gcc-15)
 
@@ -66,6 +66,14 @@ 
   "EVEN core registers @code{r0}, @code{r2}, @code{r4}, @code{r6}, @code{r8},
    @code{r10}, @code{r12}, @code{r14}")
 
+(define_register_constraint "Tr" "GENERAL_REGS"
+  "@internal As @code{r}, but the first register must be even-numbered."
+  "regno % 2 == 0")
+
+(define_register_constraint "Tl" "TARGET_THUMB ? LO_REGS : GENERAL_REGS"
+  "@internal As @code{l}, but the first register must be even-numbered."
+  "regno % 2 == 0")
+
 (define_constraint "Rd"
   "@internal In Thumb-2 state a constant in range 1 to 16"
   (and (match_code "const_int")
diff --git a/gcc/config/arm/iterators.md b/gcc/config/arm/iterators.md
index c8fd31b52c56d..0f0565945d274 100644
--- a/gcc/config/arm/iterators.md
+++ b/gcc/config/arm/iterators.md
@@ -2024,6 +2024,7 @@ 
 
 (define_mode_attr cde_suffix [(SI "") (DI "d")])
 (define_mode_attr cde_dest [(SI "%0") (DI "%0, %H0")])
+(define_mode_attr cde_constraint [(SI "r") (DI "Tr")])
 
 ;;MVE mode attribute.
 (define_mode_attr MVE_CNVT [(V8HI "V8HF") (V4SI "V4SF") (V8HF "V8HI")
diff --git a/gcc/config/arm/mve.md b/gcc/config/arm/mve.md
index 1d41da380e981..c68982b167d5c 100644
--- a/gcc/config/arm/mve.md
+++ b/gcc/config/arm/mve.md
@@ -442,7 +442,7 @@ 
 ;;
 (define_insn "@mve_<mve_insn>q_<supf>v4si"
   [
-   (set (match_operand:DI 0 "s_register_operand" "=r")
+   (set (match_operand:DI 0 "s_register_operand" "=Tr")
 	(unspec:DI [(match_operand:V4SI 1 "s_register_operand" "w")]
 	 VADDLVQ))
   ]
@@ -618,7 +618,7 @@ 
 ;;
 (define_insn "@mve_<mve_insn>q_p_<supf>v4si"
   [
-   (set (match_operand:DI 0 "s_register_operand" "=r")
+   (set (match_operand:DI 0 "s_register_operand" "=Tr")
 	(unspec:DI [(match_operand:V4SI 1 "s_register_operand" "w")
 		    (match_operand:V4BI 2 "vpr_register_operand" "Up")]
 	 VADDLVQ_P))
@@ -1135,7 +1135,7 @@ 
 ;;
 (define_insn "@mve_<mve_insn>q_<supf>v4si"
   [
-   (set (match_operand:DI 0 "s_register_operand" "=r")
+   (set (match_operand:DI 0 "s_register_operand" "=Tr")
 	(unspec:DI [(match_operand:DI 1 "s_register_operand" "0")
 		    (match_operand:V4SI 2 "s_register_operand" "w")]
 	 VADDLVAQ))
@@ -1352,7 +1352,7 @@ 
 ;;
 (define_insn "@mve_<mve_insn>q_<supf><mode>"
   [
-   (set (match_operand:DI 0 "s_register_operand" "=r")
+   (set (match_operand:DI 0 "s_register_operand" "=Tr")
 	(unspec:DI [(match_operand:MVE_5 1 "s_register_operand" "w")
 		    (match_operand:MVE_5 2 "s_register_operand" "w")]
 	 MVE_VMLxLDAVxQ))
@@ -1491,7 +1491,7 @@ 
 ;;
 (define_insn "@mve_<mve_insn>q_<supf>v4si"
   [
-   (set (match_operand:DI 0 "s_register_operand" "=r")
+   (set (match_operand:DI 0 "s_register_operand" "=Tr")
 	(unspec:DI [(match_operand:V4SI 1 "s_register_operand" "w")
 		    (match_operand:V4SI 2 "s_register_operand" "w")]
 	 MVE_VRMLxLDAVxQ))
@@ -1631,7 +1631,7 @@ 
 ;;
 (define_insn "@mve_<mve_insn>q_<supf>v4si"
   [
-   (set (match_operand:DI 0 "s_register_operand" "=r")
+   (set (match_operand:DI 0 "s_register_operand" "=Tr")
 	(unspec:DI [(match_operand:DI 1 "s_register_operand" "0")
 		    (match_operand:V4SI 2 "s_register_operand" "w")
 		    (match_operand:V4SI 3 "s_register_operand" "w")]
@@ -2061,7 +2061,7 @@ 
 ;;
 (define_insn "@mve_<mve_insn>q_p_<supf>v4si"
   [
-   (set (match_operand:DI 0 "s_register_operand" "=r")
+   (set (match_operand:DI 0 "s_register_operand" "=Tr")
 	(unspec:DI [(match_operand:DI 1 "s_register_operand" "0")
 		       (match_operand:V4SI 2 "s_register_operand" "w")
 		       (match_operand:V4BI 3 "vpr_register_operand" "Up")]
@@ -2250,7 +2250,7 @@ 
 ;;
 (define_insn "@mve_<mve_insn>q_<supf><mode>"
   [
-   (set (match_operand:DI 0 "s_register_operand" "=r")
+   (set (match_operand:DI 0 "s_register_operand" "=Tr")
 	(unspec:DI [(match_operand:DI 1 "s_register_operand" "0")
 		       (match_operand:MVE_5 2 "s_register_operand" "w")
 		       (match_operand:MVE_5 3 "s_register_operand" "w")]
@@ -2271,7 +2271,7 @@ 
 ;;
 (define_insn "@mve_<mve_insn>q_p_<supf><mode>"
   [
-   (set (match_operand:DI 0 "s_register_operand" "=r")
+   (set (match_operand:DI 0 "s_register_operand" "=Tr")
 	(unspec:DI [(match_operand:MVE_5 1 "s_register_operand" "w")
 		       (match_operand:MVE_5 2 "s_register_operand" "w")
 		       (match_operand:<MVE_VPRED> 3 "vpr_register_operand" "Up")]
@@ -2434,7 +2434,7 @@ 
 ;;
 (define_insn "@mve_<mve_insn>q_p_<supf>v4si"
   [
-   (set (match_operand:DI 0 "s_register_operand" "=r")
+   (set (match_operand:DI 0 "s_register_operand" "=Tr")
 	(unspec:DI [(match_operand:V4SI 1 "s_register_operand" "w")
 		       (match_operand:V4SI 2 "s_register_operand" "w")
 		       (match_operand:V4BI 3 "vpr_register_operand" "Up")]
@@ -2847,7 +2847,7 @@ 
 ;;
 (define_insn "@mve_<mve_insn>q_p_<supf><mode>"
   [
-   (set (match_operand:DI 0 "s_register_operand" "=r")
+   (set (match_operand:DI 0 "s_register_operand" "=Tr")
 	(unspec:DI [(match_operand:DI 1 "s_register_operand" "0")
 		       (match_operand:MVE_5 2 "s_register_operand" "w")
 		       (match_operand:MVE_5 3 "s_register_operand" "w")
@@ -2897,7 +2897,7 @@ 
 ;;
 (define_insn "@mve_<mve_insn>q_p_<supf>v4si"
   [
-   (set (match_operand:DI 0 "s_register_operand" "=r")
+   (set (match_operand:DI 0 "s_register_operand" "=Tr")
 	(unspec:DI [(match_operand:DI 1 "s_register_operand" "0")
 		       (match_operand:V4SI 2 "s_register_operand" "w")
 		       (match_operand:V4SI 3 "s_register_operand" "w")
@@ -3758,7 +3758,7 @@ 
 (define_insn "@mve_<mve_insn>q_wb_u<mode>_insn"
   [(set (match_operand:MVE_2 0 "s_register_operand" "=w")
 	(unspec:MVE_2 [(match_operand:SI 2 "s_register_operand" "1")
-		       (subreg:SI (match_operand:DI 3 "s_register_operand" "r") 4)
+		       (subreg:SI (match_operand:DI 3 "s_register_operand" "Tr") 4)
 		       (match_operand:SI 4 "mve_imm_selective_upto_8" "Rg")]
 	 VIDWDUPQ))
    (set (match_operand:SI 1 "s_register_operand" "=Te")
@@ -3778,7 +3778,7 @@ 
   [(set (match_operand:MVE_2 0 "s_register_operand" "=w")
 	(unspec:MVE_2 [(match_operand:MVE_2 1 "s_register_operand" "0")
 		       (match_operand:SI 3 "s_register_operand" "2")
-		       (subreg:SI (match_operand:DI 4 "s_register_operand" "r") 4)
+		       (subreg:SI (match_operand:DI 4 "s_register_operand" "Tr") 4)
 		       (match_operand:SI 5 "mve_imm_selective_upto_8" "Rg")
 		       (match_operand:<MVE_VPRED> 6 "vpr_register_operand" "Up")]
 	 VIDWDUPQ_M))
@@ -4280,7 +4280,7 @@ 
 ;; [uqrshll_di]
 ;;
 (define_insn "@mve_uqrshll_sat<supf>_di"
-  [(set (match_operand:DI 0 "arm_low_register_operand" "=l")
+  [(set (match_operand:DI 0 "arm_low_register_operand" "=Tl")
 	(unspec:DI [(match_operand:DI 1 "arm_low_register_operand" "0")
 		    (match_operand:SI 2 "register_operand" "r")]
 	 UQRSHLLQ))]
@@ -4292,7 +4292,7 @@ 
 ;; [sqrshrl_di]
 ;;
 (define_insn "@mve_sqrshrl_sat<supf>_di"
-  [(set (match_operand:DI 0 "arm_low_register_operand" "=l")
+  [(set (match_operand:DI 0 "arm_low_register_operand" "=Tl")
 	(unspec:DI [(match_operand:DI 1 "arm_low_register_operand" "0")
 		    (match_operand:SI 2 "register_operand" "r")]
 	 SQRSHRLQ))]
@@ -4328,7 +4328,7 @@ 
 ;; [uqshll_di]
 ;;
 (define_insn "mve_uqshll_di"
-  [(set (match_operand:DI 0 "arm_low_register_operand" "=l")
+  [(set (match_operand:DI 0 "arm_low_register_operand" "=Tl")
 	(us_ashift:DI (match_operand:DI 1 "arm_low_register_operand" "0")
 		      (match_operand:SI 2 "immediate_operand" "Pg")))]
   "TARGET_HAVE_MVE"
@@ -4339,7 +4339,7 @@ 
 ;; [urshrl_di]
 ;;
 (define_insn "mve_urshrl_di"
-  [(set (match_operand:DI 0 "arm_low_register_operand" "=l")
+  [(set (match_operand:DI 0 "arm_low_register_operand" "=Tl")
 	(unspec:DI [(match_operand:DI 1 "arm_low_register_operand" "0")
 		    (match_operand:SI 2 "immediate_operand" "Pg")]
 	 URSHRL))]
@@ -4397,7 +4397,7 @@ 
 ;; [srshrl_di]
 ;;
 (define_insn "mve_srshrl_di"
-  [(set (match_operand:DI 0 "arm_low_register_operand" "=l")
+  [(set (match_operand:DI 0 "arm_low_register_operand" "=Tl")
 	(unspec:DI [(match_operand:DI 1 "arm_low_register_operand" "0")
 		    (match_operand:SI 2 "immediate_operand" "Pg")]
 	 SRSHRL))]
@@ -4409,7 +4409,7 @@ 
 ;; [sqshll_di]
 ;;
 (define_insn "mve_sqshll_di"
-  [(set (match_operand:DI 0 "arm_low_register_operand" "=l")
+  [(set (match_operand:DI 0 "arm_low_register_operand" "=Tl")
 	(ss_ashift:DI (match_operand:DI 1 "arm_low_register_operand" "0")
 		      (match_operand:SI 2 "immediate_operand" "Pg")))]
   "TARGET_HAVE_MVE"
@@ -4760,7 +4760,7 @@ 
 ;; immediate shift amount
 ;; we have to split the insn if the amount is not in the [1..32] range
 (define_insn_and_split "mve_asrl_imm"
-  [(set (match_operand:DI 0 "arm_general_register_operand" "=r,r")
+  [(set (match_operand:DI 0 "arm_general_register_operand" "=Tr,r")
 	  (ashiftrt:DI (match_operand:DI 1 "arm_general_register_operand" "0,r")
 		       (match_operand:QI 2 "immediate_operand" "Pg,Ph")))]
   "TARGET_HAVE_MVE"
@@ -4816,7 +4816,7 @@ 
    (set_attr "length" "4,8")])
 
 (define_insn "mve_asrl_internal"
-  [(set (match_operand:DI 0 "arm_general_register_operand" "=r")
+  [(set (match_operand:DI 0 "arm_general_register_operand" "=Tr")
 	(if_then_else:DI
 	  (ge:QI (match_operand:QI 2 "arm_general_register_operand" "r")
 		 (const_int 0))
@@ -4856,7 +4856,7 @@ 
 ;; immediate shift amount
 ;; we have to split the insn if the amount is not in the [1..32] range
 (define_insn_and_split "mve_lsll_imm"
-  [(set (match_operand:DI 0 "arm_general_register_operand" "=r,r")
+  [(set (match_operand:DI 0 "arm_general_register_operand" "=Tr,r")
 	  (ashift:DI (match_operand:DI 1 "arm_general_register_operand" "0,r")
 		     (match_operand:QI 2 "immediate_operand" "Pg,Ph")))]
   "TARGET_HAVE_MVE"
@@ -4909,7 +4909,7 @@ 
    (set_attr "length" "4,8")])
 
 (define_insn "mve_lsll_internal"
-  [(set (match_operand:DI 0 "arm_general_register_operand" "=r")
+  [(set (match_operand:DI 0 "arm_general_register_operand" "=Tr")
         (if_then_else:DI
 	  (ge:QI (match_operand:QI 2 "arm_general_register_operand" "r")
 		 (const_int 0))
@@ -4921,7 +4921,7 @@ 
   [(set_attr "predicable" "yes")])
 
 (define_insn "mve_lsrl"
-  [(set (match_operand:DI 0 "arm_general_register_operand" "=r")
+  [(set (match_operand:DI 0 "arm_general_register_operand" "=Tr")
 	(lshiftrt:DI (match_operand:DI 1 "arm_general_register_operand" "0")
 		     (match_operand:SI 2 "long_shift_imm" "Pg")))]
   "TARGET_HAVE_MVE"