-fmerge-all-constants enabled by default (PR18538)


The non-conforming optimization -fmerge-all-constants is currently enabled by default. That seems surprising, and against our usual approach of trying to be correct by default. Is there some code for which this is critically important (perhaps without it, the stack usage at -O0 is unacceptable)?

Can we turn this off by default, or failing that, document very prominently that we’re not conforming, and explain why? (I’m happy to update the documentation if someone can provide a good reason for the behavior.)


Back when it was added, there was a reasonably strong arguement that the
standard was wrong and we would like to permit this optimization. Maybe, if
we can resurrect some of these arguments, we can help take a proposal to
the committee?

I think Tanya was actually involved with getting this in originally, but
perhaps my memory is deeply flawed here.

The behavior in clang was added in r85991 by Tanya.

Before we had unnamed_addr llvm used to merge every constant, so this
might be vestigial. Having said that, it is a bit surprising to see a
memcpy in

int g(const unsigned *p);
void f() {
  const unsigned foo[] = {1, 2, 3, 4};

So I think we should introduce a warning for it if we are to change the default.