Honza requested this after reviewing the patch that taught IPA-SRA
that REFERENCE_TYPEs are always non-NULL that the pass also handles
the first parameters of methods, this pointers, in the same way. So
this patch does that.
gcc/ChangeLog:
2022-12-14 Martin Jambor <mjambor@suse.cz>
* ipa-sra.cc (create_parameter_descriptors): Consider the first
parameter of a method safe to dereference.
gcc/testsuite/ChangeLog:
2022-12-14 Martin Jambor <mjambor@suse.cz>
* g++.dg/ipa/ipa-sra-6.C: New test.
if (POINTER_TYPE_P (type))
{
desc->by_ref = true;
- desc->safe_ref = (TREE_CODE (type) == REFERENCE_TYPE);
+ if (TREE_CODE (type) == REFERENCE_TYPE
+ || (num == 0
+ && TREE_CODE (TREE_TYPE (node->decl)) == METHOD_TYPE))
+ desc->safe_ref = true;
+ else
+ desc->safe_ref = false;
type = TREE_TYPE (type);
if (TREE_CODE (type) == FUNCTION_TYPE
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-sra" } */
+
+namespace {
+
+class C
+{
+
+ int mi;
+
+public:
+ C (int i)
+ : mi(i)
+ {}
+
+ void foo (int c);
+};
+
+volatile int vi;
+
+
+void __attribute__((noinline))
+C::foo (int cond)
+{
+ int i;
+ if (cond)
+ i = mi;
+ else
+ i = 0;
+ vi = i;
+}
+
+static C c_instance(1);
+}
+
+void __attribute__((noinline))
+bar (C *p, int cond)
+{
+ p->foo (cond);
+}
+
+
+class C *gp;
+
+void something(void);
+
+void
+baz (int cond)
+{
+ C c(vi);
+ gp = &c;
+ something ();
+ bar (gp, cond);
+}
+
+void
+hoo(void)
+{
+ gp = &c_instance;
+}
+
+/* { dg-final { scan-ipa-dump "Will split parameter" "sra" } } */