This is an archive of the discontinued LLVM Phabricator instance.

Use pragmas to work around MSVC x86_32 debug miscompile bug
ClosedPublic

Authored by rnk on Sep 10 2020, 11:42 AM.

Details

Summary

Halide users reported this here: https://llvm.org/pr46176
I reported the issue to MSVC here:
https://developercommunity.visualstudio.com/content/problem/1179643/msvc-copies-overaligned-non-trivially-copyable-par.html

This codepath is apparently not covered by LLVM's unit tests, so I added
coverage in a unit test.

If we want to support this configuration going forward, it means that is
in general not safe to pass a SmallVector<T, N> by value if alignof(T)
is greater than 4. This doesn't appear to come up often because passing
a SmallVector by value is inefficient and not idiomatic: it copies the
inline storage. In this case, the SmallVector<LLT,4> is captured by
value by a lambda, and the lambda is passed by value into std::function,
and that's how we hit the bug.

Diff Detail

Event Timeline

rnk created this revision.Sep 10 2020, 11:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 10 2020, 11:42 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
rnk requested review of this revision.Sep 10 2020, 11:42 AM
asbirlea accepted this revision.Sep 10 2020, 12:56 PM

Thank you so much Reid for taking the time to look into this, discovering the msvc issue and proposing this work-around!

llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp
413

nit: fix clang-tidy warnings
s/s1/S1
s/p0/P0
s/builder/Builder

This revision is now accepted and ready to land.Sep 10 2020, 12:56 PM
This revision was landed with ongoing or failed builds.Sep 10 2020, 2:50 PM
This revision was automatically updated to reflect the committed changes.
craig.topper added inline comments.
llvm/lib/CodeGen/GlobalISel/LegalityPredicates.cpp
13

This comment says "Disable optimizations", but the one below says "We have to disable runtime checks in order to enable optimizations". Are we enabling or disabling optimizations?

rnk added inline comments.Sep 10 2020, 4:42 PM
llvm/lib/CodeGen/GlobalISel/LegalityPredicates.cpp
13

Bleh, the late breaking comment update was wrong. We are enabling optimizations. I'll fix it.

You can observe the interaction between runtime checks and optimizations on the command line with cl -RTC1 -O2, it will produce an error. Using pragma optimize on by itself did nothing without producing a warning. =P