On Sun, Aug 28, 2016 at 7:59 PM, Jan Hubicka <hubi...@ucw.cz> wrote: > Hi, > I have noticed that ivopts build MEM_REF (NOP_EXPR (address)) > where NOP_EXPR converts one pointer type to another. Later it tries > to expand it that on strict alignment targets punt on determining > the alignment and winds expensive memory reference. > > It seems to make no sense to have NOP_EXPR here, but in addition > I think we want to somehow preserve alignment from original MEM_REF?
As you noticed the type carries semantics thus if you want to fix it this way then you need to make build_simple_mem_ref strip the nops _after_ remembering the type to use for the MEM_REF (and the aliasing). After all you are changing *(int *)&large-struct to *&large-struct with your patch - certainly not what you intended? Sth like @@ -4618,6 +4623,7 @@ build_simple_mem_ref_loc (location_t loc HOST_WIDE_INT offset = 0; tree ptype = TREE_TYPE (ptr); tree tem; + STRIP_NOPS (ptr); /* For convenience allow addresses that collapse to a simple base and offset. */ if (TREE_CODE (ptr) == ADDR_EXPR Richard. > Honza > > * tree-ssa-lop-ivopts.c (get_computation_cost_at): > strip nops before building mem ref > diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c > index 62ba71b..bd92031 100644 > --- a/gcc/tree-ssa-loop-ivopts.c > +++ b/gcc/tree-ssa-loop-ivopts.c > @@ -5058,7 +5058,10 @@ fallback: > return infinite_cost; > > if (address_p) > - comp = build_simple_mem_ref (comp); > + { > + STRIP_NOPS (comp); > + comp = build_simple_mem_ref (comp); > + } > > cost = comp_cost (computation_cost (comp, speed), 0); >