[5/5] Add an aligned_register_operand predicate

Message ID 20231112145229.2924713-6-richard.sandiford@arm.com
State Unresolved
Headers
Series Add support for operand-specific alignment requirements |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Richard Sandiford Nov. 12, 2023, 2:52 p.m. UTC
  This patch adds a target-independent aligned_register_operand
predicate, for use with register constraints that use filters
to impose an alignment.  The definition deliberately jetisons
some of the historical baggage in general_operand.

gcc/
	* common.md (aligned_register_operand): New predicate.
---
 gcc/common.md | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
  

Patch

diff --git a/gcc/common.md b/gcc/common.md
index 51ecd79786b..91a72bd7731 100644
--- a/gcc/common.md
+++ b/gcc/common.md
@@ -17,6 +17,34 @@ 
 ;; along with GCC; see the file COPYING3.  If not see
 ;; <http://www.gnu.org/licenses/>.  */
 
+;; This predicate is intended to be paired with register constraints that use
+;; register filters to impose an alignment.  Operands that are aligned via
+;; TARGET_HARD_REGNO_MODE_OK should use normal register_operands instead.
+(define_predicate "aligned_register_operand"
+  (match_code "reg,subreg")
+{
+  /* Require the offset in a non-paradoxical subreg to be naturally aligned.
+     For example, if we have a subreg of something that is double the size of
+     this operand, the offset must select the first or second half of it.  */
+  if (SUBREG_P (op)
+      && multiple_p (SUBREG_BYTE (op), GET_MODE_SIZE (GET_MODE (op))))
+    op = SUBREG_REG (op);
+  if (!REG_P (op))
+    return false;
+
+  if (HARD_REGISTER_P (op))
+    {
+      if (!in_hard_reg_set_p (operand_reg_set, GET_MODE (op), REGNO (op)))
+	return false;
+
+      /* Reject hard registers that would need reloading, so that the reload
+	 is visible to IRA and to pre-RA optimizers.  */
+      if (REGNO (op) % REG_NREGS (op) != 0)
+	return false;
+    }
+  return true;
+})
+
 (define_register_constraint "r" "GENERAL_REGS"
   "Matches any general register.")