This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] if-conversion of loops with conditionals containing memory loads and stores
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Jeff Law <law at redhat dot com>
- Cc: Sebastian Pop <sebpop at gmail dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Guenther <rguenther at suse dot de>
- Date: Wed, 23 Jun 2010 19:04:53 +0000 (UTC)
- Subject: Re: [patch] if-conversion of loops with conditionals containing memory loads and stores
- References: <AANLkTilFiv9bzm6E8LACu5-S7twh6w6uB2c91tgjMIAP@mail.gmail.com> <4C223632.2000701@redhat.com>
On Wed, 23 Jun 2010, Jeff Law wrote:
> On 06/22/10 14:17, Sebastian Pop wrote:
> > Hi,
> >
> > The attached patches (on top of the previous patch set) are needed to
> > if-convert the DCT loop kernel of FFmpeg.
> >
> > 0009 replaces the memory writes that are in predicated basic blocks
> > with a full write: "if (cond) A[i] = foo" is replaced with "A[i] =
> > cond ? foo : A[i]". In order to do this, the patch replaces the call
> > to gimple_assign_rhs_could_trap_p with gimple_could_trap_p, as we now
> > have to check that the LHS of assign stmts in conditions do not trap.
> >
> Doesn't this run afoul of the C++0x memory model?
Not just the C++0x memory model, but you also need to be sure that A[i] is
a valid pointer to writable memory - not an out-of-range or unaligned
pointer (if A[i] is always *read*, you can be sure of that, and simply
forming the address &A[i] means it is either valid or one past the end of
an array), not a pointer to readonly memory (remember that in C it's valid
to cast a pointer-to-const to pointer-to-non-const, so just because the
target type isn't const qualified doesn't mean you can actually write to
the memory). You need to exclude the case that A[i] is not writable or
not a valid pointer in some cases when cond is false (but is always
writable and valid when cond is true). I don't know if
gimple_could_trap_p makes sufficient checks for this.
--
Joseph S. Myers
joseph@codesourcery.com