This is an archive of the discontinued LLVM Phabricator instance.

[GlobalOpt] Fix incorrect Modified status
ClosedPublic

Authored by dstenb on Aug 12 2020, 7:26 AM.

Details

Summary

When marking a global variable constant, and simplifying users using
CleanupConstantGlobalUsers(), the pass could incorrectly return false if
there were still some uses left, and no further optimizations was done.

This was caught using the check introduced by D80916.

This fixes PR46749.

Diff Detail

Event Timeline

dstenb created this revision.Aug 12 2020, 7:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2020, 7:26 AM
dstenb requested review of this revision.Aug 12 2020, 7:26 AM
fhahn added a subscriber: fhahn.Sep 1 2020, 2:57 AM
fhahn added inline comments.
llvm/lib/Transforms/IPO/GlobalOpt.cpp
2027–2029

Can GV here be already a constant? If so, we should only set Changed if !GV->isConstant(). Or if it is always non-constant to start with, perhaps add an assert to make sure?

dstenb added inline comments.Sep 1 2020, 6:21 AM
llvm/lib/Transforms/IPO/GlobalOpt.cpp
2027–2029

This can currently not occur, since processGlobal() bails out before calling processInternalGlobal in that case:

if (GVar->isConstant() || !GVar->hasInitializer())
  return Changed;

return processInternalGlobal(GVar, GS, GetTLI, LookupDomTree) || Changed;

I can add an assert to ensure that that contract is upheld between two functions.

fhahn accepted this revision.Sep 1 2020, 12:33 PM

LGTM thanks.

llvm/lib/Transforms/IPO/GlobalOpt.cpp
2027–2029

thanks for checking. IMO it would be good to add an assertion.

This revision is now accepted and ready to land.Sep 1 2020, 12:33 PM
This revision was automatically updated to reflect the committed changes.
dstenb added a comment.Sep 2 2020, 6:03 AM

Thanks for the review!

I landed this with an assert:

+    if (GS.Ordering == AtomicOrdering::NotAtomic) {
+      assert(!GV->isConstant() && "Expected a non-constant global");
       GV->setConstant(true);
+      Changed = true;
+    }