This is an archive of the discontinued LLVM Phabricator instance.

[dataflow] Avoid copying environment
ClosedPublic

Authored by sammccall on Jun 21 2023, 7:27 PM.

Details

Summary

This appears to be just an accidental copy rather than move from a scratch
variable.
As well as doing redundant work, these copies introduce extra SAT variables
which make debugging harder (each Enviroment has a unique FC token).

Example flow condition before:

(B0:1 = V15)
(B1:1 = V8)
(B2:1 = V10)
(B3:1 = (V4 & (!V7 => V6)))
(V10 = (B3:1 & !V7))
(V12 = B1:1)
(V13 = B2:1)
(V15 = (V12 | V13))
(V3 = V2)
(V4 = V3)
(V8 = (B3:1 & !!V7))
B0:1
V2

after:

(B0:1 = (V9 | V10))
(B1:1 = (B3:1 & !!V6))
(B2:1 = (B3:1 & !V6))
(B3:1 = (V3 & (!V6 => V5)))
(V10 = B2:1)
(V3 = V2)
(V9 = B1:1)
B0:1
V2

(with labelling from D153488)

There are also some more copies that can be avoided here (when multiple blocks
without terminating statements are joined), but they're less trivial, so I'll
put those in another patch.

Diff Detail

Event Timeline

sammccall created this revision.Jun 21 2023, 7:27 PM
Herald added a project: Restricted Project. · View Herald Transcript
sammccall requested review of this revision.Jun 21 2023, 7:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2023, 7:27 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ymandel accepted this revision.Jun 22 2023, 9:13 AM
This revision is now accepted and ready to land.Jun 22 2023, 9:13 AM
This revision was landed with ongoing or failed builds.Jun 22 2023, 12:09 PM
This revision was automatically updated to reflect the committed changes.

This sounds extremely error-prone to me. In case copying the analysis state has side effects like this, I would argue we want such operations to be really explicit. What do you think?

This sounds extremely error-prone to me. In case copying the analysis state has side effects like this, I would argue we want such operations to be really explicit. What do you think?

Can you expand on this concern? Are you referring to the removal of the unintended copy (ie. this patch), or raising a concern about the how the underlying system handles copies altogether?

This sounds extremely error-prone to me. In case copying the analysis state has side effects like this, I would argue we want such operations to be really explicit. What do you think?

Can you expand on this concern? Are you referring to the removal of the unintended copy (ie. this patch), or raising a concern about the how the underlying system handles copies altogether?

FWIW I would prefer if we can call this operation clone() or fork() or something rather than have it be the copy constructor.

It is a kind of copy but between it being quite expensive, this effect on the SAT system, and intentional copies being quite an important and deliberate thing, making it a bit verbose seems justified.

I'll send a patch for this...

This sounds extremely error-prone to me. In case copying the analysis state has side effects like this, I would argue we want such operations to be really explicit. What do you think?

Can you expand on this concern? Are you referring to the removal of the unintended copy (ie. this patch), or raising a concern about the how the underlying system handles copies altogether?

The latter, https://reviews.llvm.org/D153674 should address my concerns.