Page MenuHomePhabricator

[SLPVectorizer] Don't deref std::end() of object
Needs ReviewPublic

Authored by JOE1994 on Dec 1 2022, 3:45 PM.

Details

Reviewers
ABataev
Summary

Dereferencing std::end() of an object can lead to undefined behavior
(e.g. segmentation fault, invalid memory access).

This commit updates SLPVectorizer to only dereference the iterator from
find_if_not() if it is not a std::end().

This prevents SLPVectorizer from crashing with certain workloads.

Diff Detail

Event Timeline

JOE1994 created this revision.Dec 1 2022, 3:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2022, 3:45 PM
JOE1994 requested review of this revision.Dec 1 2022, 3:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2022, 3:45 PM
fhahn added a subscriber: fhahn.Dec 1 2022, 3:53 PM

Could you provide a test case?

Could you provide a test case?

I observed a compiler crash while compiling one of private benchmark programs at my company.
Crash happens during llvm::lto::LTO::runRegularLTO.

So far I haven't been successful in extracting a minimal reproducible example.

Code that calls find_if_not was added by commit d65cc8597792ab04142cd2214c46c5c167191bcd to improve compile time & scheduling resources.
Thus I expect that using V and OpValue as is when std::end() is returned shouldn't cause any issues.

This change doesn't cause any new LIT failures in llvm/test/Transforms/SLPVectorizer.

Would be good to have tests