This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] DCE and aliasing fixes [patch]
> Thanks. I'll have to distinguish between these two cases then.
> Going back to the example I posted:
>
> int foo (int *x)
> {
> return *x;
> }
>
> int bar()
> {
> i = 10;
> p = &i;
> return foo (p);
> }
>
> We are getting a CONST attribute from flags_from_decl_or_type()
> for function foo().
Errr, I don't.
It marks it as pure, nothrow, and libcall_block:
Breakpoint 4, flags_from_decl_or_type (exp=0x40078a10) at
../../gcc/calls.c:795
795 int flags = 0;
(gdb) n
796 tree type = exp;
(gdb)
798 if (DECL_P (exp))
(gdb)
800 type = TREE_TYPE (exp);
(gdb)
803 if (DECL_P (exp) && DECL_IS_MALLOC (exp))
(gdb)
807 if (DECL_P (exp) && DECL_IS_PURE (exp))
(gdb)
808 flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
(gdb)
810 if (TREE_NOTHROW (exp))
(gdb)
811 flags |= ECF_NOTHROW;
(gdb)
814 if (TREE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
(gdb)
817 if (TREE_THIS_VOLATILE (exp))
(gdb)
822 if (TREE_CODE (type) == FUNCTION_TYPE &&
TYPE_RETURNS_STACK_DEPRESSED (type))
(gdb) n
828 return flags;
(gdb) n
829 }
(gdb)
> This was causing the dataflow pass to not
> consider foo() a clobbering function, and since i = 10 had no
> other uses in bar(), it was being killed.
>
> Now that you mention the above paragraph I'm wondering if the
> CONST attribute we're getting from flags_from_decl_or_type()
> only means that the function makes no definitions to its
> arguments.
It shouldn't.
I can't get it to say foo is const.
It's certainly *pure*, and it seems to only say that.
>
> So, if foo() had been declared as a const function, the compiler
> would've been correct to kill the assignment 'i = 10'?
Yup.
foo can't dereference p because it's a const function, and if p
dies (since it's not used), there is no use of i, and thus, i is dead too.
Note, of course, that foo could read p itself.
IE
int *foo (int *x)
{
int *y = x;
y = x + 1;
return y;
}
is a const function (it's only reading x, not what x points to).
>
>
> Thanks. Diego.
>