This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Fix FoldID::addInteger(unsigned long I)
ClosedPublic

Authored by vitalybuka on Feb 17 2023, 6:32 PM.

Details

Summary

"unsigned long" can be 8 bytes, but the code assumes 4.

This this the real root cause D122215 was reverted.

Diff Detail

Event Timeline

vitalybuka created this revision.Feb 17 2023, 6:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2023, 6:32 PM
vitalybuka requested review of this revision.Feb 17 2023, 6:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2023, 6:32 PM
fhahn accepted this revision.Feb 18 2023, 12:01 PM

LGTM, thanks for tracking this down!

This revision is now accepted and ready to land.Feb 18 2023, 12:01 PM
This revision was automatically updated to reflect the committed changes.
nikic added a subscriber: nikic.Feb 18 2023, 1:13 PM

Looks like this had a fairly significant compile-time impact: https://llvm-compile-time-tracker.com/compare.php?from=c23f29d6f05b1fe4fa2dd50cbb78ee2b30e0de4d&to=a53d940cee6f281ef1a20d4f0fb39b23b4e98614&stat=instructions:u

I think the current uses of FoldID will now have 5 elements and as such overflow SmallVector space, each resulting in a vector allocation?

It's not great that this change was backported without approval, bypassing the required backport process, immediately after landing the change on main, without even waiting for any fallout :(

As is it's a really land mine, it's cut off half of the pointer in the key, and can affect correctness anything that uses SCEV

Regarding perf, I have improved patch, which I planed to send for review, but not to backport:
https://llvm-compile-time-tracker.com/index.php?config=NewPM-O3&stat=instructions%3Au&remote=vitalybuka

We can backport both of them, to be incremental:

  1. correctness
  2. perf

Looks like this had a fairly significant compile-time impact: https://llvm-compile-time-tracker.com/compare.php?from=c23f29d6f05b1fe4fa2dd50cbb78ee2b30e0de4d&to=a53d940cee6f281ef1a20d4f0fb39b23b4e98614&stat=instructions:u

I think the current uses of FoldID will now have 5 elements and as such overflow SmallVector space, each resulting in a vector allocation?

It's not great that this change was backported without approval, bypassing the required backport process, immediately after landing the change on main, without even waiting for any fallout :(

fhahn added a comment.Feb 20 2023, 4:51 AM

Looks like this had a fairly significant compile-time impact: https://llvm-compile-time-tracker.com/compare.php?from=c23f29d6f05b1fe4fa2dd50cbb78ee2b30e0de4d&to=a53d940cee6f281ef1a20d4f0fb39b23b4e98614&stat=instructions:u

I think the current uses of FoldID will now have 5 elements and as such overflow SmallVector space, each resulting in a vector allocation?

Yeah looks like it. It looks like extending the size of the Bits vector should recover the regression while still retaining support for arbitrary SCEV expressions, which was the main reason for the current FoldID implementation.

MaskRay added inline comments.
llvm/include/llvm/Analysis/ScalarEvolution.h
1309

This can be replaced with a static_assert, but the point is moot now that you are going to remove this piece of code.