From 90b7e38b05d209a93be3e0507998089885e9da3f Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Tue, 17 Jan 2017 20:15:47 +0000 Subject: [PATCH] [EarlyCSE] 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/D28741 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292249 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/EarlyCSE.cpp | 13 +++++++------ test/Transforms/EarlyCSE/readnone-mayunwind.ll | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 test/Transforms/EarlyCSE/readnone-mayunwind.ll diff --git a/lib/Transforms/Scalar/EarlyCSE.cpp b/lib/Transforms/Scalar/EarlyCSE.cpp index ab44d84ac49..5fc0dab9047 100644 --- a/lib/Transforms/Scalar/EarlyCSE.cpp +++ b/lib/Transforms/Scalar/EarlyCSE.cpp @@ -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; diff --git a/test/Transforms/EarlyCSE/readnone-mayunwind.ll b/test/Transforms/EarlyCSE/readnone-mayunwind.ll new file mode 100644 index 00000000000..47a513f2d6a --- /dev/null +++ b/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 +} -- 2.50.1