https://github.com/loopacino created https://github.com/llvm/llvm-project/pull/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. >From db2a78434e4c64241689c56fbc8b33b380debeff Mon Sep 17 00:00:00 2001 From: amtiwari <[email protected]> Date: Sun, 20 Sep 2026 11:41:41 -0400 Subject: [PATCH] avoid_zextvalue --- clang/lib/CodeGen/CGStmtOpenMP.cpp | 5 +++-- clang/lib/Sema/SemaOpenMP.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) 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 2e4d9f2f82f0b..23f0e17aebe8c 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] _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
