Patchwork [i386] PR47698 no CMOV for volatile mem

login
register
mail settings
Submitter Sergey Ostanevich
Date Oct. 27, 2011, 12:17 p.m.
Message ID <CAGYS_TK=XcXTzyM6bv8Xn2L8KW7n2iUiRiE9TJ+Q0MAbj8N0Hg@mail.gmail.com>
Download mbox | patch
Permalink /patch/122135/
State New
Headers show

Comments

Sergey Ostanevich - Oct. 27, 2011, 12:17 p.m.
Hi!

Here's a patch for PR47698, which is about CMOV should not be
generated for memory address marked as volatile.
Successfully bootstrapped and passed make check on x86_64-unknown-linux-gnu.

Is it Ok?

regards,
Sergos


/gcc

2011-10-27 Sergey Ostanevich

	PR rtl-optimization/47698
	* config/i386/i386.c (ix86_expand_int_movcc) prevent CMOV generation
	for volatile mem

/testsuite

2011-10-27 Sergey Ostanevich

	PR rtl-optimization/47698
	* gcc.target/i386/47698.c: New test
Richard Henderson - Oct. 28, 2011, 12:01 a.m.
On 10/27/2011 05:17 AM, Sergey Ostanevich wrote:
> +  /* MOVCC semantics implies that source is always read which is wrong
> +     for devices I/O that are defined using volatile in C. PR47698 */
> +
> +  if (MEM_P (operands[2]) && MEM_VOLATILE_P (operands[2]))
> +    return false;

This looks to be at the wrong level.  This fix should be
tested in ifcvt.c where we attempted this.


r~

Patch

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index c6e09ae..afe5de3 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -18312,6 +18312,12 @@  ix86_expand_int_movcc (rtx operands[])
   rtx op0 = XEXP (operands[1], 0);
   rtx op1 = XEXP (operands[1], 1);

+  /* MOVCC semantics implies that source is always read which is wrong
+     for devices I/O that are defined using volatile in C. PR47698 */
+
+  if (MEM_P (operands[2]) && MEM_VOLATILE_P (operands[2]))
+    return false;
+
   start_sequence ();
   compare_op = ix86_expand_compare (code, op0, op1);
   compare_seq = get_insns ();
diff --git a/gcc/testsuite/gcc.target/i386/47698.c
b/gcc/testsuite/gcc.target/i386/47698.c
new file mode 100644
index 0000000..2c75109
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/47698.c
@@ -0,0 +1,10 @@ 
+/* { dg-options "-Os" } */
+/* { dg-final { scan-assembler-not "cmov" } } */
+
+extern volatile unsigned long mmio;
+unsigned long foo(int cond)
+{
+      if (cond)
+              return mmio;
+        return 0;
+}