https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127104
Bug ID: 127104
Summary: modref doesn't recognize loads in assume bodies
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: jmelcr at gcc dot gnu.org
Target Milestone: ---
Found this while working on ipa improvements for assumes. Consider the
following testcase:
```
void do_something();
struct S {
int x, y;
};
inline bool
bar (int x, int y)
{
return x < y;
}
static bool
__attribute__((noinline))
foo (struct S *s)
{
[[assume (bar (s->x, s->y))]];
bool ret = s->x < 42;
return ret;
}
void baz (int x) {
struct S s{x, 42};
bool should_do_something = foo (&s);
if (should_do_something)
do_something();
}
```
>From the dse1 dump when compiling with `-O3 -fdump-tree-dse1-details`:
ipa-modref: call stmt should_do_something_16 = foo (&s);
ipa-modref: call to bool foo(S*)/2 does not use ref: s.y alias sets: 2->1
Deleted dead store: s.y = 42;
Modref apparently doesn't take the assumption into consideration. The store
technically is dead, as the assumption won't make it into the final code, but I
think that deleting the store this early on is incorrect, or at the very least,
we rob ourselves of optimization opportunities.
Currently trying to fix this myself, without much luck though.