This is an archive of the discontinued LLVM Phabricator instance.

[LICM] Don't try to constant fold instructions
ClosedPublic

Authored by nikic on Apr 25 2023, 1:23 AM.

Details

Summary

This was introduced in https://github.com/llvm/llvm-project/commit/030f02021b6359ec5641622cf1aa63d873ecf55a as an alleged compile-time optimization. In reality, trying to constant fold instructions is more expensive than just hoisting them. In a standard pipeline, LICM tends to run either after a run of LoopInstSimplify or InstCombine, so LICM doesn't really see constant foldable instructions in the first place, and the attempted fold is futile.

This makes for a very minor compile-time improvement: http://llvm-compile-time-tracker.com/compare.php?from=41c201aabe4220d6d2ff0a07c20e20e932dbac7a&to=057b5f1f3573ddceb04d9eb6fb9973358d53fece&stat=instructions:u

Diff Detail

Event Timeline

nikic created this revision.Apr 25 2023, 1:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 1:23 AM
nikic requested review of this revision.Apr 25 2023, 1:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 1:23 AM
mkazantsev accepted this revision.Apr 25 2023, 4:39 AM

Just curious, what makes it so expensive? Is it SafetyInfo update?

This revision is now accepted and ready to land.Apr 25 2023, 4:39 AM

Just curious, what makes it so expensive? Is it SafetyInfo update?

No, it's the constant folding itself. E.g. even if you have some non-foldable operation will all-constant operands (like a load from global or call with constants) it will still do quite a bit of work, such as recursively folding all the constant operands with datalayout.

This revision was landed with ongoing or failed builds.Apr 26 2023, 12:27 AM
This revision was automatically updated to reflect the committed changes.