This is an archive of the discontinued LLVM Phabricator instance.

[CaptureTracking] Consider ephemeral calls accessing memory as capturing.
Needs RevisionPublic

Authored by fhahn on Jun 22 2023, 10:44 AM.

Details

Summary

Consider ephemeral calls reading or writing memory as capturing to avoid
memory optimizations that introduce new UB after inlining such calls.

This fixes a mis-compile (see
llvm/test/Transforms/PhaseOrdering/dse-ephemeral-value-captures.ll). The
issue is roughly:

  1. There's a call to a readonly function that takes a pointer argument and its result is only used by an assume, so the call is considered ephemeral and not capturing.
  2. Because the call doesn't capture the pointer, it's considered to not read the pointer, causing DSE to remove the store before the call.
  3. Now the called function gets inlined and there's now a load from the pointer, but the initializing store has been removed
  4. This leads to SROA replacing the load with undef, which will cause the function to get folded to unreachable by subsequent optimizations.

Alternative to D153464

Diff Detail

Unit TestsFailed

Event Timeline

fhahn created this revision.Jun 22 2023, 10:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2023, 10:44 AM
fhahn requested review of this revision.Jun 22 2023, 10:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2023, 10:44 AM
nikic requested changes to this revision.Jun 29 2023, 12:44 AM

I believe that after D153511 this should not be necessary anymore.

This revision now requires changes to proceed.Jun 29 2023, 12:44 AM