Author: Roman Lebedev Date: 2021-01-07T18:05:03+03:00 New Revision: 8dee0b4bd6376f5518accf45e9ecc4a44a4c8481
URL: https://github.com/llvm/llvm-project/commit/8dee0b4bd6376f5518accf45e9ecc4a44a4c8481 DIFF: https://github.com/llvm/llvm-project/commit/8dee0b4bd6376f5518accf45e9ecc4a44a4c8481.diff LOG: [llvm-reduce] ReduceGlobalVarInitializers delta pass: fix handling of globals w/ comdat/non-external linkage Much like with ReduceFunctionBodies delta pass, we need to remove comdat and set linkage to external, else verifier will complain, and our deltas are invalid. Added: Modified: llvm/test/Reduce/remove-global-vars.ll llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.cpp Removed: ################################################################################ diff --git a/llvm/test/Reduce/remove-global-vars.ll b/llvm/test/Reduce/remove-global-vars.ll index d078cad6b995..e791fd50bf7c 100644 --- a/llvm/test/Reduce/remove-global-vars.ll +++ b/llvm/test/Reduce/remove-global-vars.ll @@ -4,16 +4,25 @@ ; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t ; RUN: cat %t | FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL --implicit-check-not=uninteresting %s +$interesting5 = comdat any + ; CHECK-INTERESTINGNESS: @interesting = {{.*}}global i32{{.*}}, align 4 ; CHECK-INTERESTINGNESS: @interesting2 = global i32 0, align 4 ; CHECK-INTERESTINGNESS: @interesting3 = {{.*}}global i32{{.*}}, align 4 +; CHECK-INTERESTINGNESS: @interesting4 = {{.*}}constant i32{{.*}}, align 4 +; CHECK-INTERESTINGNESS: @interesting5 = {{.*}}global i32{{.*}}, align 4 ; CHECK-FINAL: @interesting = external global i32, align 4 ; CHECK-FINAL: @interesting2 = global i32 0, align 4 ; CHECK-FINAL: @interesting3 = external global i32, align 4 +; CHECK-FINAL: @interesting4 = external dso_local constant i32, align 4 +; CHECK-FINAL: @interesting5 = external global i32, align 4 @interesting = global i32 0, align 4 @interesting2 = global i32 0, align 4 @interesting3 = external global i32, align 4 +@interesting4 = private constant i32 2, align 4 +@interesting5 = global i32 2, align 4, comdat + @uninteresting = global i32 1, align 4 @uninteresting2 = external global i32, align 4 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.cpp b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.cpp index 1128710f64c4..fd5a5d1f02c6 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.cpp @@ -13,6 +13,7 @@ #include "ReduceGlobalVarInitializers.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/GlobalValue.h" using namespace llvm; @@ -23,8 +24,11 @@ static void extractGVsFromModule(std::vector<Chunk> ChunksToKeep, // Drop initializers of out-of-chunk GVs for (auto &GV : Program->globals()) - if (GV.hasInitializer() && !O.shouldKeep()) + if (GV.hasInitializer() && !O.shouldKeep()) { GV.setInitializer(nullptr); + GV.setLinkage(GlobalValue::LinkageTypes::ExternalLinkage); + GV.setComdat(nullptr); + } } /// Counts the amount of initialized GVs and displays their _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits