[llvm-branch-commits] [clang] [Clang][OpenMP] Fix upper-bound for number of threads (PR #218589)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Aug 24 23:06:11 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Kevin Sala Penades (kevinsala)
<details>
<summary>Changes</summary>
The condition to update upper-bound of number of threads was inverted. We now update the upper-bound with any constant value even if it we already found a non-constant value.
Test to be added.
---
Full diff: https://github.com/llvm/llvm-project/pull/218589.diff
1 Files Affected:
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+8-7)
``````````diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 4b8b1de973407..4f5eb2d7160da 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6712,8 +6712,8 @@ static void getNumThreads(CodeGenFunction &CGF, const CapturedStmt *CS,
if (NTExpr->isIntegerConstantExpr(CGF.getContext()))
if (auto Constant = NTExpr->getIntegerConstantExpr(CGF.getContext()))
UpperBound =
- UpperBound
- ? Constant->getZExtValue()
+ (UpperBound <= 0)
+ ? static_cast<int32_t>(Constant->getZExtValue())
: std::min(UpperBound,
static_cast<int32_t>(Constant->getZExtValue()));
// If we haven't found a upper bound, remember we saw a thread limiting
@@ -6757,12 +6757,13 @@ const Expr *CGOpenMPRuntime::getNumThreadsExprForTargetDirective(
const Expr **NTPtr = UpperBoundOnly ? nullptr : &NT;
auto CheckForConstExpr = [&](const Expr *E, const Expr **EPtr) {
- if (E->isIntegerConstantExpr(CGF.getContext())) {
+ if (E->isIntegerConstantExpr(CGF.getContext()))
if (auto Constant = E->getIntegerConstantExpr(CGF.getContext()))
- UpperBound = UpperBound ? Constant->getZExtValue()
- : std::min(UpperBound,
- int32_t(Constant->getZExtValue()));
- }
+ UpperBound =
+ (UpperBound <= 0)
+ ? static_cast<int32_t>(Constant->getZExtValue())
+ : std::min(UpperBound,
+ static_cast<int32_t>(Constant->getZExtValue()));
// If we haven't found a upper bound, remember we saw a thread limiting
// clause.
if (UpperBound == -1)
``````````
</details>
https://github.com/llvm/llvm-project/pull/218589
More information about the llvm-branch-commits
mailing list