Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp =================================================================== --- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -1511,15 +1511,18 @@ Builder.CreateStore(UpperBound, PUpperBound); Builder.CreateStore(One, PStride); - // FIXME: schedule(static) is NOT the same as schedule(static,1) - if (!Chunk) + Constant *SchedulingType; + if (Chunk) { + SchedulingType = ConstantInt::get( + I32Type, static_cast(OMPScheduleType::StaticChunked)); + } else { + SchedulingType = + ConstantInt::get(I32Type, static_cast(OMPScheduleType::Static)); Chunk = One; + } Value *ThreadNum = getOrCreateThreadID(SrcLoc); - Constant *SchedulingType = - ConstantInt::get(I32Type, static_cast(OMPScheduleType::Static)); - // Call the "init" function and update the trip count of the loop with the // value it produced. Builder.CreateCall(StaticInit, Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp =================================================================== --- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -564,10 +564,9 @@ // Find the loop configuration. llvm::Value *step = moduleTranslation.lookupValue(loop.step()[0]); llvm::Type *ivType = step->getType(); - llvm::Value *chunk = - loop.schedule_chunk_var() - ? moduleTranslation.lookupValue(loop.schedule_chunk_var()) - : llvm::ConstantInt::get(ivType, 1); + llvm::Value *chunk = nullptr; + if (loop.schedule_chunk_var()) + chunk = moduleTranslation.lookupValue(loop.schedule_chunk_var()); SmallVector reductionDecls; collectReductionDecls(loop, reductionDecls); Index: mlir/test/Target/LLVMIR/openmp-llvm.mlir =================================================================== --- mlir/test/Target/LLVMIR/openmp-llvm.mlir +++ mlir/test/Target/LLVMIR/openmp-llvm.mlir @@ -423,6 +423,50 @@ // ----- +llvm.func @body(i32) + +llvm.func @test_omp_wsloop_static_1(%lb : i32, %ub : i32, %step : i32) -> () { + omp.wsloop (%iv) : i32 = (%lb) to (%ub) step (%step) schedule(static) { + // CHECK: call void @__kmpc_for_static_init_4u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 34, i32* %{{.*}}, i32* %{{.*}}, i32* %{{.*}}, i32* %{{.*}}, i32 1, i32 1) + // CHECK: call void @__kmpc_for_static_fini + llvm.call @body(%iv) : (i32) -> () + omp.yield + } + llvm.return +} + +// ----- + +llvm.func @body(i32) + +llvm.func @test_omp_wsloop_static_2(%lb : i32, %ub : i32, %step : i32) -> () { + %static_chunk_size = llvm.mlir.constant(1 : i32) : i32 + omp.wsloop (%iv) : i32 = (%lb) to (%ub) step (%step) schedule(static = %static_chunk_size) { + // CHECK: call void @__kmpc_for_static_init_4u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 33, i32* %{{.*}}, i32* %{{.*}}, i32* %{{.*}}, i32* %{{.*}}, i32 1, i32 1) + // CHECK: call void @__kmpc_for_static_fini + llvm.call @body(%iv) : (i32) -> () + omp.yield + } + llvm.return +} + +// ----- + +llvm.func @body(i32) + +llvm.func @test_omp_wsloop_static_2(%lb : i32, %ub : i32, %step : i32) -> () { + %static_chunk_size = llvm.mlir.constant(2 : i32) : i32 + omp.wsloop (%iv) : i32 = (%lb) to (%ub) step (%step) schedule(static = %static_chunk_size) { + // CHECK: call void @__kmpc_for_static_init_4u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 33, i32* %{{.*}}, i32* %{{.*}}, i32* %{{.*}}, i32* %{{.*}}, i32 1, i32 2) + // CHECK: call void @__kmpc_for_static_fini + llvm.call @body(%iv) : (i32) -> () + omp.yield + } + llvm.return +} + +// ----- + llvm.func @body(i64) llvm.func @test_omp_wsloop_dynamic(%lb : i64, %ub : i64, %step : i64) -> () {