Hi:
  For inline asm, there could be an operand like (not (mem:)), it's
not a valid operand for normal memory constraint.
  Bootstrap is ok, regression test is ok for make check
RUNTESTFLAGS="--target_board='unix{-m32,}'"

gcc/ChangeLog
        PR target/97540
        * ira.c: (ira_setup_alts): Extract memory from operand only
        for special memory constraint.
        * recog.c (asm_operand_ok): Ditto.
        * lra-constraints.c (process_alt_operands): MEM_P is
        required for normal memory constraint.

gcc/testsuite/ChangeLog
        * gcc.target/i386/pr97540.c: New test.

--
BR,
Hongtao
From 54f21c2414041f9e62c3264542e65959eaa3318f Mon Sep 17 00:00:00 2001
From: liuhongt <hongtao.liu@intel.com>
Date: Mon, 26 Oct 2020 20:46:42 +0800
Subject: [PATCH 2/2] Don't extract memory from operand for normal memory
 constraint.

gcc/ChangeLog
	PR target/97540
	* ira.c: (ira_setup_alts): Extract memory from operand only
	for special memory constraint.
	* recog.c (asm_operand_ok): Ditto.
	* lra-constraints.c (process_alt_operands): MEM_P is
	required for normal memory constraint.

gcc/testsuite/ChangeLog
	* gcc.target/i386/pr97540.c: New test.
---
 gcc/ira.c                               | 7 ++++++-
 gcc/lra-constraints.c                   | 3 ++-
 gcc/recog.c                             | 8 ++++++--
 gcc/testsuite/gcc.target/i386/pr97540.c | 6 ++++++
 4 files changed, 20 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr97540.c

diff --git a/gcc/ira.c b/gcc/ira.c
index a61138c6e94..6838c2c6774 100644
--- a/gcc/ira.c
+++ b/gcc/ira.c
@@ -1845,6 +1845,7 @@ ira_setup_alts (rtx_insn *insn)
 		  default:
 		    {
 		      enum constraint_num cn = lookup_constraint (p);
+		      rtx mem = NULL;
 		      switch (get_constraint_type (cn))
 			{
 			case CT_REGISTER:
@@ -1867,8 +1868,12 @@ ira_setup_alts (rtx_insn *insn)
 			  goto op_success;
 
 			case CT_MEMORY:
+			  mem = op;
+			  /* Fall through.  */
 			case CT_SPECIAL_MEMORY:
-			  if (MEM_P (extract_mem_from_operand (op)))
+			  if (!mem)
+			    mem = extract_mem_from_operand (op);
+			  if (MEM_P (mem))
 			    goto op_success;
 			  win_p = true;
 			  break;
diff --git a/gcc/lra-constraints.c b/gcc/lra-constraints.c
index 9b94e0f210b..50ba75278b9 100644
--- a/gcc/lra-constraints.c
+++ b/gcc/lra-constraints.c
@@ -2428,7 +2428,8 @@ process_alt_operands (int only_alternative)
 		      break;
 
 		    case CT_MEMORY:
-		      if (satisfies_memory_constraint_p (op, cn))
+		      if (MEM_P (op)
+			  && satisfies_memory_constraint_p (op, cn))
 			win = true;
 		      else if (spilled_pseudo_p (op))
 			win = true;
diff --git a/gcc/recog.c b/gcc/recog.c
index d3552ec63eb..d1c733451a0 100644
--- a/gcc/recog.c
+++ b/gcc/recog.c
@@ -1778,6 +1778,7 @@ asm_operand_ok (rtx op, const char *constraint, const char **constraints)
 	  /* FALLTHRU */
 	default:
 	  cn = lookup_constraint (constraint);
+	  rtx mem = NULL;
 	  switch (get_constraint_type (cn))
 	    {
 	    case CT_REGISTER:
@@ -1796,10 +1797,13 @@ asm_operand_ok (rtx op, const char *constraint, const char **constraints)
 	      break;
 
 	    case CT_MEMORY:
+	      mem = op;
+	      /* Fall through.  */
 	    case CT_SPECIAL_MEMORY:
 	      /* Every memory operand can be reloaded to fit.  */
-	      result = result || memory_operand (extract_mem_from_operand (op),
-						 VOIDmode);
+	      if (!mem)
+		mem = extract_mem_from_operand (op);
+	      result = result || memory_operand (mem, VOIDmode);
 	      break;
 
 	    case CT_ADDRESS:
diff --git a/gcc/testsuite/gcc.target/i386/pr97540.c b/gcc/testsuite/gcc.target/i386/pr97540.c
new file mode 100644
index 00000000000..20f8717372c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr97540.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int mt7615_add_interface_dev_0;
+int ffs(int x) { asm("" : : "rm"(x)); }
+int mt7615_add_interface() { ffs(~mt7615_add_interface_dev_0); }
-- 
2.18.1

Reply via email to