Hi,
this patch changes IFN_ASSUME to be pure instead of const.  The const
attribute means (not only) that the function cannot read global memory.
While this is true for the internal call itself, it is only a dispatcher
for the outlined assume body, which may read any memory, e.g. below:

```
struct S
{
  int x, y;
};

void bar (int, int);

bool
foo (struct S *s)
{
  [[assume (bar (s->x, s->y))]];
  return s->x;
}
```

Now, the read does not actually happen in reality, as the assume's body
does not make into the final binary, but the call being marked
incorrectly as const makes our analysis less accurate.

Bootstrapped and regtested on x86_64-linux without regressions.  OK for
master?

Best regards,
Josef

        PR ipa/127104

gcc/ChangeLog:

        * internal-fn.def (ASSUME): Downgrade from const to pure.

Signed-off-by: Josef Melcr <[email protected]>
---
 gcc/internal-fn.def | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def
index af9f92950c7..b1c46a82a52 100644
--- a/gcc/internal-fn.def
+++ b/gcc/internal-fn.def
@@ -633,7 +633,7 @@ DEF_INTERNAL_FN (SHUFFLEVECTOR, ECF_CONST | ECF_LEAF | 
ECF_NOTHROW, NULL)
 DEF_INTERNAL_FN (SPACESHIP, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
 
 /* [[assume (cond)]].  */
-DEF_INTERNAL_FN (ASSUME, ECF_CONST | ECF_LEAF | ECF_NOTHROW
+DEF_INTERNAL_FN (ASSUME, ECF_PURE | ECF_LEAF | ECF_NOTHROW
                         | ECF_LOOPING_CONST_OR_PURE, NULL)
 
 /* For if-conversion of inbranch SIMD clones.  */
-- 
2.55.0

Reply via email to