------- Comment #3 from jamborm at gcc dot gnu dot org 2008-12-30 16:58 ------- I discussed this bug with Richi on IRC and was told that we should avoid having the statement marked as volatile since it is not an access through a volatile variable in the original source code. Instead, we should try preventing the propagation of &a to uses of p.
The patch is below, it prevents ccp and dom1 from carrying out the propagation. However, fwprop does this propagation, albeit using a VIEW_CONVERT_EXP and, moreover, fold_stmt_inplace() it calls marks the statement volatile anyway. This propagation is performed because fwprop checks types (not decls) for volatility and apparently the type of a is not volatile (as opposed to a[0] which probably is). The declaration of a is volatile though. However, when I changed it to check the declaration, nrv pass did the propagation, creating invalid gimple along the way. Because the such change would possibly be incorrect it is not included below. Anyway, the test case with this patch compiles ans it is possibly slightly more correct, though the final result is not all that different. 2008-12-30 Martin Jambor <mjam...@suse.cz> * tree-ssa-dom.c (cprop_operand): Always check the return value of may_propagate_copy. * tree-ssa-copy.c (may_propagate_copy): Do not allow propagation of addresses of volatile declarations. Index: gcc/tree-ssa-dom.c =================================================================== --- gcc/tree-ssa-dom.c (revision 142962) +++ gcc/tree-ssa-dom.c (working copy) @@ -2092,7 +2092,7 @@ cprop_operand (gimple stmt, use_operand_ /* Certain operands are not allowed to be copy propagated due to their interaction with exception handling and some GCC extensions. */ - else if (!may_propagate_copy (op, val)) + if (!may_propagate_copy (op, val)) return false; /* Do not propagate copies if the propagated value is at a deeper loop Index: gcc/tree-ssa-copy.c =================================================================== --- gcc/tree-ssa-copy.c (revision 142962) +++ gcc/tree-ssa-copy.c (working copy) @@ -73,6 +73,15 @@ may_propagate_copy (tree dest, tree orig && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (dest)) return false; + if (TREE_CODE (orig) == ADDR_EXPR) + { + tree base = TREE_OPERAND (orig, 0); + while (handled_component_p (base)) + base = TREE_OPERAND (base, 0); + if (TREE_THIS_VOLATILE (base)) + return false; + } + /* For memory partitions, copies are OK as long as the memory symbol belongs to the partition. */ if (TREE_CODE (dest) == SSA_NAME -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38645