Skip to content

Commit

Permalink
[EarlyCSE] Don't DSE across readnone functions that may throw
Browse files Browse the repository at this point in the history
Summary: Depends on D28740

Reviewers: dberlin, chandlerc, hfinkel, majnemer

Subscribers: mcrosier, llvm-commits

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

llvm-svn: 292249
  • Loading branch information
sanjoy committed Jan 17, 2017
1 parent f42a955 commit 6de072a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
13 changes: 7 additions & 6 deletions llvm/lib/Transforms/Scalar/EarlyCSE.cpp
Expand Up @@ -761,12 +761,13 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
continue;
}

// If this instruction may read from memory, forget LastStore.
// Load/store intrinsics will indicate both a read and a write to
// memory. The target may override this (e.g. so that a store intrinsic
// does not read from memory, and thus will be treated the same as a
// regular store for commoning purposes).
if (Inst->mayReadFromMemory() &&
// If this instruction may read from memory or throw (and potentially read
// from memory in the exception handler), forget LastStore. Load/store
// intrinsics will indicate both a read and a write to memory. The target
// may override this (e.g. so that a store intrinsic does not read from
// memory, and thus will be treated the same as a regular store for
// commoning purposes).
if ((Inst->mayReadFromMemory() || Inst->mayThrow()) &&
!(MemInst.isValid() && !MemInst.mayReadFromMemory()))
LastStore = nullptr;

Expand Down
15 changes: 15 additions & 0 deletions llvm/test/Transforms/EarlyCSE/readnone-mayunwind.ll
@@ -0,0 +1,15 @@
; RUN: opt -S -early-cse < %s | FileCheck %s

declare void @readnone_may_unwind() readnone

define void @f(i32* %ptr) {
; CHECK-LABEL: @f(
; CHECK: store i32 100, i32* %ptr
; CHECK: call void @readnone_may_unwind()
; CHECK: store i32 200, i32* %ptr

store i32 100, i32* %ptr
call void @readnone_may_unwind()
store i32 200, i32* %ptr
ret void
}

0 comments on commit 6de072a

Please sign in to comment.