commit 4795b095eba78ee05f46548fbc9aa9343ff34a7e
Author: Jason Merrill <jason@redhat.com>
Date: Mon Feb 22 15:18:13 2016 -0500
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.
@@ -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.
@@ -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). */
@@ -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
new file mode 100644
@@ -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();
+}