[clang] [Clang] Enable constexpr handling for builtin elementwise fshl/fshr (PR #153572)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 22 14:04:49 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 -- clang/lib/AST/ByteCode/InterpBuiltin.cpp clang/lib/AST/ExprConstant.cpp 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 a2bc34764..daae5811c 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2857,9 +2857,9 @@ static bool interp__builtin_elementwise_fsh(InterpState &S, CodePtr OpPC,
unsigned NumElems = VecT->getNumElements();
assert(VecT->getElementType() ==
- Arg2Type->castAs<VectorType>()->getElementType() &&
+ Arg2Type->castAs<VectorType>()->getElementType() &&
VecT->getElementType() ==
- Arg3Type->castAs<VectorType>()->getElementType());
+ Arg3Type->castAs<VectorType>()->getElementType());
assert(NumElems == Arg2Type->castAs<VectorType>()->getNumElements() &&
NumElems == Arg3Type->castAs<VectorType>()->getNumElements());
assert(VecT->getElementType()->isIntegralOrEnumerationType());
@@ -2869,24 +2869,24 @@ static bool interp__builtin_elementwise_fsh(InterpState &S, CodePtr OpPC,
const Pointer &VecHi = S.Stk.pop<Pointer>();
const Pointer &Dst = S.Stk.peek<Pointer>();
for (unsigned I = 0; I != NumElems; ++I) {
- APSInt Hi;
- APSInt Lo;
- APSInt Shift;
- INT_TYPE_SWITCH_NO_BOOL(ElemT, {
- Hi = VecHi.elem<T>(I).toAPSInt();
- Lo = VecLo.elem<T>(I).toAPSInt();
- Shift = VecShift.elem<T>(I).toAPSInt();
- });
- APSInt Result;
- if (BuiltinID == Builtin::BI__builtin_elementwise_fshl) {
- Result = APSInt(llvm::APIntOps::fshl(Hi, Lo, Shift), Hi.isUnsigned());
- } else if (BuiltinID == Builtin::BI__builtin_elementwise_fshr) {
- Result = APSInt(llvm::APIntOps::fshr(Hi, Lo, Shift), Hi.isUnsigned());
- } else {
- llvm_unreachable("Wrong builtin ID");
- }
- INT_TYPE_SWITCH_NO_BOOL(ElemT,
- { Dst.elem<T>(I) = static_cast<T>(Result); });
+ APSInt Hi;
+ APSInt Lo;
+ APSInt Shift;
+ INT_TYPE_SWITCH_NO_BOOL(ElemT, {
+ Hi = VecHi.elem<T>(I).toAPSInt();
+ Lo = VecLo.elem<T>(I).toAPSInt();
+ Shift = VecShift.elem<T>(I).toAPSInt();
+ });
+ APSInt Result;
+ if (BuiltinID == Builtin::BI__builtin_elementwise_fshl) {
+ Result = APSInt(llvm::APIntOps::fshl(Hi, Lo, Shift), Hi.isUnsigned());
+ } else if (BuiltinID == Builtin::BI__builtin_elementwise_fshr) {
+ Result = APSInt(llvm::APIntOps::fshr(Hi, Lo, Shift), Hi.isUnsigned());
+ } else {
+ llvm_unreachable("Wrong builtin ID");
+ }
+ INT_TYPE_SWITCH_NO_BOOL(ElemT,
+ { Dst.elem<T>(I) = static_cast<T>(Result); });
}
Dst.initializeAllElements();
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index c871f667a..3612cf53c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11965,10 +11965,12 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
const APSInt &Shift = SourceShift.getVectorElt(EltNum).getInt();
switch (E->getBuiltinCallee()) {
case Builtin::BI__builtin_elementwise_fshl:
- ResultElements.push_back(APValue(APSInt(llvm::APIntOps::fshl(Hi, Lo, Shift), Hi.isUnsigned())));
+ ResultElements.push_back(APValue(
+ APSInt(llvm::APIntOps::fshl(Hi, Lo, Shift), Hi.isUnsigned())));
break;
case Builtin::BI__builtin_elementwise_fshr:
- ResultElements.push_back(APValue(APSInt(llvm::APIntOps::fshr(Hi, Lo, Shift), Hi.isUnsigned())));
+ ResultElements.push_back(APValue(
+ APSInt(llvm::APIntOps::fshr(Hi, Lo, Shift), Hi.isUnsigned())));
break;
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/153572
More information about the cfe-commits
mailing list