This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] if-conversion of loops with conditionals containing memory loads and stores


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]