[InstCombine] Don't DSE across readnone functions that may throw

Summary: Depends on D28740

Reviewers: dberlin, chandlerc, hfinkel, majnemer

Subscribers: mcrosier, llvm-commits

Differential Revision: https://reviews.llvm.org/D28742

llvm-svn: 292197
This commit is contained in:
Sanjoy Das 2017-01-17 05:45:09 +00:00
parent 3583c8597d
commit 679bc32c6a
2 changed files with 39 additions and 5 deletions

View File

@ -1267,8 +1267,8 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) {
break;
}
// Don't skip over loads or things that can modify memory.
if (BBI->mayWriteToMemory() || BBI->mayReadFromMemory())
// Don't skip over loads, throws or things that can modify memory.
if (BBI->mayWriteToMemory() || BBI->mayReadFromMemory() || BBI->mayThrow())
break;
}
@ -1391,8 +1391,8 @@ bool InstCombiner::SimplifyStoreAtEndOfBlock(StoreInst &SI) {
}
// If we find something that may be using or overwriting the stored
// value, or if we run out of instructions, we can't do the xform.
if (BBI->mayReadFromMemory() || BBI->mayWriteToMemory() ||
BBI == OtherBB->begin())
if (BBI->mayReadFromMemory() || BBI->mayThrow() ||
BBI->mayWriteToMemory() || BBI == OtherBB->begin())
return false;
}
@ -1401,7 +1401,7 @@ bool InstCombiner::SimplifyStoreAtEndOfBlock(StoreInst &SI) {
// StoreBB.
for (BasicBlock::iterator I = StoreBB->begin(); &*I != &SI; ++I) {
// FIXME: This should really be AA driven.
if (I->mayReadFromMemory() || I->mayWriteToMemory())
if (I->mayReadFromMemory() || I->mayThrow() || I->mayWriteToMemory())
return false;
}
}

View File

@ -0,0 +1,34 @@
; RUN: opt -S -instcombine < %s | FileCheck %s
declare void @readnone_but_may_throw() readnone
define void @f_0(i32* %ptr) {
; CHECK-LABEL: @f_0(
entry:
; CHECK: store i32 10, i32* %ptr
; CHECK-NEXT: call void @readnone_but_may_throw()
; CHECK-NEXT: store i32 20, i32* %ptr, align 4
; CHECK: ret void
store i32 10, i32* %ptr
call void @readnone_but_may_throw()
store i32 20, i32* %ptr
ret void
}
define void @f_1(i1 %cond, i32* %ptr) {
; CHECK-LABEL: @f_1(
; CHECK: store i32 10, i32* %ptr
; CHECK-NEXT: call void @readnone_but_may_throw()
store i32 10, i32* %ptr
call void @readnone_but_may_throw()
br i1 %cond, label %left, label %merge
left:
store i32 20, i32* %ptr
br label %merge
merge:
ret void
}