diff options
author | Jason Merrill <jason@redhat.com> | 2016-02-24 10:18:04 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2016-02-24 10:18:04 -0500 |
commit | a021961c055d4d056d8bd7875a93c5e53450afd9 (patch) | |
tree | 66d1ebef423cc0ae9ed52f94ce534df41312b6f8 /gcc | |
parent | 28577b86833bdb2e5241790f233fd2503ab4f880 (diff) | |
download | gcc-a021961c055d4d056d8bd7875a93c5e53450afd9.zip gcc-a021961c055d4d056d8bd7875a93c5e53450afd9.tar.gz gcc-a021961c055d4d056d8bd7875a93c5e53450afd9.tar.bz2 |
Add -flifetime-dse=1.
gcc/
* common.opt (flifetime-dse): Add -flifetime-dse=1.
gcc/cp/
* decl.c (start_preparsed_function): Condition ctor clobber on
flag_lifetime_dse > 1.
From-SVN: r233672
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/common.opt | 5 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/cp/decl.c | 3 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/opt/flifetime-dse4.C | 27 |
6 files changed, 44 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0c2c960..913abc8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2016-02-24 Jason Merrill <jason@redhat.com> + + * common.opt (flifetime-dse): Add -flifetime-dse=1. + 2016-02-24 Richard Biener <rguenther@suse.de> Jakub Jelinek <jakub@redhat.com> diff --git a/gcc/common.opt b/gcc/common.opt index bc5b4c4..e91f225 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1946,10 +1946,13 @@ Common Ignore Does nothing. Preserved for backward compatibility. flifetime-dse -Common Report Var(flag_lifetime_dse) Init(1) Optimization +Common Report Var(flag_lifetime_dse,2) Init(2) Optimization Tell DSE that the storage for a C++ object is dead when the constructor starts and when the destructor finishes. +flifetime-dse= +Common Joined RejectNegative UInteger Var(flag_lifetime_dse) Optimization + flive-range-shrinkage Common Report Var(flag_live_range_shrinkage) Init(0) Optimization Relief of register pressure through live range shrinkage. diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 582fd07..6212d43 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2016-02-24 Jason Merrill <jason@redhat.com> + * decl.c (start_preparsed_function): Condition ctor clobber on + flag_lifetime_dse > 1. + * cp-gimplify.c (cp_fold): Don't fold constexpr calls if -fno-inline. 2016-02-19 Jason Merrill <jason@redhat.com> diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 30eef5c..2df3398 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -14104,7 +14104,8 @@ start_preparsed_function (tree decl1, tree attrs, int flags) store_parm_decls (current_function_parms); if (!processing_template_decl - && flag_lifetime_dse && DECL_CONSTRUCTOR_P (decl1) + && (flag_lifetime_dse > 1) + && DECL_CONSTRUCTOR_P (decl1) /* We can't clobber safely for an implicitly-defined default constructor because part of the initialization might happen before we enter the constructor, via AGGR_INIT_ZERO_FIRST (c++/68006). */ diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 9ca3793..b8b2e70 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -6809,7 +6809,10 @@ value, and any changes during the lifetime of the object are dead when the object is destroyed. Normally dead store elimination will take advantage of this; if your code relies on the value of the object storage persisting beyond the lifetime of the object, you can use this -flag to disable this optimization. +flag to disable this optimization. To preserve stores before the +constructor starts (e.g. because your operator new clears the object +storage) but still treat the object as dead after the destructor you, +can use -flifetime-dse=1. @item -flive-range-shrinkage @opindex flive-range-shrinkage diff --git a/gcc/testsuite/g++.dg/opt/flifetime-dse4.C b/gcc/testsuite/g++.dg/opt/flifetime-dse4.C new file mode 100644 index 0000000..c72444a --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/flifetime-dse4.C @@ -0,0 +1,27 @@ +// { dg-options "-O3 -flifetime-dse=1" } +// { dg-do run } + +typedef __SIZE_TYPE__ size_t; +inline void * operator new (size_t, void *p) { return p; } + +struct A +{ + int i; + A() {} + ~A() {} +}; + +int main() +{ + int ar[1] = { 42 }; + A* ap = new(ar) A; + + // With -flifetime-dse=1 we retain the old value. + if (ap->i != 42) __builtin_abort(); + + ap->i = 42; + ap->~A(); + + // When the destructor ends the object no longer exists. + if (ar[0] == 42) __builtin_abort(); +} |