This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Don't update the range value if empty
AbandonedPublic

Authored by davide on Jul 13 2023, 6:26 PM.

Details

Summary

The recent commit 22ca38da25e19a7c5fcfeb3f22159aba92ec381e introduces the ability to analyze ranges for heap allocations.

In some cases, like the one in the test, the range is empty as ConstantRange represents an half-open range on the upper side (in the very specific case, [1;1)). Detect this case, similarly to other ranges transformations in SCEV, rather than crashing.

Fixes https://github.com/llvm/llvm-project/issues/63856

Diff Detail

Event Timeline

davide created this revision.Jul 13 2023, 6:26 PM
davide requested review of this revision.Jul 13 2023, 6:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2023, 6:26 PM
nikic added inline comments.Jul 14 2023, 12:20 AM
llvm/lib/Analysis/ScalarEvolution.cpp
6838

It would be better to use ConstantRange::getNonEmpty() here.

llvm/test/Transforms/LoopStrengthReduce/scev-operator-new.ll
25

Please add the test to llvm/test/Analysis/ScalarEvolution/malloc.ll, with the same testing approach used there.

Could you add something like Fixes https://github.com/llvm/llvm-project/issues/63856 to the description/commit message so the GitHub issue gets auto-closed when the commit lands?

davide updated this revision to Diff 541208.Jul 17 2023, 1:28 PM
davide edited the summary of this revision. (Show Details)

Addressed @nikic and @fhahn review comments

davide updated this revision to Diff 541214.Jul 17 2023, 1:29 PM

Reupload with context.

fhahn accepted this revision.Jul 18 2023, 12:18 PM

LGTM thanks. I think the title still needs updating to match the latest implementation.

llvm/test/Analysis/ScalarEvolution/malloc.ll
28

it would probably be good to use a more descriptive name making it clear that this is with operator new and full range? Also, could mention the issue

llvm/test/Transforms/LoopStrengthReduce/scev-operator-new.ll
1

Does this test add anything over the one in malloc.ll? If not, probably best to remove it.

This revision is now accepted and ready to land.Jul 18 2023, 12:18 PM
nikic requested changes to this revision.Jul 18 2023, 12:24 PM

To be clear, the test I expected to see here is just this:

define ptr @size_max() {
  %alloc = call nonnull ptr @malloc(i64 -1)
  ret ptr %alloc
}

This is enough to reproduce the assertion failure for me.

llvm/test/Analysis/ScalarEvolution/malloc.ll
4

Why does this need a data layout?

34

Can reuse malloc.

40

This loop shouldn't be necessary.

This revision now requires changes to proceed.Jul 18 2023, 12:24 PM

I would like to apologize for dropping the ball here, I'm coming back to this in the next day or two.

davide added a comment.Sep 1 2023, 1:33 PM

https://reviews.llvm.org/D159160 fixes the same problem and has been committed.

davide abandoned this revision.Sep 1 2023, 1:34 PM