Skip to content

Commit 2872937

Browse files
committed
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. (cherry picked from commit 08e752e)
1 parent 026ecb9 commit 2872937

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

gcc/config/avr/avr.cc

+6
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,12 @@ avr_option_override (void)
11121112
if (targetm.addr_space.zero_address_valid (ADDR_SPACE_GENERIC))
11131113
flag_delete_null_pointer_checks = 0;
11141114

1115+
/* PR ipa/92606: Inter-procedural analysis optimizes data across
1116+
address-spaces and PROGMEM. As of v14, the PROGMEM part is
1117+
still not fixed (and there is still no target hook as proposed
1118+
in PR92932). Just disable respective bogus optimization. */
1119+
flag_ipa_icf_variables = 0;
1120+
11151121
if (flag_pic == 1)
11161122
warning (OPT_fpic, "%<-fpic%> is not supported");
11171123
if (flag_pic == 2)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* { dg-do run } */
2+
3+
typedef __UINT16_TYPE__ uint16_t;
4+
typedef __UINT32_TYPE__ uint32_t;
5+
6+
typedef uint32_t T;
7+
8+
#define NI __attribute__((noinline,noclone))
9+
10+
11+
#ifndef __AVR_TINY__
12+
#define read_u32(X) \
13+
(__extension__( \
14+
{ \
15+
uint16_t __addr16 = (uint16_t)(X); \
16+
uint32_t __result; \
17+
__asm__ __volatile__ ("lpm %A0, Z+" "\n\t" \
18+
"lpm %B0, Z+" "\n\t" \
19+
"lpm %C0, Z+" "\n\t" \
20+
"lpm %D0, Z" "\n\t" \
21+
: "=r" (__result), "+z" (__addr16)); \
22+
__result; \
23+
}))
24+
#else
25+
NI uint32_t read_u32 (const uint32_t *p)
26+
{
27+
return *p;
28+
}
29+
#endif
30+
31+
static const __attribute((progmem)) T xyz_prog[] = { 123, 123, 123 };
32+
T xyz[] = { 123, 123, 123 };
33+
volatile int x = 0;
34+
35+
NI void prf (T f)
36+
{
37+
if (f != 123)
38+
__builtin_abort();
39+
}
40+
41+
NI void func_progmem()
42+
{
43+
prf (read_u32 (&xyz_prog[0]));
44+
}
45+
46+
NI void func_ram()
47+
{
48+
prf (xyz[x]);
49+
}
50+
51+
int main (void)
52+
{
53+
func_progmem();
54+
func_ram();
55+
56+
return 0;
57+
}

0 commit comments

Comments
 (0)