re PR target/86314 (GCC 7.x and 8.x zero out "eax" before using "rax" in "lock bts")
authorJakub Jelinek <jakub@redhat.com>
Tue, 26 Jun 2018 11:35:52 +0000 (13:35 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 26 Jun 2018 11:35:52 +0000 (13:35 +0200)
PR target/86314
* config/i386/i386.md (setcc + movzbl to xor + setcc peephole2s):
Check reg_overlap_mentioned_p in addition to reg_set_p with the same
operands.

* gcc.dg/pr86314.c: New test.

From-SVN: r262141

gcc/ChangeLog
gcc/config/i386/i386.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr86314.c [new file with mode: 0644]

index ec68212bc0af4ad1f07a49c6b4ad4776ce84ba17..13b648cab29ec25ab7b744c7104f114cf824af07 100644 (file)
@@ -1,3 +1,10 @@
+2018-06-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/86314
+       * config/i386/i386.md (setcc + movzbl to xor + setcc peephole2s):
+       Check reg_overlap_mentioned_p in addition to reg_set_p with the same
+       operands.
+
 2018-06-26  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/86287
index 6f2300057aa9f5387076a26189bd7baedf498a80..559ad9334a77429b911a0deef284ed10b702b731 100644 (file)
   "(peep2_reg_dead_p (3, operands[1])
     || operands_match_p (operands[1], operands[3]))
    && ! reg_overlap_mentioned_p (operands[3], operands[0])
+   && ! reg_overlap_mentioned_p (operands[3], operands[4])
    && ! reg_set_p (operands[3], operands[4])
    && peep2_regno_dead_p (0, FLAGS_REG)"
   [(parallel [(set (match_dup 5) (match_dup 0))
     || operands_match_p (operands[2], operands[4]))
    && ! reg_overlap_mentioned_p (operands[4], operands[0])
    && ! reg_overlap_mentioned_p (operands[4], operands[1])
+   && ! reg_overlap_mentioned_p (operands[4], operands[5])
    && ! reg_set_p (operands[4], operands[5])
    && refers_to_regno_p (FLAGS_REG, operands[1], (rtx *)NULL)
    && peep2_regno_dead_p (0, FLAGS_REG)"
   "(peep2_reg_dead_p (3, operands[1])
     || operands_match_p (operands[1], operands[3]))
    && ! reg_overlap_mentioned_p (operands[3], operands[0])
+   && ! reg_overlap_mentioned_p (operands[3], operands[4])
    && ! reg_set_p (operands[3], operands[4])
    && peep2_regno_dead_p (0, FLAGS_REG)"
   [(parallel [(set (match_dup 5) (match_dup 0))
     || operands_match_p (operands[2], operands[4]))
    && ! reg_overlap_mentioned_p (operands[4], operands[0])
    && ! reg_overlap_mentioned_p (operands[4], operands[1])
+   && ! reg_overlap_mentioned_p (operands[4], operands[5])
    && ! reg_set_p (operands[4], operands[5])
    && refers_to_regno_p (FLAGS_REG, operands[1], (rtx *)NULL)
    && peep2_regno_dead_p (0, FLAGS_REG)"
index 7aea7efb21f943be77a8dda57be38ede716e1d14..3931bfe8525efc5e89f6050bca97f096c1f69017 100644 (file)
@@ -1,5 +1,8 @@
 2018-06-26  Jakub Jelinek  <jakub@redhat.com>
 
+       PR target/86314
+       * gcc.dg/pr86314.c: New test.
+
        PR debug/86257
        * gcc.target/i386/pr86257.c: Add -mtls-dialect=gnu to dg-options.
 
diff --git a/gcc/testsuite/gcc.dg/pr86314.c b/gcc/testsuite/gcc.dg/pr86314.c
new file mode 100644 (file)
index 0000000..8962a3c
--- /dev/null
@@ -0,0 +1,20 @@
+// PR target/86314
+// { dg-do run { target sync_int_long } }
+// { dg-options "-O2" }
+
+__attribute__((noinline, noclone)) unsigned long
+foo (unsigned long *p)
+{
+  unsigned long m = 1UL << ((*p & 1) ? 1 : 0);
+  unsigned long n = __atomic_fetch_or (p, m, __ATOMIC_SEQ_CST);
+  return (n & m) == 0;
+}
+
+int
+main ()
+{
+  unsigned long v = 1;
+  if (foo (&v) != 1)
+    __builtin_abort ();
+  return 0;
+}