libgcc's __xload_1...4 is clobbering Z (and also R21 is some cases), but avr.md had clobbers of respective GPRs only up to reload. Outcome was that code reading from the same __memx address twice could be wrong. This patch adds respective clobbers.
Applied as obvious. Johann -- AVR: target/119989 - Add missing clobbers to xload_<mode>_libgcc. libgcc's __xload_1...4 is clobbering Z (and also R21 is some cases), but avr.md had clobbers of respective GPRs only up to reload. Outcome was that code reading from the same __memx address twice could be wrong. This patch adds respective clobbers. PR target/119989 gcc/ * config/avr/avr.md (xload_<mode>_libgcc): Clobber R21, Z. gcc/testsuite/ * gcc.target/avr/torture/pr119989.h: New file. * gcc.target/avr/torture/pr119989-memx-1.c: New test. * gcc.target/avr/torture/pr119989-memx-2.c: New test. * gcc.target/avr/torture/pr119989-memx-3.c: New test. * gcc.target/avr/torture/pr119989-memx-4.c: New test.
AVR: target/119989 - Add missing clobbers to xload_<mode>_libgcc. libgcc's __xload_1...4 is clobbering Z (and also R21 is some cases), but avr.md had clobbers of respective GPRs only up to reload. Outcome was that code reading from the same __memx address twice could be wrong. This patch adds respective clobbers. PR target/119989 gcc/ * config/avr/avr.md (xload_<mode>_libgcc): Clobber R21, Z. gcc/testsuite/ * gcc.target/avr/torture/pr119989.h: New file. * gcc.target/avr/torture/pr119989-memx-1.c: New test. * gcc.target/avr/torture/pr119989-memx-2.c: New test. * gcc.target/avr/torture/pr119989-memx-3.c: New test. * gcc.target/avr/torture/pr119989-memx-4.c: New test. diff --git a/gcc/config/avr/avr.md b/gcc/config/avr/avr.md index 823fc716f2c..e07626dc109 100644 --- a/gcc/config/avr/avr.md +++ b/gcc/config/avr/avr.md @@ -674,12 +674,16 @@ (define_insn_and_split "xload_<mode>_libgcc" [(parallel [(set (reg:MOVMODE 22) (mem:MOVMODE (lo_sum:PSI (reg:QI 21) (reg:HI REG_Z)))) + (clobber (reg:QI 21)) + (clobber (reg:HI REG_Z)) (clobber (reg:CC REG_CC))])]) (define_insn "*xload_<mode>_libgcc" [(set (reg:MOVMODE 22) (mem:MOVMODE (lo_sum:PSI (reg:QI 21) (reg:HI REG_Z)))) + (clobber (reg:QI 21)) + (clobber (reg:HI REG_Z)) (clobber (reg:CC REG_CC))] "avr_xload_libgcc_p (<MODE>mode) && reload_completed" diff --git a/gcc/testsuite/gcc.target/avr/torture/pr119989-memx-1.c b/gcc/testsuite/gcc.target/avr/torture/pr119989-memx-1.c new file mode 100644 index 00000000000..27b89e437bd --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/torture/pr119989-memx-1.c @@ -0,0 +1,6 @@ +/* { dg-do run { target { ! avr_tiny } } } */ +/* { dg-additional-options "-std=gnu99" } */ + +typedef __UINT8_TYPE__ TYP; + +#include "pr119989.h" diff --git a/gcc/testsuite/gcc.target/avr/torture/pr119989-memx-2.c b/gcc/testsuite/gcc.target/avr/torture/pr119989-memx-2.c new file mode 100644 index 00000000000..a8011a25b83 --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/torture/pr119989-memx-2.c @@ -0,0 +1,6 @@ +/* { dg-do run { target { ! avr_tiny } } } */ +/* { dg-additional-options "-std=gnu99" } */ + +typedef __UINT16_TYPE__ TYP; + +#include "pr119989.h" diff --git a/gcc/testsuite/gcc.target/avr/torture/pr119989-memx-3.c b/gcc/testsuite/gcc.target/avr/torture/pr119989-memx-3.c new file mode 100644 index 00000000000..ea1c4b62c04 --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/torture/pr119989-memx-3.c @@ -0,0 +1,6 @@ +/* { dg-do run { target { ! avr_tiny } } } */ +/* { dg-additional-options "-std=gnu99" } */ + +__extension__ typedef __uint24 TYP; + +#include "pr119989.h" diff --git a/gcc/testsuite/gcc.target/avr/torture/pr119989-memx-4.c b/gcc/testsuite/gcc.target/avr/torture/pr119989-memx-4.c new file mode 100644 index 00000000000..32b5cd3b55f --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/torture/pr119989-memx-4.c @@ -0,0 +1,6 @@ +/* { dg-do run { target { ! avr_tiny } } } */ +/* { dg-additional-options "-std=gnu99" } */ + +typedef __UINT32_TYPE__ TYP; + +#include "pr119989.h" diff --git a/gcc/testsuite/gcc.target/avr/torture/pr119989.h b/gcc/testsuite/gcc.target/avr/torture/pr119989.h new file mode 100644 index 00000000000..ab9d14a208b --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/torture/pr119989.h @@ -0,0 +1,37 @@ +const __memx TYP some_data[] = { 1, 2, 3, 4, 5 }; +const __memx TYP *IP; + +TYP DT, a, b; + +__attribute__((noipa)) +void do_test1 (void) +{ + DT = *IP; + DT = *IP--; +} + +__attribute__((noipa)) +void do_test2 (void) +{ + DT = *IP; + __asm volatile ("" ::: "memory"); // Prevents unwanted optimization + DT = *IP--; +} + +TYP difference(void) +{ + IP = &some_data[3]; + do_test1(); + a = DT; + IP = &some_data[3]; + do_test2(); + b = DT; + return a - b; // Expected: 0 +} + +int main (void) +{ + if (difference () != 0) + __builtin_exit (__LINE__); + return 0; +}