[llvm] [ConstantFolding] Add constant folding support for nextafter/nexttoward (PR #167324)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 10 06:52:05 PST 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/ADT/APFloat.h llvm/lib/Analysis/ConstantFolding.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 210af1d42..fadd3e789 100755
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1997,7 +1997,8 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
Name == "log1p" || Name == "log1pf";
case 'n':
return Name == "nearbyint" || Name == "nearbyintf" || Name == "nextafter" ||
- Name == "nextafterf" || Name == "nexttoward" || Name == "nexttowardf";
+ Name == "nextafterf" || Name == "nexttoward" ||
+ Name == "nexttowardf";
case 'p':
return Name == "pow" || Name == "powf";
case 'r':
@@ -3228,13 +3229,14 @@ static Constant *ConstantFoldLibCall2(StringRef Name, Type *Ty,
case LibFunc_nexttowardf:
if (TLI->has(Func)) {
if (Op1V.isNaN() || Op2V.isNaN()) {
- return ConstantFP::get(Ty->getContext(), APFloat::getNaN(Ty->getFltSemantics()));
+ return ConstantFP::get(Ty->getContext(),
+ APFloat::getNaN(Ty->getFltSemantics()));
}
APFloat PromotedOp1V = Op1V.getPromoted(APFloat::IEEEquad());
APFloat PromotedOp2V = Op2V.getPromoted(APFloat::IEEEquad());
if (PromotedOp1V == PromotedOp2V) {
- return ConstantFP::get(Ty->getContext(), Op1V);
+ return ConstantFP::get(Ty->getContext(), Op1V);
}
APFloat Next(Op1V);
@@ -4683,7 +4685,8 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,
case LibFunc_nexttowardl: {
APFloat PromotedOp0 = Op0.getPromoted(APFloat::IEEEquad());
APFloat PromotedOp1 = Op1.getPromoted(APFloat::IEEEquad());
- if (PromotedOp0 == PromotedOp1) return true;
+ if (PromotedOp0 == PromotedOp1)
+ return true;
APFloat Next(Op0);
Next.next(/*nextDown=*/PromotedOp0 > PromotedOp1);
``````````
</details>
https://github.com/llvm/llvm-project/pull/167324
More information about the llvm-commits
mailing list