[clang] [clang] constexpr `__builtin_elementwise_abs` support (PR #152497)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 13 21:29:16 PDT 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 HEAD~1 HEAD --extensions cpp,c -- clang/lib/AST/ByteCode/InterpBuiltin.cpp clang/lib/AST/ExprConstant.cpp clang/test/CodeGen/builtins-elementwise-math.c clang/test/Sema/constant-builtins-vector.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 86303ecfc..b602b9731 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -598,15 +598,15 @@ static bool interp__builtin_fpclassify(InterpState &S, CodePtr OpPC,
return true;
}
-static inline Floating abs(InterpState& S, const Floating& In){
- if(!In.isNegative())
- return In;
+static inline Floating abs(InterpState &S, const Floating &In) {
+ if (!In.isNegative())
+ return In;
- Floating Output = S.allocFloat(In.getSemantics());
- APFloat New = In.getAPFloat();
- New.changeSign();
- Output.copy(New);
- return Output;
+ Floating Output = S.allocFloat(In.getSemantics());
+ APFloat New = In.getAPFloat();
+ New.changeSign();
+ Output.copy(New);
+ return Output;
}
// The C standard says "fabs raises no floating-point exceptions,
@@ -1703,11 +1703,11 @@ static bool interp__builtin_elementwise_abs(InterpState &S, CodePtr OpPC,
}
if (Ty->isFloatingType()) {
- Floating Val = S.Stk.pop<Floating>();
- Floating Result = abs(S, Val);
- S.Stk.push<Floating>(Result);
- return true;
- }
+ Floating Val = S.Stk.pop<Floating>();
+ Floating Result = abs(S, Val);
+ S.Stk.push<Floating>(Result);
+ return true;
+ }
// Otherwise, the argument must be a vector.
assert(Call->getArg(0)->getType()->isVectorType());
@@ -1723,16 +1723,16 @@ static bool interp__builtin_elementwise_abs(InterpState &S, CodePtr OpPC,
unsigned NumElems = Arg.getNumElems();
// we can either have a vector of integer or a vector of floating point
for (unsigned I = 0; I != NumElems; ++I) {
- if (ElemType->isIntegerType()) {
- INT_TYPE_SWITCH_NO_BOOL(ElemT, {
- Dst.elem<T>(I) = T::from(static_cast<T>(
- APSInt(Arg.elem<T>(I).toAPSInt().abs(),
- ElemType->isUnsignedIntegerOrEnumerationType())));
- });
- } else {
- Floating Val = Arg.elem<Floating>(I);
- Dst.elem<Floating>(I) = abs(S, Val);
- }
+ if (ElemType->isIntegerType()) {
+ INT_TYPE_SWITCH_NO_BOOL(ElemT, {
+ Dst.elem<T>(I) = T::from(static_cast<T>(
+ APSInt(Arg.elem<T>(I).toAPSInt().abs(),
+ ElemType->isUnsignedIntegerOrEnumerationType())));
+ });
+ } else {
+ Floating Val = Arg.elem<Floating>(I);
+ Dst.elem<Floating>(I) = abs(S, Val);
+ }
}
Dst.initializeAllElements();
``````````
</details>
https://github.com/llvm/llvm-project/pull/152497
More information about the cfe-commits
mailing list