-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Resolving #171877 #172139
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
base: main
Are you sure you want to change the base?
Resolving #171877 #172139
Conversation
Moved constant folding logic from SimplifyLibCalls.cpp to ConstantFoldLibCall2
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-llvm-analysis @llvm/pr-subscribers-llvm-transforms Author: Ron Xavier (Ronxvier) ChangesMoved constant folding logic from SimplifyLibCalls.cpp to ConstantFoldLibCall2 Full diff: https://github.com/llvm/llvm-project/pull/172139.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index a9b51065a1d99..8a73c02bc363e 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -3241,6 +3241,18 @@ static Constant *ConstantFoldLibCall2(StringRef Name, Type *Ty,
if (TLI->has(Func))
return ConstantFoldBinaryFP(atan2, Op1V, Op2V, Ty);
break;
+ case LibFunc_fdim:
+ case LibFunc_fdimf:
+ case LibFunc_fdiml:
+ if (TLI->has(Func)){
+ APFloat Difference = Op1V;
+ Difference.subtract(Op2V, RoundingMode::NearestTiesToEven);
+
+ APFloat MaxVal =
+ maximum(Difference, APFloat::getZero(Ty->getFltSemantics()));
+ return ConstantFP::get(Ty->getContext(), MaxVal);
+ }
+ break;
}
return nullptr;
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index c3537f544c432..55cd08b3de855 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -3201,18 +3201,8 @@ Value *LibCallSimplifier::optimizeFdim(CallInst *CI, IRBuilderBase &B) {
if (isa<PoisonValue>(CI->getArgOperand(1)))
return CI->getArgOperand(1);
- const APFloat *X, *Y;
- // Check if both values are constants
- if (!match(CI->getArgOperand(0), m_APFloat(X)) ||
- !match(CI->getArgOperand(1), m_APFloat(Y)))
- return nullptr;
-
- APFloat Difference = *X;
- Difference.subtract(*Y, RoundingMode::NearestTiesToEven);
-
- APFloat MaxVal =
- maximum(Difference, APFloat::getZero(CI->getType()->getFltSemantics()));
- return ConstantFP::get(CI->getType(), MaxVal);
+ // Constant folding will be handled by ConstantFoldLibCall2
+ return nullptr;
}
//===----------------------------------------------------------------------===//
|
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Analysis/ConstantFolding.cpp llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp --diff_from_common_commit
View the diff from clang-format here.diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 8a73c02bc..55dfca551 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -3244,15 +3244,15 @@ static Constant *ConstantFoldLibCall2(StringRef Name, Type *Ty,
case LibFunc_fdim:
case LibFunc_fdimf:
case LibFunc_fdiml:
- if (TLI->has(Func)){
- APFloat Difference = Op1V;
- Difference.subtract(Op2V, RoundingMode::NearestTiesToEven);
+ if (TLI->has(Func)) {
+ APFloat Difference = Op1V;
+ Difference.subtract(Op2V, RoundingMode::NearestTiesToEven);
- APFloat MaxVal =
- maximum(Difference, APFloat::getZero(Ty->getFltSemantics()));
- return ConstantFP::get(Ty->getContext(), MaxVal);
- }
- break;
+ APFloat MaxVal =
+ maximum(Difference, APFloat::getZero(Ty->getFltSemantics()));
+ return ConstantFP::get(Ty->getContext(), MaxVal);
+ }
+ break;
}
return nullptr;
|
🐧 Linux x64 Test Results
Failed Tests(click on a test name to see its output) LLVMLLVM.Transforms/InstCombine/fdim.llLLVM.Transforms/InstCombine/win-fdim.llIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
🪟 Windows x64 Test Results
Failed Tests(click on a test name to see its output) LLVMLLVM.Transforms/InstCombine/fdim.llLLVM.Transforms/InstCombine/win-fdim.llIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
Might be an overguarding issue
Moved constant folding logic from SimplifyLibCalls.cpp to ConstantFoldLibCall2
Meant to resolve #171877