From a8b7129f6ad7ce052e661eee4dca9345c0a9675a Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 26 Jun 2018 13:54:29 +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: r262144 --- gcc/ChangeLog | 7 +++++++ gcc/config/i386/i386.md | 2 ++ gcc/testsuite/ChangeLog | 5 +++++ 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 e6f90dae8190..2156085dec63 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-25 Michael Meissner Back port from trunk diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 8469cf02510c..c5dae5ffe7d2 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -11787,6 +11787,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)) @@ -11833,6 +11834,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)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 40ce62b0a7c9..33595511eb02 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-06-26 Jakub Jelinek + + PR target/86314 + * gcc.dg/pr86314.c: New test. + 2018-06-25 Fritz Reese PR fortran/82972 diff --git a/gcc/testsuite/gcc.dg/pr86314.c b/gcc/testsuite/gcc.dg/pr86314.c new file mode 100644 index 000000000000..8962a3cf2ff7 --- /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.47.2