This is an archive of the discontinued LLVM Phabricator instance.

[NFC] ConstantMerge: don't insert when find should be used
ClosedPublic

Authored by jfb on Aug 8 2018, 2:06 PM.

Details

Summary

DenseMap's operator[] performs an insertion if the entry isn't found. The second phase of ConstantMerge isn't trying to insert anything: it's just looking to see if the first phased performed an insertion. Use find instead, avoiding insertion of every single global initializer in the map of constants. This has the side-effect of making all entries in CMap non-null (because only global declarations would have null initializers, and that would be a bug).

Diff Detail

Event Timeline

jfb created this revision.Aug 8 2018, 2:06 PM
jfb added a comment.Aug 8 2018, 2:17 PM

To clarify: my intent is that this change be NFC. Updating the title accordingly.

jfb retitled this revision from ConstantMerge: don't insert when find should be used to [NFC] ConstantMerge: don't insert when find should be used.Aug 8 2018, 2:17 PM
This revision is now accepted and ready to land.Aug 8 2018, 4:17 PM
davide accepted this revision.Aug 8 2018, 7:39 PM

LGTM as discussed in person.

This revision was automatically updated to reflect the committed changes.

You could use D.count(V) to save the comparison with end, etc.

jfb added a comment.Aug 13 2018, 10:31 AM

You could use D.count(V) to save the comparison with end, etc.

I don't understand what you're suggesting, could you clarify?

In D50476#1197511, @jfb wrote:

You could use D.count(V) to save the comparison with end, etc.

I don't understand what you're suggesting, could you clarify?

Oh, read the code more - my mistake. Thought you were only testing for whether something was in the container - not actually having to use it afterwards. Carry on!

jfb added a comment.Aug 13 2018, 10:37 AM
In D50476#1197511, @jfb wrote:

You could use D.count(V) to save the comparison with end, etc.

I don't understand what you're suggesting, could you clarify?

Oh, read the code more - my mistake. Thought you were only testing for whether something was in the container - not actually having to use it afterwards. Carry on!

Ah OK! No worries, I thought *I* was having Monday-grogginess issues :-)