This is an archive of the discontinued LLVM Phabricator instance.

Always run GlobalDCE at O0
Needs ReviewPublic

Authored by mehdi_amini on Dec 7 2016, 6:22 PM.

Details

Reviewers
chandlerc
Summary

Clang can emit unreachable call-graph from valid C++ code. There
is no point keeping this into the binary, and also sometimes the
generated code is broken and does not link, for example:

#include <iostream>
#include <string>
namespace {

	struct VA {
	};
	struct A : virtual public VA {
		A() {
			static bool b = false;
			std::string str;
		}
	};

}
int main(int argc, char* argv[]) {

	A::A a;

}

See: http://lists.llvm.org/pipermail/cfe-dev/2016-October/051152.html

Event Timeline

mehdi_amini updated this revision to Diff 80706.Dec 7 2016, 6:22 PM
mehdi_amini retitled this revision from to Always run GlobalDCE at O0.
mehdi_amini updated this object.
mehdi_amini added a reviewer: chandlerc.
mehdi_amini added subscribers: llvm-commits, dexonsmith.

Note: I ran CTMark and didn't see a meaningful difference (in the noise, mostly small improvements, largest was 0.49%)

chandlerc edited edge metadata.Dec 13 2016, 5:25 PM

Personally, I would much rather teach Clang to not emit code than run a pass at O0. I really would like to preserve the ability to use O0 to understand why LLVM is misbehaving.

(The fact that we need to run the always inliner at O0 is already somewhat frustrating, I think it makes sense to resist worsening that situation.)

Another reason -O0 isn't great / enough to debug when LLVM is misbehaving is that it impacts the clang codegen (lifetime intrinsics, etc.).

Another reason -O0 isn't great / enough to debug when LLVM is misbehaving is that it impacts the clang codegen (lifetime intrinsics, etc.).

But you're changing *opt*, not Clang.

I really think that we shouldn't add passes to -O0...

I am sympathetic to wanting a developer "friendly" mode in the compiler that does some cleanup by not too much so as to confuse things or slow anything down. But:

  1. I don't think GlobalDCE is nearly enough.
  2. I don't think it should be spelled '-O0'. I actually think this is what -O1 should be.

Another reason -O0 isn't great / enough to debug when LLVM is misbehaving is that it impacts the clang codegen (lifetime intrinsics, etc.).

But you're changing *opt*, not Clang.

I really think that we shouldn't add passes to -O0...

Well if you expect opt -O0 to not run any pass, then it is fairly easy to achieve in opt: do not invoke the PM builder when OptLevel == 0 :)
(But that defeats the point of -O0 in opt, it actually wouldn't do *anything*)

I am sympathetic to wanting a developer "friendly" mode in the compiler

Note that my motivation to submit this is not that, it is a (admittedly lame) approach to fix a build failure related to us not processing always_inline functions.