Thread-safe profiling

Jan Hubicka hubicka@ucw.cz
Thu Mar 15 15:06:00 GMT 2007


> Hi,
> 
> On Thu, 15 Mar 2007, Jan Hubicka wrote:
> 
> > > @@ -5717,8 +5717,10 @@ expand_builtin_sync_operation (enum mach
> > >    mem = get_builtin_sync_mem (CALL_EXPR_ARG (exp, 0), mode);
> > > 
> > >    val = expand_expr (CALL_EXPR_ARG (exp, 1), NULL, mode, EXPAND_NORMAL);
> > > -  /* If VAL is promoted to a wider mode, convert it back to MODE.  */
> > > -  val = convert_to_mode (mode, val, 1);
> > > +  /* If VAL is promoted to a wider mode, convert it back to MODE.
> > > +     Not for CONST_INTs though.  */
> > > +  if (GET_MODE (val) != VOIDmode)
> > > +    val = convert_to_mode (mode, val, 1);
> > > 
> > >    if (ignore)
> > >      return expand_sync_operation (mem, val, code);
> > > 
> > > 
> > > Without this change, this call will be miscompiled on 32bit hosts:
> > > 
> > > __sync_fetch_and_add_8 (ptr, -(unsigned long long)1);
> > > 
> > > Because the -1LL will be 0xffffffffffffffff in the tree expression.  Now 
> > > the expand_expr call above will turn that tree constant into a RTL 
> > > constant, namely (const_int -1 [0xffffffff]), that is correct as far as I 
> > > can see, as RTL constants are implicitely sign extended.
> > > 
> > > Now, without my change the convert_to_mode() call will turn that RTL 
> > > constant into the wrong 64bit unsigned variant of this (mode is DImode, 
> > > and due to the unsigned flag being set for the convert_to_mode call), 
> > > namely (const_int [0xffffffff] [0] [0] [0]), i.e. it's zero extended.
> > > 
> > > So, my thought was to not call convert_to_mode for CONST_INTs at all, 
> > > which seems what other code sometimes is doing.  This works fine for the 
> > > DImode case, but I'm now seeing e.g. QImode failures :-(
> > 
> > Hmm, is thre reason why convert_modes doesn't work?
> 
> convert_to_mode is just a wrapper around convert_modes.  In the cases at 
> hand (the input is a (const_int), i.e. input mode is VOIDmode) it would be 
> exactly equivalent to convert_modes,

I would expect the input_mode to be TYPE_MODE (TREE_TYPE (CALL_EXPR_ARG (exp, 1)))
or does the promotion happen behind our back?

Honza



More information about the Gcc-patches mailing list