Hans Wennborg
2009-Nov-06 15:49 UTC
[LLVMdev] BasicAliasAnalysis: Null pointers do not alias with anything
Dan Gohman wrote:> Hello, > > On Nov 4, 2009, at 1:51 AM, Hans Wennborg wrote: >> >> / Hans >> Index: lib/Analysis/BasicAliasAnalysis.cpp >> ==================================================================>> --- lib/Analysis/BasicAliasAnalysis.cpp (revision 86023) >> +++ lib/Analysis/BasicAliasAnalysis.cpp (working copy) >> @@ -633,6 +633,15 @@ >> AliasAnalysis::AliasResult >> BasicAliasAnalysis::aliasCheck(const Value *V1, unsigned V1Size, >> const Value *V2, unsigned V2Size) { >> + // Null pointers do not alias with anything >> + if (const Constant *C = dyn_cast<Constant>(V1)) >> + if (C->isNullValue()) >> + return NoAlias; >> + >> + if (const Constant *C = dyn_cast<Constant>(V2)) >> + if (C->isNullValue()) >> + return NoAlias; >> + > > As Chris mentioned, for consistency with what the rest of LLVM is doing, > this should check whether the pointers are in the default address space > (0). > > Also, this could be generalized by checking the results from > getUnderlyingObject, since it's not valid to do arithmetic from null to > reach an LLVM identified object either.I'm not sure what you mean by generalizing. Do you mean I should do the check on O1 and O2, which are the results of calls to getUnderlyingObject? Something like: if (const ConstantPointerNull *CPN = dyn_cast<ConstantPointerNull>(O1)) if (CPN->getType()->getAddressSpace() == 0) return NoAlias; and the same for O2 (maybe extract it into a function?) / Hans> > Dan >
Dan Gohman
2009-Nov-07 01:48 UTC
[LLVMdev] BasicAliasAnalysis: Null pointers do not alias with anything
On Nov 6, 2009, at 7:49 AM, Hans Wennborg wrote:> > I'm not sure what you mean by generalizing. > Do you mean I should do the check on O1 and O2, which are the results of calls to getUnderlyingObject? > > Something like: > > if (const ConstantPointerNull *CPN = dyn_cast<ConstantPointerNull>(O1)) > if (CPN->getType()->getAddressSpace() == 0) > return NoAlias; > > and the same for O2 (maybe extract it into a function?)Yes, thanks. Dan
Hans Wennborg
2009-Nov-07 09:44 UTC
[LLVMdev] BasicAliasAnalysis: Null pointers do not alias with anything
Dan Gohman wrote:> On Nov 6, 2009, at 7:49 AM, Hans Wennborg wrote: >> I'm not sure what you mean by generalizing. >> Do you mean I should do the check on O1 and O2, which are the results of calls to getUnderlyingObject? >> >> Something like: >> >> if (const ConstantPointerNull *CPN = dyn_cast<ConstantPointerNull>(O1)) >> if (CPN->getType()->getAddressSpace() == 0) >> return NoAlias; >> >> and the same for O2 (maybe extract it into a function?) > > Yes, thanks.Ok, patch with test case attached. / Hans> > Dan >-------------- next part -------------- A non-text attachment was scrubbed... Name: BasicAliasAnalysis.diff Type: text/x-patch Size: 1508 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091107/4b1e737b/attachment.bin>
Reasonably Related Threads
- [LLVMdev] BasicAliasAnalysis: Null pointers do not alias with anything
- [LLVMdev] BasicAliasAnalysis: Null pointers do not alias with anything
- [LLVMdev] BasicAliasAnalysis: Null pointers do not alias with anything
- [LLVMdev] BasicAliasAnalysis: Null pointers do not alias with anything
- [LLVMdev] BasicAliasAnalysis: constant does not alias with noalias parameter