[Bug optimization/14272] [tree-ssa] miscompilation of __exchange_and_add (atomicity.h)

dnovillo at redhat dot com gcc-bugzilla@gcc.gnu.org
Wed Feb 25 18:06:00 GMT 2004


------- Additional Comments From dnovillo at redhat dot com  2004-02-25 18:06 -------
Subject: Re:  [tree-ssa] miscompilation of
	__exchange_and_add (atomicity.h)

On Wed, 2004-02-25 at 09:06, amacleod at redhat dot com wrote:
> ------- Additional Comments From amacleod at redhat dot com  2004-02-25 14:06 -------
> Hmm.
> 
> __exchange_and_add (__mem, __val)
> {
>   int __tmp;
>   int __result;
>   int T.1;
>   int T.0;
> 
>   # BLOCK 0
>   # PRED: ENTRY [100.0%]  (fallthru,exec)
>   __result_2 = *__mem_1;
>   T.0_3 = *__mem_1;
>   T.1_5 = T.0_3 + __val_4;
>   *__mem_1 = T.1_5;
>   return __result_2;
>   # SUCC: EXIT [100.0%]
> 
> }
> 
> Since there are dereferences to memory and a store to memory here, ought there
> not be a virtual operand of some sort to prevent the movement of the
> dereferences past the store?
> 
I had missed the fact that those statements are examining volatile
storage.  It looks like TER was not using all the data flow
information.  We don't add operands to volatile variables, we mark the
statement with 'has_volatile_ops'.  This is to make passes ignore them.

We *could* add operands, but it would be a waste of space because the
passes would again have to check for volatility.  An alternative to
this, would involve having special virtual operands for volatile
variables or have the SSA renamer give them a special version number
(like zero).

But it always involves the optimizers checking for these markers, so it
seems easiest to just mark the statement as having volatile ops.

Fixed with this.  Andrew, am I missing anything else?  This seemed to be
the only spot where TER looked at statements.


$ cvs diff -dcp tree-ssa.c
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.205
diff -d -c -p -r1.1.4.205 tree-ssa.c
*** tree-ssa.c  25 Feb 2004 03:22:47 -0000      1.1.4.205
--- tree-ssa.c  25 Feb 2004 18:05:26 -0000
*************** find_replaceable_in_bb (temp_expr_table_
*** 2390,2395 ****
--- 2390,2399 ----
        stmt = bsi_stmt (bsi);
        ann = stmt_ann (stmt);

+       /* If the statement has volatile operands, it can be replaced.  */
+       if (ann->has_volatile_ops)
+       continue;
+
        /* Determine if this stmt finishes an existing expression.  */
        uses = USE_OPS (ann);
        num = NUM_USES (uses);




-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14272



More information about the Gcc-bugs mailing list