[clang] c64686f - [Clang][OpenMP][NFC] Use `getLimitedValue` for loop transform counts (#224940)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 20 23:34:29 PDT 2026
Author: Amit Tiwari
Date: 2026-09-21T12:04:23+05:30
New Revision: c64686f1f0cce966ac00480dc4d1a91702536145
URL: https://github.com/llvm/llvm-project/commit/c64686f1f0cce966ac00480dc4d1a91702536145
DIFF: https://github.com/llvm/llvm-project/commit/c64686f1f0cce966ac00480dc4d1a91702536145.diff
LOG: [Clang][OpenMP][NFC] Use `getLimitedValue` for loop transform counts (#224940)
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.
Added:
Modified:
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 7c3b30c6cedc0..1a805b05b401e 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 6c46cd547592a..ae3d6653442d2 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]
More information about the cfe-commits
mailing list