-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[ELFObject.cpp] Added dbgs() statement in removeSections() Function #124582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ilogb libcall was not being constant folded correctly. It was due to LibCallShrinkWrap pass not handling ilogbx, as a result SimplifyCFG pass did not remove redundant libcall. This patch adds ilogb case in performCallErrors(). Fixes llvm#101873
ilogb libcall was not being constant folded correctly. This patch adds ilogb with its correct domain in isMathLibCallNoop(). Fixes llvm#101873
I have added the dbgs() function inside removeSections() function to print the removed sections and symbols. Fixes: llvm#123041
Member
|
@llvm/pr-subscribers-llvm-binary-utilities @llvm/pr-subscribers-llvm-analysis Author: Kshitij Paranjape (kshitijvp) ChangesAddeed dbgs() in removeSections() function to print the removed Fixes: #123041 Full diff: https://github.com/llvm/llvm-project/pull/124582.diff 4 Files Affected:
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 031d675c330ec4..6814a1e4d8394c 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -3807,6 +3807,9 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,
case LibFunc_log10f:
return Op.isNaN() || (!Op.isZero() && !Op.isNegative());
+ case LibFunc_ilogb:
+ return !Op.isNaN() && !Op.isZero() && !Op.isInfinity();
+
case LibFunc_expl:
case LibFunc_exp:
case LibFunc_expf:
diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
index 01c2f24629077a..340edebbc67902 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -766,8 +766,14 @@ Error SymbolTableSection::removeSymbols(
function_ref<bool(const Symbol &)> ToRemove) {
Symbols.erase(
std::remove_if(std::begin(Symbols) + 1, std::end(Symbols),
- [ToRemove](const SymPtr &Sym) { return ToRemove(*Sym); }),
- std::end(Symbols));
+ [ToRemove](const SymPtr &Sym) {
+ if (ToRemove(*Sym)) {
+ dbgs()<<"Symbols Removed:"<<Sym->Name<< "\n";
+ return true;
+ }
+ return false;
+ }));
+
auto PrevSize = Size;
Size = Symbols.size() * EntrySize;
if (Size < PrevSize)
@@ -2240,10 +2246,18 @@ Error Object::removeSections(
// Transfer removed sections into the Object RemovedSections container for use
// later.
- std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
- // Now finally get rid of them all together.
- Sections.erase(Iter, std::end(Sections));
- return Error::success();
+ for(auto &KeepSec : make_range(std::begin(Sections) , Iter))
+ {
+
+ if (Error E = KeepSec->removeSectionReferences(
+ AllowBrokenLinks, [&RemoveSections](const SectionBase *Sec) {
+ return RemoveSections.find(Sec) != RemoveSections.end();
+ }))
+ std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
+ dbgs()<<"Sections Removed:"<<KeepSec->Name<<'\n';
+ Sections.erase(Iter, std::end(Sections));
+ return Error::success();
+ }
}
Error Object::replaceSections(
diff --git a/llvm/test/Transforms/InstSimplify/pr122582.ll b/llvm/test/Transforms/InstSimplify/pr122582.ll
new file mode 100644
index 00000000000000..fd507e39eccdda
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/pr122582.ll
@@ -0,0 +1,213 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+
+define i32 @ilogbf_const1() {
+; CHECK-LABEL: define i32 @ilogbf_const1() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogbf(float 7.000000e+00)
+; CHECK-NEXT: ret i32 2
+;
+ %r = call i32 @ilogbf(float 7.000000e+00)
+ ret i32 %r
+}
+
+define i32 @ilogb_const1() {
+; CHECK-LABEL: define i32 @ilogb_const1() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogb(double -7.000000e+00)
+; CHECK-NEXT: ret i32 2
+;
+ %r = call i32 @ilogb(double -7.000000e+00)
+ ret i32 %r
+}
+
+define i32 @ilogbf_const2() {
+; CHECK-LABEL: define i32 @ilogbf_const2() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogbf(float 5.000000e-01)
+; CHECK-NEXT: ret i32 -1
+;
+ %r = call i32 @ilogbf(float 5.000000e-01)
+ ret i32 %r
+}
+
+define i32 @ilogb_const2() {
+; CHECK-LABEL: define i32 @ilogb_const2() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogb(double -5.000000e-01)
+; CHECK-NEXT: ret i32 -1
+;
+ %r = call i32 @ilogb(double -5.000000e-01)
+ ret i32 %r
+}
+
+define i32 @ilogbf_zero() {
+; CHECK-LABEL: define i32 @ilogbf_zero() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogbf(float 0.000000e+00)
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogbf(float 0.000000e+00)
+ ret i32 %r
+}
+
+define i32 @ilogb_zero() {
+; CHECK-LABEL: define i32 @ilogb_zero() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogb(double 0.000000e+00)
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogb(double 0.000000e+00)
+ ret i32 %r
+}
+
+define i32 @ilogbf_neg_zero() {
+; CHECK-LABEL: define i32 @ilogbf_neg_zero() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogbf(float -0.000000e+00)
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogbf(float -0.000000e+00)
+ ret i32 %r
+}
+
+define i32 @ilogb_neg_zero() {
+; CHECK-LABEL: define i32 @ilogb_neg_zero() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogb(double -0.000000e+00)
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogb(double -0.000000e+00)
+ ret i32 %r
+}
+
+define i32 @ilogbf_inf() {
+; CHECK-LABEL: define i32 @ilogbf_inf() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogbf(float 0x7FF0000000000000)
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogbf(float 0x7FF0000000000000)
+ ret i32 %r
+}
+
+define i32 @ilogb_inf() {
+; CHECK-LABEL: define i32 @ilogb_inf() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogb(double 0x7FF0000000000000)
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogb(double 0x7FF0000000000000)
+ ret i32 %r
+}
+
+define i32 @ilogbf_nan() {
+; CHECK-LABEL: define i32 @ilogbf_nan() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogbf(float 0x7FF8000000000000)
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogbf(float 0x7FF8000000000000)
+ ret i32 %r
+}
+
+define i32 @ilogb_nan() {
+; CHECK-LABEL: define i32 @ilogb_nan() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogb(double 0x7FF8000000000000)
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogb(double 0x7FF8000000000000)
+ ret i32 %r
+}
+
+define i32 @ilogbf_zero_readnone() {
+; CHECK-LABEL: define i32 @ilogbf_zero_readnone() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogbf(float 0.000000e+00) #[[ATTR1:[0-9]+]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogbf(float 0.000000e+00) readnone
+ ret i32 %r
+}
+
+define i32 @ilogb_zero_readnone() {
+; CHECK-LABEL: define i32 @ilogb_zero_readnone() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogb(double 0.000000e+00) #[[ATTR1]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogb(double 0.000000e+00) readnone
+ ret i32 %r
+}
+
+define i32 @ilogbf_neg_zero_readnone() {
+; CHECK-LABEL: define i32 @ilogbf_neg_zero_readnone() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogbf(float -0.000000e+00) #[[ATTR1]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogbf(float -0.000000e+00) readnone
+ ret i32 %r
+}
+
+define i32 @ilogb_neg_zero_readnone() {
+; CHECK-LABEL: define i32 @ilogb_neg_zero_readnone() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogb(double -0.000000e+00) #[[ATTR1]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogb(double -0.000000e+00) readnone
+ ret i32 %r
+}
+
+define i32 @ilogbf_inf_readnone() {
+; CHECK-LABEL: define i32 @ilogbf_inf_readnone() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogbf(float 0x7FF0000000000000) #[[ATTR1]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogbf(float 0x7FF0000000000000) readnone
+ ret i32 %r
+}
+
+define i32 @ilogb_inf_readnone() {
+; CHECK-LABEL: define i32 @ilogb_inf_readnone() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogb(double 0x7FF0000000000000) #[[ATTR1]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogb(double 0x7FF0000000000000) readnone
+ ret i32 %r
+}
+
+define i32 @ilogbf_nan_readnone() {
+; CHECK-LABEL: define i32 @ilogbf_nan_readnone() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogbf(float 0x7FF8000000000000) #[[ATTR1]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogbf(float 0x7FF8000000000000) readnone
+ ret i32 %r
+}
+
+define i32 @ilogb_nan_readnone() {
+; CHECK-LABEL: define i32 @ilogb_nan_readnone() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogb(double 0x7FF8000000000000) #[[ATTR1]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogb(double 0x7FF8000000000000) readnone
+ ret i32 %r
+}
+
+define i32 @ilogbf_poison() {
+; CHECK-LABEL: define i32 @ilogbf_poison() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogbf(float poison)
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogbf(float poison)
+ ret i32 %r
+}
+
+define i32 @ilogb_poison() {
+; CHECK-LABEL: define i32 @ilogb_poison() {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogb(double poison)
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %r = call i32 @ilogb(double poison)
+ ret i32 %r
+}
+
+define i32 @ilogb_const1_1() strictfp {
+; CHECK-LABEL: define i32 @ilogb_const1_1(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[R:%.*]] = call i32 @ilogb(double -7.000000e+00)
+; CHECK-NEXT: ret i32 2
+;
+ %r = call i32 @ilogb(double -7.000000e+00)
+ ret i32 %r
+}
+
+declare i32 @ilogbf(float)
+declare i32 @ilogb(double)
diff --git a/llvm/tools/llvm-objcopy/CommonOpts.td b/llvm/tools/llvm-objcopy/CommonOpts.td
index c247c93f6e0f27..5b15191f546051 100644
--- a/llvm/tools/llvm-objcopy/CommonOpts.td
+++ b/llvm/tools/llvm-objcopy/CommonOpts.td
@@ -117,6 +117,8 @@ def regex
def version : Flag<["--"], "version">,
HelpText<"Print the version and exit.">;
+def verbose : Flag<["--"], "verbose">,
+ HelpText<"Prints the removed symbols and sections">;
def V : Flag<["-"], "V">,
Alias<version>,
HelpText<"Alias for --version">;
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
llvm:analysis
Includes value tracking, cost tables and constant folding
llvm:binary-utilities
llvm:instcombine
Covers the InstCombine, InstSimplify and AggressiveInstCombine passes
llvm:transforms
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addeed dbgs() in removeSections() function to print the removed
sections and symbols.
Fixes: #123041