[AliasSetTracker] Teach AliasSetTracker about MemSetInst

This change is to fix the problem discussed in
http://lists.llvm.org/pipermail/llvm-dev/2016-February/095446.html.

llvm-svn: 261052
This commit is contained in:
Haicheng Wu 2016-02-17 02:01:50 +00:00
parent a0d5347ee9
commit 5cf99095bb
3 changed files with 95 additions and 0 deletions

View File

@ -30,6 +30,7 @@ namespace llvm {
class LoadInst; class LoadInst;
class StoreInst; class StoreInst;
class VAArgInst; class VAArgInst;
class MemSetInst;
class AliasSetTracker; class AliasSetTracker;
class AliasSet; class AliasSet;
@ -329,6 +330,7 @@ public:
bool add(LoadInst *LI); bool add(LoadInst *LI);
bool add(StoreInst *SI); bool add(StoreInst *SI);
bool add(VAArgInst *VAAI); bool add(VAArgInst *VAAI);
bool add(MemSetInst *MSI);
bool add(Instruction *I); // Dispatch to one of the other add methods... bool add(Instruction *I); // Dispatch to one of the other add methods...
void add(BasicBlock &BB); // Add all instructions in basic block void add(BasicBlock &BB); // Add all instructions in basic block
void add(const AliasSetTracker &AST); // Add alias relations from another AST void add(const AliasSetTracker &AST); // Add alias relations from another AST
@ -341,6 +343,7 @@ public:
bool remove(LoadInst *LI); bool remove(LoadInst *LI);
bool remove(StoreInst *SI); bool remove(StoreInst *SI);
bool remove(VAArgInst *VAAI); bool remove(VAArgInst *VAAI);
bool remove(MemSetInst *MSI);
bool remove(Instruction *I); bool remove(Instruction *I);
void remove(AliasSet &AS); void remove(AliasSet &AS);
bool removeUnknown(Instruction *I); bool removeUnknown(Instruction *I);

View File

@ -342,6 +342,24 @@ bool AliasSetTracker::add(VAArgInst *VAAI) {
return NewPtr; return NewPtr;
} }
bool AliasSetTracker::add(MemSetInst *MSI) {
AAMDNodes AAInfo;
MSI->getAAMetadata(AAInfo);
bool NewPtr;
uint64_t Len;
if (ConstantInt *C = dyn_cast<ConstantInt>(MSI->getLength()))
Len = C->getZExtValue();
else
Len = MemoryLocation::UnknownSize;
AliasSet &AS =
addPointer(MSI->getDest(), Len, AAInfo, AliasSet::ModAccess, NewPtr);
if (MSI->isVolatile())
AS.setVolatile();
return NewPtr;
}
bool AliasSetTracker::addUnknown(Instruction *Inst) { bool AliasSetTracker::addUnknown(Instruction *Inst) {
if (isa<DbgInfoIntrinsic>(Inst)) if (isa<DbgInfoIntrinsic>(Inst))
@ -368,7 +386,10 @@ bool AliasSetTracker::add(Instruction *I) {
return add(SI); return add(SI);
if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I)) if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
return add(VAAI); return add(VAAI);
if (MemSetInst *MSI = dyn_cast<MemSetInst>(I))
return add(MSI);
return addUnknown(I); return addUnknown(I);
// FIXME: add support of memcpy and memmove.
} }
void AliasSetTracker::add(BasicBlock &BB) { void AliasSetTracker::add(BasicBlock &BB) {
@ -479,6 +500,23 @@ bool AliasSetTracker::remove(VAArgInst *VAAI) {
return true; return true;
} }
bool AliasSetTracker::remove(MemSetInst *MSI) {
AAMDNodes AAInfo;
MSI->getAAMetadata(AAInfo);
uint64_t Len;
if (ConstantInt *C = dyn_cast<ConstantInt>(MSI->getLength()))
Len = C->getZExtValue();
else
Len = MemoryLocation::UnknownSize;
AliasSet *AS = findAliasSetForPointer(MSI->getDest(), Len, AAInfo);
if (!AS)
return false;
remove(*AS);
return true;
}
bool AliasSetTracker::removeUnknown(Instruction *I) { bool AliasSetTracker::removeUnknown(Instruction *I) {
if (!I->mayReadOrWriteMemory()) if (!I->mayReadOrWriteMemory())
return false; // doesn't alias anything return false; // doesn't alias anything
@ -497,7 +535,10 @@ bool AliasSetTracker::remove(Instruction *I) {
return remove(SI); return remove(SI);
if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I)) if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
return remove(VAAI); return remove(VAAI);
if (MemSetInst *MSI = dyn_cast<MemSetInst>(I))
return remove(MSI);
return removeUnknown(I); return removeUnknown(I);
// FIXME: add support of memcpy and memmove.
} }

View File

@ -0,0 +1,51 @@
; RUN: opt < %s -loop-deletion -licm -loop-idiom -disable-output
; Check no assertion when loop-idiom deletes the MemSet already analyzed by licm
define void @set_array() {
br i1 false, label %bb3.preheader.lr.ph, label %bb9
bb3.preheader.lr.ph: ; preds = %0
br label %bb3.preheader
bb4: ; preds = %bb4.lr.ph, %bb7
%j.3.06 = phi i8 [ %j.3.17, %bb4.lr.ph ], [ %_tmp13, %bb7 ]
br label %bb6
bb6: ; preds = %bb4, %bb6
%k.4.04 = phi i8 [ 0, %bb4 ], [ %_tmp9, %bb6 ]
%_tmp31 = sext i8 %j.3.06 to i64
%_tmp4 = mul i64 %_tmp31, 10
%_tmp5 = getelementptr i8, i8* undef, i64 %_tmp4
%_tmp7 = getelementptr i8, i8* %_tmp5, i8 %k.4.04
store i8 42, i8* %_tmp7
%_tmp9 = add i8 %k.4.04, 1
%_tmp11 = icmp slt i8 %_tmp9, 10
br i1 %_tmp11, label %bb6, label %bb7
bb7: ; preds = %bb6
%_tmp13 = add i8 %j.3.06, 1
%_tmp15 = icmp slt i8 %_tmp13, 2
br i1 %_tmp15, label %bb4, label %bb3.bb1.loopexit_crit_edge
bb3.bb1.loopexit_crit_edge: ; preds = %bb7
%split = phi i8 [ %_tmp13, %bb7 ]
br label %bb1.loopexit
bb1.loopexit: ; preds = %bb3.bb1.loopexit_crit_edge, %bb3.preheader
%j.3.0.lcssa = phi i8 [ %split, %bb3.bb1.loopexit_crit_edge ], [ %j.3.17, %bb3.preheader ]
br i1 false, label %bb3.preheader, label %bb1.bb9_crit_edge
bb3.preheader: ; preds = %bb3.preheader.lr.ph, %bb1.loopexit
%j.3.17 = phi i8 [ undef, %bb3.preheader.lr.ph ], [ %j.3.0.lcssa, %bb1.loopexit ]
%_tmp155 = icmp slt i8 %j.3.17, 2
br i1 %_tmp155, label %bb4.lr.ph, label %bb1.loopexit
bb4.lr.ph: ; preds = %bb3.preheader
br label %bb4
bb1.bb9_crit_edge: ; preds = %bb1.loopexit
br label %bb9
bb9: ; preds = %bb1.bb9_crit_edge, %0
ret void
}