forked from OSchip/llvm-project
perform DSE through launder.invariant.group
Summary: Alias Analysis knows that llvm.launder.invariant.group returns pointer that mustalias argument, but this information wasn't used, therefor we didn't DSE through launder.invariant.group Reviewers: chandlerc, dberlin, bogner, hfinkel, efriedma Reviewed By: dberlin Subscribers: amharc, llvm-commits, nlewycky, rsmith Differential Revision: https://reviews.llvm.org/D31581 llvm-svn: 331449
This commit is contained in:
parent
5dde809404
commit
c77ab8ef2f
|
@ -343,7 +343,8 @@ static OverwriteResult isOverwrite(const MemoryLocation &Later,
|
||||||
const TargetLibraryInfo &TLI,
|
const TargetLibraryInfo &TLI,
|
||||||
int64_t &EarlierOff, int64_t &LaterOff,
|
int64_t &EarlierOff, int64_t &LaterOff,
|
||||||
Instruction *DepWrite,
|
Instruction *DepWrite,
|
||||||
InstOverlapIntervalsTy &IOL) {
|
InstOverlapIntervalsTy &IOL,
|
||||||
|
AliasAnalysis &AA) {
|
||||||
// If we don't know the sizes of either access, then we can't do a comparison.
|
// If we don't know the sizes of either access, then we can't do a comparison.
|
||||||
if (Later.Size == MemoryLocation::UnknownSize ||
|
if (Later.Size == MemoryLocation::UnknownSize ||
|
||||||
Earlier.Size == MemoryLocation::UnknownSize)
|
Earlier.Size == MemoryLocation::UnknownSize)
|
||||||
|
@ -354,7 +355,7 @@ static OverwriteResult isOverwrite(const MemoryLocation &Later,
|
||||||
|
|
||||||
// If the start pointers are the same, we just have to compare sizes to see if
|
// If the start pointers are the same, we just have to compare sizes to see if
|
||||||
// the later store was larger than the earlier store.
|
// the later store was larger than the earlier store.
|
||||||
if (P1 == P2) {
|
if (P1 == P2 || AA.isMustAlias(P1, P2)) {
|
||||||
// Make sure that the Later size is >= the Earlier size.
|
// Make sure that the Later size is >= the Earlier size.
|
||||||
if (Later.Size >= Earlier.Size)
|
if (Later.Size >= Earlier.Size)
|
||||||
return OW_Complete;
|
return OW_Complete;
|
||||||
|
@ -1162,9 +1163,8 @@ static bool eliminateDeadStores(BasicBlock &BB, AliasAnalysis *AA,
|
||||||
if (isRemovable(DepWrite) &&
|
if (isRemovable(DepWrite) &&
|
||||||
!isPossibleSelfRead(Inst, Loc, DepWrite, *TLI, *AA)) {
|
!isPossibleSelfRead(Inst, Loc, DepWrite, *TLI, *AA)) {
|
||||||
int64_t InstWriteOffset, DepWriteOffset;
|
int64_t InstWriteOffset, DepWriteOffset;
|
||||||
OverwriteResult OR =
|
OverwriteResult OR = isOverwrite(Loc, DepLoc, DL, *TLI, DepWriteOffset,
|
||||||
isOverwrite(Loc, DepLoc, DL, *TLI, DepWriteOffset, InstWriteOffset,
|
InstWriteOffset, DepWrite, IOL, *AA);
|
||||||
DepWrite, IOL);
|
|
||||||
if (OR == OW_Complete) {
|
if (OR == OW_Complete) {
|
||||||
DEBUG(dbgs() << "DSE: Remove Dead Store:\n DEAD: "
|
DEBUG(dbgs() << "DSE: Remove Dead Store:\n DEAD: "
|
||||||
<< *DepWrite << "\n KILLER: " << *Inst << '\n');
|
<< *DepWrite << "\n KILLER: " << *Inst << '\n');
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
; RUN: opt < %s -basicaa -dse -S | FileCheck %s
|
||||||
|
|
||||||
|
; CHECK-LABEL: void @skipBarrier(i8* %ptr)
|
||||||
|
define void @skipBarrier(i8* %ptr) {
|
||||||
|
; CHECK-NOT: store i8 42
|
||||||
|
store i8 42, i8* %ptr
|
||||||
|
; CHECK: %ptr2 = call i8* @llvm.launder.invariant.group.p0i8(i8* %ptr)
|
||||||
|
%ptr2 = call i8* @llvm.launder.invariant.group.p0i8(i8* %ptr)
|
||||||
|
; CHECK: store i8 43
|
||||||
|
store i8 43, i8* %ptr2
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK-LABEL: void @skip2Barriers(i8* %ptr)
|
||||||
|
define void @skip2Barriers(i8* %ptr) {
|
||||||
|
; CHECK-NOT: store i8 42
|
||||||
|
store i8 42, i8* %ptr
|
||||||
|
; CHECK: %ptr2 = call i8* @llvm.launder.invariant.group.p0i8(i8* %ptr)
|
||||||
|
%ptr2 = call i8* @llvm.launder.invariant.group.p0i8(i8* %ptr)
|
||||||
|
; CHECK-NOT: store i8 43
|
||||||
|
store i8 43, i8* %ptr2
|
||||||
|
%ptr3 = call i8* @llvm.launder.invariant.group.p0i8(i8* %ptr2)
|
||||||
|
%ptr4 = call i8* @llvm.launder.invariant.group.p0i8(i8* %ptr3)
|
||||||
|
|
||||||
|
; CHECK: store i8 44
|
||||||
|
store i8 44, i8* %ptr4
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare i8* @llvm.launder.invariant.group.p0i8(i8*)
|
Loading…
Reference in New Issue