This is an archive of the discontinued LLVM Phabricator instance.

Add IntrInaccessibleMemOnly property for intrinsics
ClosedPublic

Authored by andrew.w.kaylor on Nov 9 2016, 4:53 PM.

Details

Summary

This property corresponds directly to the inaccessiblememonly function attribute.

I intend to use this attribute with the experimental constrained FP intrinsics that I will be adding soon, but it seemed best to have these changes reviewed separately.

I considered adding this attribute to the @llvm.assume() intrinsic as Hal suggested in the comments on D26382, but that would have resulted in changes to aliasing behavior which is specifically tested for in test/Analysis/BasicAA/assume.ll and I am not familiar enough with that intrinsic to be comfortable judging whether or not that is acceptable. Consequently, I have no direct test for this change set. I am, of course, open to guidance.

A notable piece of code that I did not change is the InstAnalyzer::AnalyzeNode() function in utils/TableGen/CodeGenDAGPatterns.cpp. That function contains the following code:

if (const CodeGenIntrinsic *IntInfo = N->getIntrinsicInfo(CDP)) {
  // If this is an intrinsic, analyze it.
  if (IntInfo->ModRef & CodeGenIntrinsic::MR_Ref)
    mayLoad = true;// These may load memory.

  if (IntInfo->ModRef & CodeGenIntrinsic::MR_Mod)
    mayStore = true;// Intrinsics that can write to memory are 'mayStore'.

  if (IntInfo->ModRef >= CodeGenIntrinsic::ReadWriteMem)
    // ReadWriteMem intrinsics can have other strange effects.
    hasSideEffects = true;
}

This code will not set the 'hasSideEffects' flag for intrinsics that use the IntrInaccessibleMemOnly property, but it currently does not set that flag for intrinsics that use the IntrArgMemOnly property. This seems wrong to me in both cases, but I decided to defer to the existing logic over my own judgment pending review.

Diff Detail

Repository
rL LLVM

Event Timeline

andrew.w.kaylor retitled this revision from to Add IntrInaccessibleMemOnly property for intrinsics.
andrew.w.kaylor updated this object.
andrew.w.kaylor added reviewers: hfinkel, nhaehnle.
andrew.w.kaylor set the repository for this revision to rL LLVM.
andrew.w.kaylor added a subscriber: llvm-commits.
hfinkel edited edge metadata.Nov 9 2016, 5:04 PM

I considered adding this attribute to the @llvm.assume() intrinsic as Hal suggested in the comments on D26382, but that would have resulted in changes to aliasing behavior which is specifically tested for in test/Analysis/BasicAA/assume.ll and I am not familiar enough with that intrinsic to be comfortable judging whether or not that is acceptable. Consequently, I have no direct test for this change set. I am, of course, open to guidance.

I don't see why they should be different. Please feel free to update the test case and I'll review it -- or explain why the semantics are different.

This code will not set the 'hasSideEffects' flag for intrinsics that use the IntrInaccessibleMemOnly property, but it currently does not set that flag for intrinsics that use the IntrArgMemOnly property. This seems wrong to me in both cases, but I decided to defer to the existing logic over my own judgment pending review.

hasSideEffects is somewhat misnamed. It really means "has otherwise-unmodeled side effects", so not setting it seems correct.

include/llvm/IR/Intrinsics.td
48 ↗(On Diff #77423)

We should go ahead and add InaccessibleMemOrArgMemOnly too while we're here.

andrew.w.kaylor edited edge metadata.

I added the IntrInaccessibleMemOrArgMemOnly property, and updated the llvm.assume intrinsic to use IntrInaccessibleMemOnly.

It turns out that I was wrong about this changing the aliasing behavior, at least with respect to BasicAA, because BasicAA specifically looks for llvm.assume and reports that it does not alias with any memory location or function call. The reason I thought it would be a change is because I expected llvm.assume with the new property to alias in the same way any other inaccessiblememonly function would, meaning it would report "Both ModRef" for any function call except calls to argmemonly functions.

It's not clear to me which other existing intrinsics should be using the new properties.

sanjoy added a subscriber: sanjoy.Nov 13 2016, 5:26 PM

I added the IntrInaccessibleMemOrArgMemOnly property, and updated the llvm.assume intrinsic to use IntrInaccessibleMemOnly.

It turns out that I was wrong about this changing the aliasing behavior, at least with respect to BasicAA, because BasicAA specifically looks for llvm.assume and reports that it does not alias with any memory location or function call. The reason I thought it would be a change is because I expected llvm.assume with the new property to alias in the same way any other inaccessiblememonly function would, meaning it would report "Both ModRef" for any function call except calls to argmemonly functions.

Ah, you're right. Nevermind, then. Adding the attribute to assume does not help because we still want assume not to alias with other function calls, and so it still needs special handling. Please remove the change to assume as it does not let us remove the special-case behavior in BasicAA.

It's not clear to me which other existing intrinsics should be using the new properties.

Removed IntrInaccessibleMemOnly from llvm.assume.

hfinkel accepted this revision.Nov 22 2016, 5:50 AM
hfinkel edited edge metadata.

LGTM

This revision is now accepted and ready to land.Nov 22 2016, 5:50 AM
This revision was automatically updated to reflect the committed changes.