[llvm] e60b0d2 - llvm-reduce: Reduce prologue data
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 3 08:08:12 PST 2023
Author: Matt Arsenault
Date: 2023-01-03T11:07:02-05:00
New Revision: e60b0d2a2227a3fa299884bc3388baecdd4c88e6
URL: https://github.com/llvm/llvm-project/commit/e60b0d2a2227a3fa299884bc3388baecdd4c88e6
DIFF: https://github.com/llvm/llvm-project/commit/e60b0d2a2227a3fa299884bc3388baecdd4c88e6.diff
LOG: llvm-reduce: Reduce prologue data
Identical to the prefix data handling, and also had broken cloning.
Added:
llvm/test/tools/llvm-reduce/reduce-prologue-data.ll
Modified:
llvm/lib/Transforms/Utils/CloneFunction.cpp
llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 7e84191c799a..87822ee85c2b 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -105,18 +105,25 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
NewFunc->copyAttributesFrom(OldFunc);
NewFunc->setAttributes(NewAttrs);
+ const RemapFlags FuncGlobalRefFlags =
+ ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges;
+
// Fix up the personality function that got copied over.
if (OldFunc->hasPersonalityFn())
- NewFunc->setPersonalityFn(
- MapValue(OldFunc->getPersonalityFn(), VMap,
- ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
- TypeMapper, Materializer));
+ NewFunc->setPersonalityFn(MapValue(OldFunc->getPersonalityFn(), VMap,
+ FuncGlobalRefFlags, TypeMapper,
+ Materializer));
if (OldFunc->hasPrefixData()) {
- NewFunc->setPrefixData(
- MapValue(OldFunc->getPrefixData(), VMap,
- ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
- TypeMapper, Materializer));
+ NewFunc->setPrefixData(MapValue(OldFunc->getPrefixData(), VMap,
+ FuncGlobalRefFlags, TypeMapper,
+ Materializer));
+ }
+
+ if (OldFunc->hasPrologueData()) {
+ NewFunc->setPrologueData(MapValue(OldFunc->getPrologueData(), VMap,
+ FuncGlobalRefFlags, TypeMapper,
+ Materializer));
}
SmallVector<AttributeSet, 4> NewArgAttrs(NewFunc->arg_size());
diff --git a/llvm/test/tools/llvm-reduce/reduce-prologue-data.ll b/llvm/test/tools/llvm-reduce/reduce-prologue-data.ll
new file mode 100644
index 000000000000..4c9418875f4b
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-prologue-data.ll
@@ -0,0 +1,47 @@
+; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=function-data --test FileCheck --test-arg --check-prefix=CHECK --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck -check-prefixes=CHECK,RESULT %s < %t
+
+ at gv = linkonce_odr global i32 1
+
+; CHECK: define void @drop_prologue_const_array()
+define void @drop_prologue_const_array() prologue [2 x i32] [i32 1, i32 2] {
+ ret void
+}
+
+; CHECK: define void @keep_prologue_const_array() prologue i32 1 {
+define void @keep_prologue_const_array() prologue i32 1 {
+ ret void
+}
+
+; CHECK: define void @drop_prologue_ptr_global()
+define void @drop_prologue_ptr_global() prologue ptr @gv {
+ ret void
+}
+
+; CHECK: define void @keep_prologue_ptr_global() prologue ptr @gv {
+define void @keep_prologue_ptr_global() prologue ptr @gv {
+ ret void
+}
+
+; Make sure there's no invalid reduction if the prologue data is really
+; accessed
+; CHECK: define i32 @drop_uses_prologue_const_array()
+define i32 @drop_uses_prologue_const_array() prologue [2 x i32] [i32 1, i32 2] {
+ %gep = getelementptr inbounds i32, ptr @drop_uses_prologue_const_array, i32 -1
+ %load = load i32, ptr %gep
+ ret i32 %load
+}
+
+; CHECK: define ptr @drop_uses_prologue_gv(
+define ptr @drop_uses_prologue_gv() prologue ptr @gv {
+ %gep = getelementptr inbounds i32, ptr @drop_uses_prologue_gv, i32 -1
+ %load = load ptr, ptr %gep
+ ret ptr %load
+}
+
+
+; RESULT: declare void @declaration_prologue_const_array(){{$}}
+declare void @declaration_prologue_const_array() prologue [2 x i32] [i32 1, i32 2]
+
+; RESULT: void @declaration_prologue_ptr_gv(){{$}}
+declare void @declaration_prologue_ptr_gv() prologue ptr @gv
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp b/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
index bda3e2113ef3..98a280f74000 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
@@ -51,7 +51,8 @@ static void reduceFunctionData(Oracle &O, Module &M) {
if (F.hasPrefixData() && !O.shouldKeep())
F.setPrefixData(nullptr);
- // TODO: Handle prologue data
+ if (F.hasPrologueData() && !O.shouldKeep())
+ F.setPrologueData(nullptr);
}
}
More information about the llvm-commits
mailing list