[PATCH] D117543: [DSE] Handle inaccessiblememonly calloc
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 19 03:55:24 PST 2022
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG26f81984e797: [DSE] Handle inaccessiblememonly calloc (authored by nikic).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D117543/new/
https://reviews.llvm.org/D117543
Files:
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/calloc-store.ll
llvm/test/Transforms/DeadStoreElimination/noop-stores.ll
llvm/test/Transforms/DeadStoreElimination/operand-bundles.ll
Index: llvm/test/Transforms/DeadStoreElimination/operand-bundles.ll
===================================================================
--- llvm/test/Transforms/DeadStoreElimination/operand-bundles.ll
+++ llvm/test/Transforms/DeadStoreElimination/operand-bundles.ll
@@ -42,7 +42,7 @@
ret void
}
-declare noalias i8* @calloc(i64, i64)
+declare noalias i8* @calloc(i64, i64) inaccessiblememonly
define void @test4() {
; CHECK-LABEL: @test4
Index: llvm/test/Transforms/DeadStoreElimination/noop-stores.ll
===================================================================
--- llvm/test/Transforms/DeadStoreElimination/noop-stores.ll
+++ llvm/test/Transforms/DeadStoreElimination/noop-stores.ll
@@ -378,7 +378,7 @@
}
; This should not create recursive call to calloc.
-define i8* @calloc(i64 %nmemb, i64 %size) {
+define i8* @calloc(i64 %nmemb, i64 %size) inaccessiblememonly {
; CHECK-LABEL: @calloc(
; CHECK: entry:
; CHECK-NEXT: [[MUL:%.*]] = mul i64 [[SIZE:%.*]], [[NMEMB:%.*]]
@@ -488,7 +488,6 @@
define i8* @store_zero_after_calloc_inaccessiblememonly() {
; CHECK-LABEL: @store_zero_after_calloc_inaccessiblememonly(
; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 1, i64 10) #[[ATTR6:[0-9]+]]
-; CHECK-NEXT: store i8 0, i8* [[CALL]], align 1
; CHECK-NEXT: ret i8* [[CALL]]
;
%call = tail call i8* @calloc(i64 1, i64 10) inaccessiblememonly
@@ -582,7 +581,6 @@
define i8* @zero_memset_after_calloc_inaccessiblememonly() {
; CHECK-LABEL: @zero_memset_after_calloc_inaccessiblememonly(
; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4) #[[ATTR6]]
-; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[CALL]], i8 0, i64 40000, i1 false)
; CHECK-NEXT: ret i8* [[CALL]]
;
%call = tail call i8* @calloc(i64 10000, i64 4) inaccessiblememonly
Index: llvm/test/Transforms/DeadStoreElimination/calloc-store.ll
===================================================================
--- llvm/test/Transforms/DeadStoreElimination/calloc-store.ll
+++ llvm/test/Transforms/DeadStoreElimination/calloc-store.ll
@@ -1,6 +1,6 @@
; RUN: opt < %s -basic-aa -dse -S | FileCheck %s
-declare noalias i8* @calloc(i64, i64)
+declare noalias i8* @calloc(i64, i64) inaccessiblememonly
define i32* @test1() {
; CHECK-LABEL: test1
Index: llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1786,14 +1786,11 @@
auto *CB = cast<CallBase>(DefUO);
auto *InitC = getInitialValueOfAllocation(CB, &TLI,
StoredConstant->getType());
- if (InitC && InitC == StoredConstant) {
- auto *UnderlyingDef = cast<MemoryDef>(MSSA.getMemoryAccess(CB));
- // If UnderlyingDef is the clobbering access of Def, no instructions
- // between them can modify the memory location.
- auto *ClobberDef =
- MSSA.getSkipSelfWalker()->getClobberingMemoryAccess(Def);
- return UnderlyingDef == ClobberDef;
- }
+ // If the clobbering access is LiveOnEntry, no instructions between them
+ // can modify the memory location.
+ if (InitC && InitC == StoredConstant)
+ return MSSA.isLiveOnEntryDef(
+ MSSA.getSkipSelfWalker()->getClobberingMemoryAccess(Def));
}
if (!Store)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117543.401166.patch
Type: text/x-patch
Size: 3447 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220119/f55f6bb3/attachment.bin>
More information about the llvm-commits
mailing list