Hi!

Since r11-2238-ge443d8213864ac337c29092d4767224f280d2062 the C++ FE
emits clobbers like *_1 = {CLOBBER}; where *_1 MEM_REF has some scalar
type like int for -flifetime-dse={1,2} and most of the compiler manages
to cope with that.
If we are very unlucky, we trigger an ICE while trying to regimplify it
(at least during inlining), as happens with GCC 15.2 on firefox-145.0
built with LTO+PGO.
I haven't managed to reduce that to a small testcase that would ICE though,
the clobber certainly appears in code like
template <typename T>
struct S {
  T *p;
  union { char a; T b; };
  static S foo (T *x) { S s; s.p = x; s.b.~T (); return s; }
  ~S ();
};

void
bar ()
{
  int i = 42;
  S <int> s = S <int>::foo (&i);
}
but convincing inliner that it should id->regimplify = true; on exactly
that stmt has been difficult.

The ICE is because we try (in two spots) to regimplify the rhs of the
gimple_clobber_p stmt if gimple-reg-type type (i.e. the TREE_CLOBBER),
because it doesn't satisfy the is_gimple_mem_rhs_or_call predicate
returned by rhs_predicate_for for the MEM_REF lhs.  And regimplify it
by trying to gimplify SSA_NAME = {CLOBBER}; INIT_EXPR and in there reach
a special case which stores that freshly made SSA_NAME into memory and
loads it from memory, so uses a SSA_NAME without SSA_NAME_DEF_STMT.

Fixed thusly by saying clobbers are ok even for the gimple-reg-types.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk
and release branches?

2025-11-11  Jakub Jelinek  <[email protected]>

        PR lto/122620
        * gimplify-me.cc (gimple_regimplify_operands): Don't try to regimplify
        TREE_CLOBBER on rhs of gimple_clobber_p if it has gimple_reg_type.

--- gcc/gimplify-me.cc.jj       2025-10-22 13:30:36.000000000 +0200
+++ gcc/gimplify-me.cc  2025-11-10 15:32:24.747470202 +0100
@@ -232,9 +232,13 @@ gimple_regimplify_operands (gimple *stmt
          else if (i == 2
                   && gimple_assign_single_p (stmt)
                   && num_ops == 2)
-           gimplify_expr (&op, &pre, NULL,
-                          rhs_predicate_for (gimple_assign_lhs (stmt)),
-                          fb_rvalue);
+           {
+             if (gimple_clobber_p (stmt))
+               continue;
+             gimplify_expr (&op, &pre, NULL,
+                            rhs_predicate_for (gimple_assign_lhs (stmt)),
+                            fb_rvalue);
+           }
          else if (i == 2 && is_gimple_call (stmt))
            {
              if (TREE_CODE (op) == FUNCTION_DECL)
@@ -253,8 +257,9 @@ gimple_regimplify_operands (gimple *stmt
        {
          bool need_temp = false;
 
-         if (gimple_assign_single_p (stmt)
-             && num_ops == 2)
+         if (gimple_clobber_p (stmt))
+           ;
+         else if (gimple_assign_single_p (stmt) && num_ops == 2)
            gimplify_expr (gimple_assign_rhs1_ptr (stmt), &pre, NULL,
                           rhs_predicate_for (gimple_assign_lhs (stmt)),
                           fb_rvalue);

        Jakub

Reply via email to