public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix asm X constraint (PR inline-asm/59155)
@ 2016-05-25 13:45 Bernd Edlinger
  2016-06-06 13:33 ` [PING] " Bernd Edlinger
  0 siblings, 1 reply; 24+ messages in thread
From: Bernd Edlinger @ 2016-05-25 13:45 UTC (permalink / raw)
  To: gcc-patches; +Cc: Vladimir Makarov, Richard Biener, Jeff Law

[-- Attachment #1: Type: text/plain, Size: 657 bytes --]

Hi!

This restricts the X constraint in asm statements, which
can be easily folded by combine in something completely
invalid.

It is necessary to allow scratch here, because on i386
the md_asm_adjust hook inserts them.

The second test case fails because lra does not
allow all register for anything_ok operands (aka X)
and later it fails to match the two X constraints
in case '0': if (curr_alt[m] == NO_REGS) break.

There is also an identical bug in the reload pass,
but I do not know how to fix that, as it is almost
used nowhere today.


Boot-strapped and regression-tested on x86_64-pc-linux-gnu.
OK for trunk?


Thanks
Bernd.

[-- Attachment #2: changelog-pr59155.txt --]
[-- Type: text/plain, Size: 407 bytes --]

gcc:
2016-05-23  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	PR inline-asm/59155
	* lra-constraints.c (process_alt_operands): Allow ALL_REGS.
	* recog.c (asm_operand_ok): Handle X constraint.

testsuite:
2016-05-23  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	PR inline-asm/59155
	* gcc.dg/torture/pr59155-1.c: New test.
	* gcc.dg/torture/pr59155-2.c: New test.
	* gcc.dg/torture/pr59155-3.c: New test.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: patch-pr59155.diff --]
[-- Type: text/x-patch; name="patch-pr59155.diff", Size: 2398 bytes --]

Index: gcc/lra-constraints.c
===================================================================
--- gcc/lra-constraints.c	(revision 236569)
+++ gcc/lra-constraints.c	(working copy)
@@ -1854,7 +1854,7 @@ process_alt_operands (int only_alternative)
 	  if (curr_static_id->operand_alternative[opalt_num].anything_ok)
 	    {
 	      /* Fast track for no constraints at all.	*/
-	      curr_alt[nop] = NO_REGS;
+	      curr_alt[nop] = ALL_REGS;
 	      CLEAR_HARD_REG_SET (curr_alt_set[nop]);
 	      curr_alt_win[nop] = true;
 	      curr_alt_match_win[nop] = false;
Index: gcc/recog.c
===================================================================
--- gcc/recog.c	(revision 236569)
+++ gcc/recog.c	(working copy)
@@ -1757,6 +1757,10 @@ asm_operand_ok (rtx op, const char *constraint, co
 	    result = 1;
 	  break;
 
+	case 'X':
+	  if (scratch_operand (op, VOIDmode))
+	    result = 1;
+	  /* ... fall through ...  */
 	case 'g':
 	  if (general_operand (op, VOIDmode))
 	    result = 1;
Index: gcc/testsuite/gcc.dg/torture/pr59155-1.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr59155-1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr59155-1.c	(working copy)
@@ -0,0 +1,7 @@
+double f(double x){
+  asm volatile("":"+X"(x));
+  return x;
+}
+double g(double x,double y){
+  return f(f(x)+f(y));
+}
Index: gcc/testsuite/gcc.dg/torture/pr59155-2.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr59155-2.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr59155-2.c	(working copy)
@@ -0,0 +1,7 @@
+double f(double x){
+  asm volatile("":"+X"(x));
+  return x;
+}
+double g(){
+  return f(1.);
+}
Index: gcc/testsuite/gcc.dg/torture/pr59155-3.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr59155-3.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr59155-3.c	(working copy)
@@ -0,0 +1,27 @@
+void
+noprop1 (int **x, int y, int z)
+{
+  int *ptr = *x + y * z / 11;
+  asm volatile ("noprop1 %0" : : "X" (*ptr));
+}
+
+void
+noprop2 (int **x, int y, int z)
+{
+  int *ptr = *x + y * z / 11;
+  asm volatile ("noprop2 %0" : : "X" (ptr));
+}
+
+int *global_var;
+
+void
+const1 (void)
+{
+  asm volatile ("const1 %0" : : "X" (global_var));
+}
+
+void
+const2 (void)
+{
+  asm volatile ("const2 %0" : : "X" (*global_var));
+}

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2016-08-05 13:30 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-25 13:45 [PATCH] Fix asm X constraint (PR inline-asm/59155) Bernd Edlinger
2016-06-06 13:33 ` [PING] " Bernd Edlinger
2016-06-06 17:04   ` Vladimir Makarov
2016-06-06 17:54     ` Jeff Law
2016-06-06 18:01       ` Jakub Jelinek
2016-06-06 18:04         ` Jeff Law
2016-06-06 18:09           ` Jakub Jelinek
2016-06-06 19:28             ` Marc Glisse
2016-06-06 19:40               ` Jakub Jelinek
2016-06-09 16:30                 ` Jeff Law
2016-06-09 16:43                   ` Jakub Jelinek
2016-06-09 16:45                     ` Jakub Jelinek
2016-06-10 14:13                       ` Bernd Edlinger
2016-06-19 13:25                         ` [PING**2] " Bernd Edlinger
2016-06-22 19:51                           ` Jeff Law
2016-06-22 20:49                             ` Bernd Edlinger
2016-07-20 20:04                               ` Jeff Law
2016-07-21 16:30                                 ` Bernd Edlinger
2016-08-04 20:27                                   ` Jeff Law
2016-08-05 13:30                                     ` Bernd Edlinger
2016-06-20 22:06                       ` [PING] " Jeff Law
2016-06-21  1:52                         ` Bernd Edlinger
2016-06-07 17:58             ` Bernd Edlinger
2016-06-09 16:28               ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).