aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Pinski <quic_apinski@quicinc.com>2024-08-01 10:33:34 -0700
committerAndrew Pinski <quic_apinski@quicinc.com>2024-08-02 02:58:23 -0700
commit33baa20c5cdcf5ff8164606115f00aa30f559312 (patch)
tree75e5c28388a860850e10e38e580a6fe1c4530431
parent4b9ba9cee9511930411b7b53e1333e1b6b93078d (diff)
downloadgcc-33baa20c5cdcf5ff8164606115f00aa30f559312.zip
gcc-33baa20c5cdcf5ff8164606115f00aa30f559312.tar.gz
gcc-33baa20c5cdcf5ff8164606115f00aa30f559312.tar.bz2
forwprop: Don't add uses to dce list if debug statement [PR116156]
The problem here is that when forwprop does a copy prop, into a statement, we mark the uses of that statement as possibly need to be removed. But it just happened that statement was a debug statement, there will be a difference when compiling with debuging info turned on vs off; this is not expected. So the fix is not to add the old use to dce list to process if it was a debug statement. Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/116156 gcc/ChangeLog: * tree-ssa-forwprop.cc (pass_forwprop::execute): Don't add uses if the statement was a debug statement. gcc/testsuite/ChangeLog: * c-c++-common/torture/pr116156-1.c: New test. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
-rw-r--r--gcc/testsuite/c-c++-common/torture/pr116156-1.c30
-rw-r--r--gcc/tree-ssa-forwprop.cc16
2 files changed, 39 insertions, 7 deletions
diff --git a/gcc/testsuite/c-c++-common/torture/pr116156-1.c b/gcc/testsuite/c-c++-common/torture/pr116156-1.c
new file mode 100644
index 0000000..10f938e
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/pr116156-1.c
@@ -0,0 +1,30 @@
+/* { dg-additional-options "-fcompare-debug" } */
+/* PR tree-optimization/116156 */
+
+/* Forwprop used to delete an unused statement
+ but only with debug statements around. */
+
+struct jpeg_compress_struct {
+ int X_density;
+};
+void gg();
+int h(const char*,const char*) __attribute((pure));
+int h1(const char*) __attribute((pure));
+int f1() __attribute__((returns_twice));
+void real_save_jpeg(char **keys, char *values) {
+ struct jpeg_compress_struct cinfo;
+ int x_density = 0;
+ while (*keys)
+ {
+ if (h1(*keys) == 0)
+ gg();
+ if (h1(*keys) == 0) {
+ if (!*values)
+ x_density = -1;
+ if (x_density <= 0)
+ gg();
+ }
+ }
+ if (f1())
+ cinfo.X_density = x_density;
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 44a6b5d..2e37642 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -3923,7 +3923,8 @@ pass_forwprop::execute (function *fun)
tree val = fwprop_ssa_val (use);
if (val && val != use)
{
- bitmap_set_bit (simple_dce_worklist, SSA_NAME_VERSION (use));
+ if (!is_gimple_debug (stmt))
+ bitmap_set_bit (simple_dce_worklist, SSA_NAME_VERSION (use));
if (may_propagate_copy (use, val))
{
propagate_value (usep, val);
@@ -3963,12 +3964,13 @@ pass_forwprop::execute (function *fun)
if (gimple_cond_true_p (cond)
|| gimple_cond_false_p (cond))
cfg_changed = true;
- /* Queue old uses for simple DCE. */
- for (tree use : uses)
- if (TREE_CODE (use) == SSA_NAME
- && !SSA_NAME_IS_DEFAULT_DEF (use))
- bitmap_set_bit (simple_dce_worklist,
- SSA_NAME_VERSION (use));
+ /* Queue old uses for simple DCE if not debug statement. */
+ if (!is_gimple_debug (stmt))
+ for (tree use : uses)
+ if (TREE_CODE (use) == SSA_NAME
+ && !SSA_NAME_IS_DEFAULT_DEF (use))
+ bitmap_set_bit (simple_dce_worklist,
+ SSA_NAME_VERSION (use));
}
if (changed || substituted_p)