[PATCH] D149563: [TRE] Mark alloca's as escaped if their call does not write memory
Joshua Cao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 30 22:41:10 PDT 2023
caojoshua updated this revision to Diff 518402.
caojoshua retitled this revision from "[TRE] don't escape callsite if its alloca argument is readonly" to "[TRE] Mark alloca's as escaped if their call does not write memory".
caojoshua edited the summary of this revision.
caojoshua added a comment.
Update this patch to not mark alloca's as escaped even if their call does not write to memory.
I added some more pre-committed tests for memory(none|read) functions. After this patch, they are no longer marked as tail calls
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149563/new/
https://reviews.llvm.org/D149563
Files:
llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
llvm/test/Transforms/TailCallElim/basic.ll
Index: llvm/test/Transforms/TailCallElim/basic.ll
===================================================================
--- llvm/test/Transforms/TailCallElim/basic.ll
+++ llvm/test/Transforms/TailCallElim/basic.ll
@@ -259,7 +259,7 @@
define void @test17() {
; CHECK-LABEL: @test17
; CHECK-NOT: tail call void @use_memory_none
-; CHECK: tail call void @noarg
+; CHECK-NOT: tail call void @noarg
entry:
%x = alloca i32, align 4
call void @use_memory_none(ptr %x)
@@ -270,7 +270,7 @@
define void @test18() {
; CHECK-LABEL: @test18
; CHECK-NOT: tail call void @use_memory_read
-; CHECK: tail call void @noarg
+; CHECK-NOT: tail call void @noarg
entry:
%x = alloca i32, align 4
call void @use_memory_read(ptr %x)
Index: llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
+++ llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
@@ -133,14 +133,12 @@
// beyond the lifetime of the current frame.
if (CB.isArgOperand(U) && CB.isByValArgument(CB.getArgOperandNo(U)))
continue;
- bool IsNocapture =
- CB.isDataOperand(U) && CB.doesNotCapture(CB.getDataOperandNo(U));
- callUsesLocalStack(CB, IsNocapture);
- if (IsNocapture) {
+ AllocaUsers.insert(&CB);
+ if (!CB.isDataOperand(U) || CB.doesNotCapture(CB.getDataOperandNo(U)))
// If the alloca-derived argument is passed in as nocapture, then it
// can't propagate to the call's return. That would be capturing.
continue;
- }
+ EscapePoints.insert(&CB);
break;
}
case Instruction::Load: {
@@ -168,19 +166,6 @@
}
}
- void callUsesLocalStack(CallBase &CB, bool IsNocapture) {
- // Add it to the list of alloca users.
- AllocaUsers.insert(&CB);
-
- // If it's nocapture then it can't capture this alloca.
- if (IsNocapture)
- return;
-
- // If it can write to memory, it can leak the alloca value.
- if (!CB.onlyReadsMemory())
- EscapePoints.insert(&CB);
- }
-
SmallPtrSet<Instruction *, 32> AllocaUsers;
SmallPtrSet<Instruction *, 32> EscapePoints;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149563.518402.patch
Type: text/x-patch
Size: 2237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230501/a9b486cb/attachment.bin>
More information about the llvm-commits
mailing list