Attached please find two dumps t.c.032t.mergephi1 and t.c.033t.cddce1.
The assignment is present in the former while it disappears in the
latter. The latter dump is the output of the dead code elimination
pass pass_cd_dce. So this is indeed an instance of dead code elimination.

But may be you are right, what facilitate dead code elimination
be based on modification of read-only data. However, if that is
the case, I wonder what is the reason why change happens when s is
an array...


Daniel Jacobowitz wrote, On Tuesday 14 September 2010 11:54 PM:
On Tue, Sep 14, 2010 at 11:50:11PM +0530, Uday P. Khedker wrote:
The point is: in your program is is only a pointer. When you pass s
as a parameter to printf, the compiler assumes that only s is being
used so the (effective) assignment

    *s = 'H'

is deleted as dead code when optimization is enabled.

No, this is incorrect.  The issue must be specific to modification of
read-only data.

;; Function printf (printf)

printf (const char * restrict __fmt)
{
  int D.1913;

<bb 2>:
  D.1913_2 = __printf_chk (1, __fmt_1(D), __builtin_va_arg_pack ());
  return D.1913_2;

}



;; Function main (main)

main ()
{
  int D.2657;
  int D.2657;
  int D.2654;
  int D.2654;
  const char * restrict D.2648;

<bb 2>:
  D.2648_2 = (const char * restrict) "%s\n";
  D.2654_5 = __printf_chk (1, D.2648_2, &"hello"[0]);
  "hello"[0] = 72;
  D.2648_3 = (const char * restrict) "%s\n";
  D.2657_6 = __printf_chk (1, D.2648_3, &"hello"[0]);
  return 0;

}


;; Function printf (printf)

printf (const char * restrict __fmt)
{
  int D.1913;

<bb 2>:
  D.1913_2 = __printf_chk (1, __fmt_1(D), __builtin_va_arg_pack ());
  return D.1913_2;

}



;; Function main (main)

main ()
{
  const char * restrict D.2648;

<bb 2>:
  D.2648_2 = (const char * restrict) "%s\n";
  __printf_chk (1, D.2648_2, &"hello"[0]);
  D.2648_3 = (const char * restrict) "%s\n";
  __printf_chk (1, D.2648_3, &"hello"[0]);
  return 0;

}


Reply via email to