From d37a91e5c57c518c91de2e570fdbf9d96f90dd41 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 26 Jun 2018 13:35:52 +0200 Subject: [PATCH] re PR target/86314 (GCC 7.x and 8.x zero out "eax" before using "rax" in "lock bts") 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 | 7 +++++++ gcc/config/i386/i386.md | 4 ++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/pr86314.c | 20 ++++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr86314.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ec68212bc0a..13b648cab29 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2018-06-26 Jakub Jelinek + + 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 PR tree-optimization/86287 diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 6f2300057aa..559ad9334a7 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -12761,6 +12761,7 @@ "(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)) @@ -12786,6 +12787,7 @@ || 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)" @@ -12835,6 +12837,7 @@ "(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)) @@ -12861,6 +12864,7 @@ || 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)" diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7aea7efb21f..3931bfe8525 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2018-06-26 Jakub Jelinek + 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 index 00000000000..8962a3cf2ff --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr86314.c @@ -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; +} -- 2.30.2