From: Florian Hahn Date: Fri, 4 Sep 2020 16:19:56 +0000 (+0100) Subject: [DSE,MemorySSA] Check for throwing instrs between killing/killed def. X-Git-Tag: llvmorg-13-init~12894 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=00eb6fef0809ed143975ad16f3988a4fee13261b;p=platform%2Fupstream%2Fllvm.git [DSE,MemorySSA] Check for throwing instrs between killing/killed def. We also have to check all uses between the killing & killed def and check if any of them is throwing. --- diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 7e4ef1e..0296d20 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -2023,6 +2023,14 @@ struct DSEState { if (isMemTerminator(DefLoc, UseInst)) continue; + if (UseInst->mayThrow() && !isInvisibleToCallerBeforeRet(DefUO)) { + LLVM_DEBUG(dbgs() << " ... found throwing instruction\n"); + Cache.KnownReads.insert(UseAccess); + Cache.KnownReads.insert(StartAccess); + Cache.KnownReads.insert(EarlierAccess); + return None; + } + // Uses which may read the original MemoryDef mean we cannot eliminate the // original MD. Stop walk. if (isReadClobber(DefLoc, UseInst)) { diff --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-malloc-free.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-malloc-free.ll index 46712cc..763362d 100644 --- a/llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-malloc-free.ll +++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-malloc-free.ll @@ -37,10 +37,12 @@ bb3: ret void } - +; We cannot remove the store in the entry block, because @unknown_func could +; unwind and the stored value could be read by the caller. define void @test17(i32* noalias %P) { ; CHECK-LABEL: @test17( ; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to i8* +; CHECK-NEXT: store i32 1, i32* [[P]], align 4 ; CHECK-NEXT: br i1 true, label [[BB1:%.*]], label [[BB3:%.*]] ; CHECK: bb1: ; CHECK-NEXT: call void @unknown_func() diff --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-throwing.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-throwing.ll index d297ac3..f6031e8 100644 --- a/llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-throwing.ll +++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-throwing.ll @@ -1,5 +1,4 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; XFAIL: * ; RUN: opt < %s -basic-aa -dse -enable-dse-memoryssa -S | FileCheck %s target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"