[llvm] 00eb6fe - [DSE,MemorySSA] Check for throwing instrs between killing/killed def.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 4 10:55:46 PDT 2020
Author: Florian Hahn
Date: 2020-09-04T18:54:59+01:00
New Revision: 00eb6fef0809ed143975ad16f3988a4fee13261b
URL: https://github.com/llvm/llvm-project/commit/00eb6fef0809ed143975ad16f3988a4fee13261b
DIFF: https://github.com/llvm/llvm-project/commit/00eb6fef0809ed143975ad16f3988a4fee13261b.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-malloc-free.ll
llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-throwing.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 7e4ef1ed9cd8..0296d20bc07b 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 46712ccc92ff..763362dd3d47 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 d297ac3f44f8..f6031e86bef0 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"
More information about the llvm-commits
mailing list