This is an archive of the discontinued LLVM Phabricator instance.

[LSR] Check if terminating value is safe to expand before transformation
ClosedPublic

Authored by eopXD on Oct 20 2022, 8:28 PM.

Details

Summary

According to report by @JojoR, the assertion error was hit hence we need
to have this check before the actual transformation.

Diff Detail

Event Timeline

eopXD created this revision.Oct 20 2022, 8:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2022, 8:28 PM
eopXD requested review of this revision.Oct 20 2022, 8:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2022, 8:28 PM

According to report by @JojoR, the assertion error was hit hence we need to have this check before the actual transformation.

Would it be possible to add the test case?

eopXD added a comment.Oct 22 2022, 7:40 AM

@JojoR May you please upload the LLVM IR with -O0 (so nothing is triggered) of what causes the assertion error to hit to here so I can try reduce the a test case out of it?

eopXD updated this revision to Diff 469913.Oct 22 2022, 10:10 AM

Add test case reduced from FFmpeg/libavfilter/ebur128.c

eopXD added a comment.Oct 25 2022, 2:43 AM

Gentle ping, thank you.

@JojoR May you please upload the LLVM IR with -O0 (so nothing is triggered) of what causes the assertion error to hit to here so I can try reduce the a test case out of it?

I tested again and the error is not triggered with -O0,
I reduce the test case, see attached, hope that it's helpful for you :)

JojoR added inline comments.Oct 26 2022, 11:57 PM
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
6862–6863

The patch looks good to me,
but the implementation is redundant with here ?
it should merge into one ?

eopXD added inline comments.Oct 27 2022, 12:02 AM
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
6862–6863

Sorry, may you explain more on the redundancy you see here.

eopXD updated this revision to Diff 471034.Oct 27 2022, 12:10 AM

Add test case provided by @JojoR

JojoR added inline comments.Oct 27 2022, 12:15 AM
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
6862–6863

Looks only one expression, ignore this comment.
my original consideration is that put same action/checker into one place, it's ok also here :)

Meinersbur added inline comments.Oct 27 2022, 1:35 PM
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
6862–6863

Could you explain why the TermValueS that that is checked by Expander.isSafeToExpand before this patch is different than the TermValueS in IsToHelpFold after this patch?

llvm/test/Transforms/LoopStrengthReduce/lsr-term-fold-negative-testcase.ll
224

[nit]

eopXD added inline comments.Oct 28 2022, 1:55 AM
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
6862–6863

TermValueS calculation does not change before/after this patch. The addition here is to guard the expansion of it by checking if it is safe in the legalization of this terminating condition fold transformation.

eopXD updated this revision to Diff 471464.Oct 28 2022, 2:55 AM

Address comments from Michael.

eopXD marked an inline comment as done.Oct 30 2022, 9:30 AM
Meinersbur added a reviewer: Restricted Project.Nov 2 2022, 8:51 AM
bmahjour added a project: Restricted Project.Nov 2 2022, 8:51 AM
syzaara added a subscriber: syzaara.Nov 2 2022, 9:21 AM
syzaara added inline comments.
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
6862–6863

It seems like we are doing this SCEV expansion already in IsToHelpFold. Could we just return TermValueS from there rather than redoing the SCEV calculation again?

eopXD updated this revision to Diff 472763.Nov 2 2022, 2:19 PM

Change: Address comment, avoid duplicate calculation for TermValueS.

eopXD marked an inline comment as done.Nov 2 2022, 2:19 PM
eopXD marked 2 inline comments as done.

Ping for reviewal.

This revision is now accepted and ready to land.Nov 8 2022, 7:20 PM
eopXD updated this revision to Diff 475567.Nov 15 2022, 1:39 PM

Rebase to latest main.

This revision was landed with ongoing or failed builds.Nov 15 2022, 2:56 PM
This revision was automatically updated to reflect the committed changes.