]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add an aligned_register_operand predicate
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 21 Nov 2023 15:39:11 +0000 (15:39 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Tue, 21 Nov 2023 15:39:11 +0000 (15:39 +0000)
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

index 51ecd79786b557d0512bc68aa1804f6b7dbb458a..91a72bd7731e7bdb09b1833de2618812ec81a999 100644 (file)
 ;; 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.")