[Mlir-commits] [llvm] [mlir] [OpenMP][OMPIRBuilder] Fix lastiter assertion in target workshare loop (PR #214996)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Aug 14 06:26:34 PDT 2026


================
@@ -6605,6 +6613,15 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::applyWorkshareLoopTarget(
   ToBeDeleted.push_back(NewLoopCntLoad);
   ToBeDeleted.push_back(NewLoopCnt);
 
+  // Set p.lastiter to 1 if the current iteration is the last one.
+  Builder.restoreIP(CLI->getBody(), CLI->getBody()->getFirstInsertionPt());
----------------
RohithPariki wrote:

Thanks for catching the compile error and for the feedback on the approach ,i 've just pushed an update that addresses both of your points:
Compile Error: Good catch! I fixed the missing {} in the Builder.restoreIP call.
Conditional Emission: You are completely right about the runtime cost. i updated applyWorkshareLoopTarget and applyWorkshareLoop to take a HasLastiterClause boolean. in the MLIR translation (OpenMPToLLVMIRTranslation.cpp), we now pass !wsloopOp.getLinearVars().empty() to it. This ensures that the p.lastiter initialization and the per-iteration icmp eq checks are only emitted for target loops that actually have a linear clause.
this avoids making every target loop pay for it and resolves the existing test failures, as the llvm ir remains completely unchanged for target loops without linear variables.

let me know if this looks good to you now

https://github.com/llvm/llvm-project/pull/214996


More information about the Mlir-commits mailing list