This is an archive of the discontinued LLVM Phabricator instance.

[IPSCCP] Drop argmemonly after replacing pointer argument.
ClosedPublic

Authored by fhahn on Jul 23 2020, 9:31 AM.

Details

Summary

This patch updates IPSCCP to drop argmemonly and
inaccessiblemem_or_argmemonly if it replaces a pointer argument.

Fixes PR46717.

Diff Detail

Event Timeline

fhahn created this revision.Jul 23 2020, 9:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2020, 9:31 AM
Herald added a subscriber: hiraditya. · View Herald Transcript

This doesn't "work" for

define internal void @ptrarg.5(i64 %arg, i32 %val) argmemonly inaccessiblemem_or_argmemonly nounwind {
  %p = inttoptr i64 %arg to i32* 
  store i32 %val, i32* %p
  ret void
}

Unsure if that is a problem in the real world but I wanted to mention it.

fhahn added a comment.Jul 23 2020, 9:53 AM

This doesn't "work" for

define internal void @ptrarg.5(i64 %arg, i32 %val) argmemonly inaccessiblemem_or_argmemonly nounwind {
  %p = inttoptr i64 %arg to i32* 
  store i32 %val, i32* %p
  ret void
}

Unsure if that is a problem in the real world but I wanted to mention it.

Is this valid (as in not UB)? For argmemonly, langref says ... loads and stores from objects pointed to by its pointer-typed arguments, with arbitrary offsets., but in the example we access an object not pointed to any pointer argument.

BTW, I think it would be good to have something like an attribute verifier. Catching all violations is impossible, but at least some things could be checked :)

jdoerfert accepted this revision.Jul 23 2020, 10:30 AM

This doesn't "work" for

define internal void @ptrarg.5(i64 %arg, i32 %val) argmemonly inaccessiblemem_or_argmemonly nounwind {
  %p = inttoptr i64 %arg to i32* 
  store i32 %val, i32* %p
  ret void
}

Unsure if that is a problem in the real world but I wanted to mention it.

Is this valid (as in not UB)? For argmemonly, langref says ... loads and stores from objects pointed to by its pointer-typed arguments, with arbitrary offsets., but in the example we access an object not pointed to any pointer argument.

I think you're right.

BTW, I think it would be good to have something like an attribute verifier. Catching all violations is impossible, but at least some things could be checked :)

100% Agreed, patches welcome ;)

This revision is now accepted and ready to land.Jul 23 2020, 10:30 AM
efriedma added inline comments.Jul 23 2020, 3:32 PM
llvm/lib/Transforms/Scalar/SCCP.cpp
1927

Do we also need to modify the attributes on the callsites?

fhahn updated this revision to Diff 280375.Jul 24 2020, 2:16 AM
fhahn marked an inline comment as done.

Also drop callsite argmemonly/inaccessiblemem_or_argmemonly attributes

llvm/lib/Transforms/Scalar/SCCP.cpp
1927

Yes, updated!

This revision was automatically updated to reflect the committed changes.