[clang] [Clang][OpenMP][NFC] Use `getLimitedValue` for loop transform counts (PR #224940)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 20 08:48:42 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-clang
Author: Amit Tiwari (loopacino)
<details>
<summary>Changes</summary>
Use `getLimitedValue()` when reading integer counts for `unroll, split, interchange, fuse` transforms.
It avoids direct `getZExtValue()` calls and follows the existing OpenMP count handling style.
---
Full diff: https://github.com/llvm/llvm-project/pull/224940.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+3-2)
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+5-5)
``````````diff
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 7c3b30c6cedc0e..1a805b05b401e4 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -3281,7 +3281,8 @@ void CodeGenFunction::EmitOMPUnrollDirective(const OMPUnrollDirective &S) {
} else if (auto *PartialClause = S.getSingleClause<OMPPartialClause>()) {
uint64_t Factor = 0;
if (Expr *FactorExpr = PartialClause->getFactor()) {
- Factor = FactorExpr->EvaluateKnownConstInt(getContext()).getZExtValue();
+ Factor =
+ FactorExpr->EvaluateKnownConstInt(getContext()).getLimitedValue();
assert(Factor >= 1 && "Only positive factors are valid");
}
OMPBuilder.unrollLoopPartial(DL, CLI, Factor,
@@ -3310,7 +3311,7 @@ void CodeGenFunction::EmitOMPUnrollDirective(const OMPUnrollDirective &S) {
} else if (auto *PartialClause = S.getSingleClause<OMPPartialClause>()) {
if (Expr *FactorExpr = PartialClause->getFactor()) {
uint64_t Factor =
- FactorExpr->EvaluateKnownConstInt(getContext()).getZExtValue();
+ FactorExpr->EvaluateKnownConstInt(getContext()).getLimitedValue();
assert(Factor >= 1 && "Only positive factors are valid");
LoopStack.setUnrollCount(Factor);
}
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 2e4d9f2f82f0b7..23f0e17aebe8c0 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -15940,7 +15940,7 @@ StmtResult SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses,
SourceLocation FactorLoc;
if (Expr *FactorVal = PartialClause->getFactor();
FactorVal && !FactorVal->containsErrors()) {
- Factor = FactorVal->getIntegerConstantExpr(Context)->getZExtValue();
+ Factor = FactorVal->getIntegerConstantExpr(Context)->getLimitedValue();
FactorLoc = FactorVal->getExprLoc();
} else {
// TODO: Use a better profitability model.
@@ -16366,7 +16366,7 @@ StmtResult SemaOpenMP::ActOnOpenMPSplitDirective(ArrayRef<OMPClause *> Clauses,
if (!OptVal || OptVal->isNegative())
return OMPSplitDirective::Create(Context, StartLoc, EndLoc, Clauses,
NumLoops, AStmt, nullptr, nullptr);
- CountValues[I] = OptVal->getZExtValue();
+ CountValues[I] = OptVal->getLimitedValue();
}
Expr *NumIterExpr = LoopHelper.NumIterations;
@@ -16566,7 +16566,7 @@ StmtResult SemaOpenMP::ActOnOpenMPInterchangeDirective(
PermArg->getIntegerConstantExpr(Context);
if (!PermCstExpr)
continue;
- uint64_t PermInt = PermCstExpr->getZExtValue();
+ uint64_t PermInt = PermCstExpr->getLimitedValue();
assert(1 <= PermInt && PermInt <= NumLoops &&
"Must be a permutation; diagnostic emitted in "
"ActOnOpenMPPermutationClause");
@@ -16757,8 +16757,8 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
uint64_t &CountVal) {
llvm::APSInt FirstInt = First->EvaluateKnownConstInt(Context);
llvm::APSInt CountInt = Count->EvaluateKnownConstInt(Context);
- FirstVal = FirstInt.getZExtValue();
- CountVal = CountInt.getZExtValue();
+ FirstVal = FirstInt.getLimitedValue();
+ CountVal = CountInt.getLimitedValue();
};
// OpenMP [6.0, Restrictions]
``````````
</details>
https://github.com/llvm/llvm-project/pull/224940
More information about the cfe-commits
mailing list