ipa: Avoid IPA confusing scalar values and single-field aggregates (PR 108679)
authorMartin Jambor <mjambor@suse.cz>
Wed, 15 Feb 2023 10:38:01 +0000 (11:38 +0100)
committerMartin Jambor <mjambor@suse.cz>
Wed, 15 Feb 2023 10:38:07 +0000 (11:38 +0100)
PR 108679 testcase shows a situation when IPA-CP is able to track a
scalar constant in a single-field structure that is part of a bigger
structure.  This smaller structure is however also passed in a few
calls to other functions, but the two same-but-different entities,
originally placed at the same offset and with the same size, confuse
the mechanism that takes care of handling call statements after
IPA-SRA.

I think that in stage 4 it is best to revert to GCC 12 behavior in this
particular case (when IPA-CP detects a constant in a single-field
structure or a single element array that is part of a bigger aggregate)
and the patch below does that.  If accepted, I plan to file a
missed-optimization bug to track that we could use the IPA-CP propagated
value to re-construct the small aggregate arguments.

gcc/ChangeLog:

2023-02-13  Martin Jambor  <mjambor@suse.cz>

PR ipa/108679
* ipa-sra.cc (push_param_adjustments_for_index): Do not omit
creation of non-scalar replacements even if IPA-CP knows their
contents.

gcc/testsuite/ChangeLog:

2023-02-13  Martin Jambor  <mjambor@suse.cz>

PR ipa/108679
* gcc.dg/ipa/pr108679.c: New test.

gcc/ipa-sra.cc
gcc/testsuite/gcc.dg/ipa/pr108679.c [new file with mode: 0644]

index 0495f446bf4b82cc467782bf1762f2b7d6002f73..3de7d426b7e7339d16b2ed8a28e88659bbf9562e 100644 (file)
@@ -3989,7 +3989,7 @@ push_param_adjustments_for_index (isra_func_summary *ifs, unsigned base_index,
        {
          ipa_argagg_value_list avl (ipcp_ts);
          tree value = avl.get_value (base_index, pa->unit_offset);
-         if (value)
+         if (value && !AGGREGATE_TYPE_P (pa->type))
            {
              if (dump_file)
                fprintf (dump_file, "    - omitting component at byte "
diff --git a/gcc/testsuite/gcc.dg/ipa/pr108679.c b/gcc/testsuite/gcc.dg/ipa/pr108679.c
new file mode 100644 (file)
index 0000000..b1ed50b
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+struct S1 {
+  signed f0;
+};
+struct S2 {
+  struct S1 f2;
+  short f8;
+} g_18;
+void safe_lshift_func_int16_t_s_u();
+void safe_unary_minus_func_uint64_t_u();
+int safe_mul_func_uint8_t_u_u(int, struct S1 p_14);
+int g_732, func_6_l_17;
+static int *func_12();
+static int func_6(struct S2 p_7) { func_12(func_6_l_17, p_7.f2, g_18, 0); }
+static int *func_12(int, struct S1 p_14) {
+  safe_lshift_func_int16_t_s_u();
+  safe_unary_minus_func_uint64_t_u();
+  g_732 = safe_mul_func_uint8_t_u_u(0, p_14);
+}
+int main() {
+  struct S2 l_10 = {3};
+  func_6(l_10);
+}