[PATCH] D28404: IRGen: Add optnone attribute on function during O0
Chandler Carruth via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 10 00:42:14 PST 2017
chandlerc added a comment.
In https://reviews.llvm.org/D28404#640862, @probinson wrote:
> In https://reviews.llvm.org/D28404#640682, @mehdi_amini wrote:
> > > I'm now thinking along the lines of a `-foptimize-off` flag (bikesheds welcome) which would set the default for the pragma to 'off'. How is that different than what you wanted for `-O0`? It is defined in terms of an existing pragma, which is WAY easier to explain and WAY easier to implement. And, it still lets us say that `-c -O0 -flto` is a mistake, if that seems like a useful thing to say.
> > Well -O0 being actually "disable optimization", I found "way easier" to handle everything the same way (pragma, command line, etc.). I kind of find it confusing for the user to differentiate `-O0` from `-foptimize=off`. What is supposed to change between the two?
> There is a pedantic difference, rooted in the still-true factoid that O0 != optnone.
> If we redefine LTO as "Link Time Operation" (rather than Optimization; see my reply to Duncan) then `-O0 -flto` is no longer an oxymoron, but using the attribute to imply the optimization level is still not good fidelity to what the user asked for.
I have to say, I don't understand the confusion or problem here...
For me, the arguments you're raising against -O0 and -flto don't hold up on closer inspection:
- O0 != optnone: correct. But this is only visible in LTO. And in LTO, Os != optsize, and Oz != minsize. But we use optsize and minsize to communicate between the compilation and the LTO step to the best of our ability the intent of the programmer. It appears we can use optnone exactly the same way here.
- optnone isn't *really* no optimizations: clearly this is true, but then neither is -O0. We run the always inliner, a couple of other passes, and we run several parts of the code generators optimizer. I understand why optnone deficiencies (ie, too many optimizations) might be frustrating, but having *more users* seems likely to make this *better*.
- There is no use case for -O0 + -flto: I really don't understand this. CFI and other whole program analysis or semantic transformations (*not* optimizations) require LTO but not any particular pipeline. And I *really* want the ability to bisect files going into an LTO build to chase miscompiles. There are large systems built to manipulate flags that are much more efficient and accessible than modifying source code. It seems an entirely reasonable (and quite low cost) feature. The fact that the LTO acronym stands for Link Time Optimization seems like a relatively unimportant thing. It is just an acronym and a name. We shouldn't let it preclude interesting use cases.
But all of this seems like an attempt to argue "you are wrong to have your use case". I personally find that an unproductive line of discussion. I would suggest instead we look at this differently:
For example, you might ask: could we find some other way to solve the problem you are trying to solve here? Suggesting an alternative approach would seem constructive. So far, all we've got is modify source code, but I think that there is a clear explanation of why that doesn't address the particular use case.
You might also ask: is supporting this feature a reasonable maintenance burden for Clang to address the use case? That seems like a productive discussion. For example, I *am* concerned about the increasing attribute noise at -O0. I don't think it is something to be dismissed. However, given the options we have today, it seems like the most effective way to address this use case and I don't have any better ideas to solve the problems Mehdi is solving here.
But I'm also not one of the most active maintainers writing patches, fixing bugs, and improving the IRGen layer. So ultimately, I defer on the maintenance issue to those maintainers.
More information about the cfe-commits