This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Look through ptrmask intrinsics during getUnderlyingObject.
ClosedPublic

Authored by fhahn on May 8 2019, 2:38 AM.

Event Timeline

fhahn created this revision.May 8 2019, 2:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 8 2019, 2:38 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
fhahn added a reviewer: aqjune.May 8 2019, 2:40 AM
fhahn updated this revision to Diff 198611.May 8 2019, 2:52 AM

Add missing attributes to @init argument.

I'd look into this but I have trouble locating the "ptrmask" intrinsic in LLVM/Clang/LangRef. Could you help me out?

I'd look into this but I have trouble locating the "ptrmask" intrinsic in LLVM/Clang/LangRef. Could you help me out?

This missed the dependency on D59065, which proposes the ptrmask intrinsic.

aqjune added inline comments.May 8 2019, 9:14 AM
llvm/lib/Analysis/ValueTracking.cpp
3706

I found that getArgumentAliasingToReturnedPointer (which calls this function) is used at isKnownNonZero with the following pattern:

if (const auto *RP = getArgumentAliasingToReturnedPointer(Call))
  return isKnownNonZero(RP, Depth, Q);

which seems to assume that the non-zeroness of the result of a function call is equivalent to the non-zeroness of the first argument. isKnownNonZero should be fixed, or maybe we can add a boolean flag to isIntrinsicReturningPointerAliasingArgumentWithoutCapturing that allows callers to determine its purpose?

jdoerfert added inline comments.May 8 2019, 9:21 AM
llvm/lib/Analysis/ValueTracking.cpp
3706

Value::stripPointerCasts() is sometimes used with the same assumption but there is it also not given (due to address space casts). In D61607 I try to introduce a version that "keeps the bit pattern the same" to fix uses that put the result in to isKnownNonZero-like functions.

That said, I guess you can introduce an
isIntrinsicReturningPointerArgumentWithoutCapturing
to fix this issue?

fhahn updated this revision to Diff 207846.Jul 3 2019, 11:01 AM

Handle nonnullness requirement for the use of getArgumentAliasingToReturnedPointer
in isKnownNonZero, as suggested.

Also simplified the test.

fhahn marked an inline comment as done.Jul 3 2019, 11:03 AM
fhahn added inline comments.
llvm/lib/Analysis/ValueTracking.cpp
3706

Sorry for the long delay! I've added a MustPreserveNullness argument in D64150, to distinguish those 2 cases.

This revision is now accepted and ready to land.Jul 3 2019, 12:00 PM
This revision was automatically updated to reflect the committed changes.