[llvm] 4afb10d - llvm-reduce: Reduce prefix data
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 3 08:05:52 PST 2023
Author: Matt Arsenault
Date: 2023-01-03T11:03:43-05:00
New Revision: 4afb10d572ead76b033c72195f6d280014e04ccc
URL: https://github.com/llvm/llvm-project/commit/4afb10d572ead76b033c72195f6d280014e04ccc
DIFF: https://github.com/llvm/llvm-project/commit/4afb10d572ead76b033c72195f6d280014e04ccc.diff
LOG: llvm-reduce: Reduce prefix data
Also fixes broken cloning.
Added:
llvm/test/tools/llvm-reduce/reduce-prefix-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 1051b62ab294..7e84191c799a 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -112,6 +112,13 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
TypeMapper, Materializer));
+ if (OldFunc->hasPrefixData()) {
+ NewFunc->setPrefixData(
+ MapValue(OldFunc->getPrefixData(), VMap,
+ ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
+ TypeMapper, Materializer));
+ }
+
SmallVector<AttributeSet, 4> NewArgAttrs(NewFunc->arg_size());
AttributeList OldAttrs = OldFunc->getAttributes();
diff --git a/llvm/test/tools/llvm-reduce/reduce-prefix-data.ll b/llvm/test/tools/llvm-reduce/reduce-prefix-data.ll
new file mode 100644
index 000000000000..7abc7b650e73
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-prefix-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_prefix_i32_const()
+define void @drop_prefix_i32_const() prefix i32 1 {
+ ret void
+}
+
+; CHECK: define void @keep_prefix_i32_const() prefix i32 1 {
+define void @keep_prefix_i32_const() prefix i32 1 {
+ ret void
+}
+
+; CHECK: define void @drop_prefix_ptr_global()
+define void @drop_prefix_ptr_global() prefix ptr @gv {
+ ret void
+}
+
+; CHECK: define void @keep_prefix_ptr_global() prefix ptr @gv {
+define void @keep_prefix_ptr_global() prefix ptr @gv {
+ ret void
+}
+
+; Make sure there's no invalid reduction if the prefix data is really
+; accessed
+; CHECK: define i32 @drop_uses_prefix_i32_const()
+define i32 @drop_uses_prefix_i32_const() prefix i32 1 {
+ %gep = getelementptr inbounds i32, ptr @drop_uses_prefix_i32_const, i32 -1
+ %load = load i32, ptr %gep
+ ret i32 %load
+}
+
+; CHECK: define ptr @drop_uses_prefix_gv(
+define ptr @drop_uses_prefix_gv() prefix ptr @gv {
+ %gep = getelementptr inbounds i32, ptr @drop_uses_prefix_gv, i32 -1
+ %load = load ptr, ptr %gep
+ ret ptr %load
+}
+
+
+; RESULT: declare void @declaration_prefix_i32_const(){{$}}
+declare void @declaration_prefix_i32_const() prefix i32 2
+
+; RESULT: void @declaration_prefix_ptr_gv(){{$}}
+declare void @declaration_prefix_ptr_gv() prefix ptr @gv
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp b/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
index 89dcbf42852e..bda3e2113ef3 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
@@ -38,9 +38,6 @@ void llvm::reduceFunctionBodiesDeltaPass(TestRunner &Test) {
static void reduceFunctionData(Oracle &O, Module &M) {
for (Function &F : M) {
- if (F.isDeclaration())
- continue;
-
if (F.hasPersonalityFn()) {
if (none_of(F,
[](const BasicBlock &BB) {
@@ -51,7 +48,10 @@ static void reduceFunctionData(Oracle &O, Module &M) {
}
}
- // TODO: Handle prefix data and prologue data
+ if (F.hasPrefixData() && !O.shouldKeep())
+ F.setPrefixData(nullptr);
+
+ // TODO: Handle prologue data
}
}
More information about the llvm-commits
mailing list