This is an archive of the discontinued LLVM Phabricator instance.

[MemoryBuiltins] Fix an issue with hasNoAliasAttr
ClosedPublic

Authored by sanjoy on Feb 9 2016, 11:55 AM.

Details

Summary

hasNoAliasAttr is buggy: it checks to see if the called function has
a noalias attribute, which is incorrect since functions are not even
allowed to have the noalias attribute. The comment on its only
caller, llvm::isNoAliasFn, makes it pretty clear that the intention
to do the noalias check on the return value, and not the callee.

Unfortunately I couldn't find a way to test this upstream -- fixing
this does not change the observable behavior of any of the passes that
use this. This is not very surprising, since noalias does not tell
anything about the contents of the allocated memory (so, e.g., you
still cannot fold loads). I'll be happy to be proven wrong though.

Diff Detail

Repository
rL LLVM

Event Timeline

sanjoy updated this revision to Diff 47349.Feb 9 2016, 11:55 AM
sanjoy retitled this revision from to [MemoryBuiltins] Fix an issue with hasNoAliasAttr.
sanjoy updated this object.
sanjoy added reviewers: chandlerc, reames.
sanjoy added a subscriber: llvm-commits.
reames accepted this revision.Feb 9 2016, 1:37 PM
reames edited edge metadata.

LGTM w/optional comments.

As a test case consider:
%p = ...
load from %p
%p2 = malloc()
load from %p

GVN? Not sure this will actually work, but worth trying.

lib/Analysis/MemoryBuiltins.cpp
147 ↗(On Diff #47349)

Can you add an assert inside the attribute mechanism that would have caught this?

This revision is now accepted and ready to land.Feb 9 2016, 1:37 PM
sanjoy added inline comments.Feb 9 2016, 1:58 PM
lib/Analysis/MemoryBuiltins.cpp
147 ↗(On Diff #47349)

That's a good idea, I'll do that in a follow-up patch.

This revision was automatically updated to reflect the committed changes.