This is an archive of the discontinued LLVM Phabricator instance.

[LLVM IR] Allow volatile stores to trap.
ClosedPublic

Authored by efriedma on Jul 19 2021, 1:51 PM.

Details

Summary

Proposed alternative to D105338.

This is ugly, but short-term I think it's the best way forward: first, let's formalize the hacks into a coherent model. Then we can consider extensions of that model (we could have different flavors of volatile with different rules).

Diff Detail

Event Timeline

efriedma created this revision.Jul 19 2021, 1:51 PM
efriedma requested review of this revision.Jul 19 2021, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2021, 1:51 PM

I think this makes it consistent but I would have hoped to avoid it anyway. willreturn might not be the most important attribute yet but it's uses are growing. It affects align, dereferenceable, and already various optimizations already.

That said, the conversation in the other thread doesn't have to stop if we land this and this would at least give us some consistency, so I'm in favor of landing it.

nikic added inline comments.Jul 19 2021, 2:23 PM
llvm/lib/Analysis/ValueTracking.cpp
5295

This should be sunk into Instruction::willReturn(), otherwise FuncAttrs won't use the new semantics.

efriedma updated this revision to Diff 359939.Jul 19 2021, 3:16 PM

Move check into Instruction::willReturn.

Note that this still won't quite match clang's expectations, since it expects that load volatile also may trap.

Note that this still won't quite match clang's expectations, since it expects that load volatile also may trap.

Where does clang expect that?

Note that this still won't quite match clang's expectations, since it expects that load volatile also may trap.

Where does clang expect that?

In the C++ specification, i believe.

C++ [dcl.type.cv] explicitly states "The semantics of an access through a volatile glvalue are implementation-defined." I think that's a pretty clear statement that the standard wants to stay out of this debate. :)

nikic accepted this revision.Jul 24 2021, 8:08 AM

LGTM, with the understanding that this is just bringing our current hacks into a coherent model, and does not match the semantics we actually want to have.

This revision is now accepted and ready to land.Jul 24 2021, 8:08 AM
nick added a subscriber: nick.Jul 24 2021, 12:13 PM
This revision was landed with ongoing or failed builds.Jul 26 2021, 10:51 AM
This revision was automatically updated to reflect the committed changes.