[PATCH] D43269: [MemorySSA] Be less aggressive with @llvm.lifetime.start

George Burgess IV via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 16:35:11 PST 2018


george.burgess.iv created this revision.
george.burgess.iv added a reviewer: dberlin.
Herald added subscribers: llvm-commits, Prazek.

Primarily uploading to get your opinion on whether this is a MSSA bug, or insanity that shouldn't exist in IR.

After inlining, EarlyCSE may be given code like:

  ; snip
  %.fca.0.gep.i = getelementptr inbounds [2 x i64], [2 x i64]* %retval.i, i64 0, i64 0
  %.fca.1.gep.i = getelementptr inbounds [2 x i64], [2 x i64]* %retval.i, i64 0, i64 1
  %.fca.1.load.i = load i64, i64* %.fca.1.gep.i, align 8
  call void @llvm.lifetime.end.p0i8(i64 16, i8* %2)
  %23 = bitcast %class.SkRecorder* %this to %class.SkCanvas*
  call void @llvm.lifetime.start.p0i8(i64 16, i8* %2) #8
  store i64 0, i64* %.fca.0.gep.i, align 8
  store i64 %.fca.1.load.i, i64* %.fca.1.gep.i, align 8
  call void @whatever(%class.SkCanvas* %23, %struct.SkIRect* dereferenceable(16) %tmpcast.i)
  ; snip

...where %2 and %tmpcast.i are bitcasted %retval.i pointers. This is a pretty roundabout way of saying "store 0 into %.fca.0.gep.i", but doesn't venture into illegal IR AFAICT.

The issue is that "`%fca.1.load.i` MustAlias `%2`" is false, so MSSA doesn't treat it as a clobber for the store into %.fca.1.gep.i. Hence, EarlyCSE considers the last store to be redundant, and eliminates it. Later passes then eliminate the now-dead %.fca.1.load.i, then the store that paired with %.fca.1.load.i dies, presumably due to being unused before `lifetime.end`, etc.

I imagine we can get into a similar situation if we had code like:

  %foo = select %whatever, %ptr1, %ptr2 ; %ptr1 NoAlias %ptr2 
  %f = load i8, i8* %foo
  call void @llvm.lifetime.end.p0i8(i64 8, i8* %ptr1)
  call void @llvm.lifetime.start.p0i8(i64 8, i8* %ptr1)
  store i8, i8* %foo
  call void @use(i8* %foo)

...We'd eliminate the `store`, an optimization after us turns %whatever into a constant truthy value, ...


Repository:
  rL LLVM

https://reviews.llvm.org/D43269

Files:
  lib/Analysis/MemorySSA.cpp
  test/Transforms/EarlyCSE/memoryssa.ll
  unittests/Analysis/MemorySSA.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43269.134134.patch
Type: text/x-patch
Size: 5002 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180214/d3dcaac7/attachment.bin>


More information about the llvm-commits mailing list