public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch,avr,applied] PR92606: Don't optimize PROGMEM data against non-PROGMEM
@ 2024-05-03 16:58 Georg-Johann Lay
  0 siblings, 0 replies; only message in thread
From: Georg-Johann Lay @ 2024-05-03 16:58 UTC (permalink / raw)
  To: gcc-patches

Applied to fix this long standing wrong-code bug.

Johann

-- 

AVR: ipa/92606 - Don't optimize PROGMEM data against non-PROGMEM.

ipa/92606: Inter-procedural analysis optimizes data across
address-spaces and PROGMEM.  As of v14, the PROGMEM part is
still not fixed (and there is still no target hook as proposed
in PR92932).  Just disable respective bogus optimization.

         PR ipa/92606
gcc/
         * config/avr/avr.cc (avr_option_override): Set
         flag_ipa_icf_variables = 0.
gcc/testsuite/
         * gcc.target/avr/torture/pr92606.c: New test.


diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index 510e4cea19f..74924ab0565 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -1140,6 +1140,12 @@ avr_option_override (void)
    if (targetm.addr_space.zero_address_valid (ADDR_SPACE_GENERIC))
      flag_delete_null_pointer_checks = 0;

+  /* PR ipa/92606: Inter-procedural analysis optimizes data across
+     address-spaces and PROGMEM.  As of v14, the PROGMEM part is
+     still not fixed (and there is still no target hook as proposed
+     in PR92932).  Just disable respective bogus optimization.  */
+  flag_ipa_icf_variables = 0;
+
    if (flag_pic == 1)
      warning (OPT_fpic, "%<-fpic%> is not supported");
    if (flag_pic == 2)
diff --git a/gcc/testsuite/gcc.target/avr/torture/pr92606.c 
b/gcc/testsuite/gcc.target/avr/torture/pr92606.c
new file mode 100644
index 00000000000..cc07128c73b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/avr/torture/pr92606.c
@@ -0,0 +1,57 @@
+/* { dg-do run } */
+
+typedef __UINT16_TYPE__ uint16_t;
+typedef __UINT32_TYPE__ uint32_t;
+
+typedef uint32_t T;
+
+#define NI __attribute__((noinline,noclone))
+
+
+#ifndef __AVR_TINY__
+#define read_u32(X)                                                     \
+    (__extension__(                                                     \
+        {                                                               \
+            uint16_t __addr16 = (uint16_t)(X);                          \
+            uint32_t __result;                                          \
+            __asm__ __volatile__ ("lpm %A0, Z+" "\n\t"                  \
+                                  "lpm %B0, Z+" "\n\t"                  \
+                                  "lpm %C0, Z+" "\n\t"                  \
+                                  "lpm %D0, Z" "\n\t"                   \
+                                  : "=r" (__result), "+z" (__addr16));  \
+            __result;                                                   \
+        }))
+#else
+NI uint32_t read_u32 (const uint32_t *p)
+{
+	return *p;
+}
+#endif
+
+static const __attribute((progmem)) T xyz_prog[] = { 123, 123, 123 };
+T xyz[] = { 123, 123, 123 };
+volatile int x = 0;
+
+NI void prf (T f)
+{
+    if (f != 123)
+        __builtin_abort();
+}
+
+NI void func_progmem()
+{
+    prf (read_u32 (&xyz_prog[0]));
+}
+
+NI void func_ram()
+{
+    prf (xyz[x]);
+}
+
+int main (void)
+{
+    func_progmem();
+    func_ram();
+
+	return 0;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-05-03 16:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-03 16:58 [patch,avr,applied] PR92606: Don't optimize PROGMEM data against non-PROGMEM Georg-Johann Lay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).