[PATCH] D73679: [MemoryBuiltins] Determine the size of a global w/o initializer

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 2 19:53:23 PST 2020


jdoerfert marked an inline comment as done.
jdoerfert added inline comments.


================
Comment at: llvm/test/Analysis/BasicAA/bug.23540.ll:11
 ; CHECK-LABEL: f
-; CHECK: MayAlias: i32* %arrayidx, i32* %arrayidx6
+; CHECK: PartialAlias: i32* %arrayidx, i32* %arrayidx6
 define void @f() {
----------------
george.burgess.iv wrote:
> jdoerfert wrote:
> > george.burgess.iv wrote:
> > > Can you expand a bit on why PartialAlias is the correct answer here, please?
> > > 
> > > I'd naively expect this to be either MustAlias (both pointers are to a 32 bit object, and there're only 32 bits in this allocation; derefing anything else is UB), or MayAlias (there're only 32 bits here, but maaaaybe you're pointing to `((int*)&c + 1)`, and that's OK.)
> > My reasoning is that `arrayidx6` points right after `c` and `arrayidx` points somewhere based on `c`. There are no accesses so the alias query is done with an unspecified size on the access part which should mean the two accesses can very well overlap. 
> I don't quite agree with the unspecified size part: if the access size were entirely unknown, we could only correctly return `PartialAlias` in cases with provably identical object offsets, since `PartialAlias` *guarantees* the two accesses will overlap somehow.
> 
> Experimentally, we report `NoAlias` for `(%b, %c)` in:
> ```
> define void @f() {
>   %a = alloca i32
>   %b = bitcast i32* %a to i8*
>   %c = getelementptr i8, i8* %b, i64 1
>   ret void
> }
> ```
> 
> So I think the sizes here should be 4 bytes. If that's the case, `MustAlias` seems like the optimal answer, which means that `PartialAlias` is also correct.  `sizeof(access) == sizeof(underlying_object)` in both cases means there's really no room for nonzero object offsets. :)
> 
> If this sounds correct, please update the newly-added comment.
So I added a `d = gep %b, undef` which is closer to the test case that changed and which results in a `MayAlias`: https://godbolt.org/z/KT4F5z

I don't follow the `MustAlias` argument. There is no access here, so we talk about pointers only. 
The pointers are based on the same thing with an unknown offset from each other (at least that seems to me how `undef` is interpreted here).

I'll come up with more tests asap.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73679/new/

https://reviews.llvm.org/D73679





More information about the llvm-commits mailing list