diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -3655,13 +3655,52 @@ static bool isSupportedByOpenMPIRBuilder(const OMPForDirective &S) { if (S.hasCancel()) return false; - for (OMPClause *C : S.clauses()) - if (!isa(C)) - return false; + for (OMPClause *C : S.clauses()) { + if (isa(C)) + continue; + + if (auto *SC = dyn_cast(C)) { + if (SC->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) + return false; + if (SC->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) + return false; + switch (SC->getScheduleKind()) { + case OMPC_SCHEDULE_auto: + case OMPC_SCHEDULE_dynamic: + case OMPC_SCHEDULE_runtime: + case OMPC_SCHEDULE_guided: + case OMPC_SCHEDULE_static: + continue; + case OMPC_SCHEDULE_unknown: + return false; + } + } + + return false; + } return true; } +static llvm::omp::ScheduleKind +convertClauseKindToSchedKind(OpenMPScheduleClauseKind ScheduleClauseKind) { + switch (ScheduleClauseKind) { + case OMPC_SCHEDULE_unknown: + return llvm::omp::OMP_SCHEDULE_Default; + case OMPC_SCHEDULE_auto: + return llvm::omp::OMP_SCHEDULE_Auto; + case OMPC_SCHEDULE_dynamic: + return llvm::omp::OMP_SCHEDULE_Dynamic; + case OMPC_SCHEDULE_guided: + return llvm::omp::OMP_SCHEDULE_Guided; + case OMPC_SCHEDULE_runtime: + return llvm::omp::OMP_SCHEDULE_Runtime; + case OMPC_SCHEDULE_static: + return llvm::omp::OMP_SCHEDULE_Static; + } + llvm_unreachable("Unhandled schedule kind"); +} + void CodeGenFunction::EmitOMPForDirective(const OMPForDirective &S) { bool HasLastprivates = false; bool UseOMPIRBuilder = @@ -3670,18 +3709,29 @@ UseOMPIRBuilder](CodeGenFunction &CGF, PrePostActionTy &) { // Use the OpenMPIRBuilder if enabled. if (UseOMPIRBuilder) { + bool NeedsBarrier = !S.getSingleClause(); + + llvm::omp::ScheduleKind SchedKind = llvm::omp::OMP_SCHEDULE_Default; + llvm::Value *ChunkSize = nullptr; + if (auto *SchedClause = S.getSingleClause()) { + SchedKind = + convertClauseKindToSchedKind(SchedClause->getScheduleKind()); + if (const Expr *ChunkSizeExpr = SchedClause->getChunkSize()) + ChunkSize = EmitScalarExpr(ChunkSizeExpr); + } + // Emit the associated statement and get its loop representation. const Stmt *Inner = S.getRawStmt(); llvm::CanonicalLoopInfo *CLI = EmitOMPCollapsedCanonicalLoopNest(Inner, 1); - bool NeedsBarrier = !S.getSingleClause(); llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder(); llvm::OpenMPIRBuilder::InsertPointTy AllocaIP( AllocaInsertPt->getParent(), AllocaInsertPt->getIterator()); OMPBuilder.applyWorkshareLoop(Builder.getCurrentDebugLocation(), CLI, - AllocaIP, NeedsBarrier); + AllocaIP, NeedsBarrier, SchedKind, + ChunkSize); return; } diff --git a/clang/test/OpenMP/cancel_codegen.cpp b/clang/test/OpenMP/cancel_codegen.cpp --- a/clang/test/OpenMP/cancel_codegen.cpp +++ b/clang/test/OpenMP/cancel_codegen.cpp @@ -1361,7 +1361,7 @@ // CHECK3-NEXT: store i32 0, i32* [[P_UPPERBOUND]], align 4 // CHECK3-NEXT: store i32 1, i32* [[P_STRIDE]], align 4 // CHECK3-NEXT: [[OMP_GLOBAL_THREAD_NUM11:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) -// CHECK3-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM11]], i32 34, i32* [[P_LASTITER]], i32* [[P_LOWERBOUND]], i32* [[P_UPPERBOUND]], i32* [[P_STRIDE]], i32 1, i32 1) +// CHECK3-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM11]], i32 34, i32* [[P_LASTITER]], i32* [[P_LOWERBOUND]], i32* [[P_UPPERBOUND]], i32* [[P_STRIDE]], i32 1, i32 0) // CHECK3-NEXT: [[TMP0:%.*]] = load i32, i32* [[P_LOWERBOUND]], align 4 // CHECK3-NEXT: [[TMP1:%.*]] = load i32, i32* [[P_UPPERBOUND]], align 4 // CHECK3-NEXT: [[TMP2:%.*]] = sub i32 [[TMP1]], [[TMP0]] @@ -1397,7 +1397,7 @@ // CHECK3-NEXT: store i32 1, i32* [[P_UPPERBOUND29]], align 4 // CHECK3-NEXT: store i32 1, i32* [[P_STRIDE30]], align 4 // CHECK3-NEXT: [[OMP_GLOBAL_THREAD_NUM31:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) -// CHECK3-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM31]], i32 34, i32* [[P_LASTITER27]], i32* [[P_LOWERBOUND28]], i32* [[P_UPPERBOUND29]], i32* [[P_STRIDE30]], i32 1, i32 1) +// CHECK3-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM31]], i32 34, i32* [[P_LASTITER27]], i32* [[P_LOWERBOUND28]], i32* [[P_UPPERBOUND29]], i32* [[P_STRIDE30]], i32 1, i32 0) // CHECK3-NEXT: [[TMP7:%.*]] = load i32, i32* [[P_LOWERBOUND28]], align 4 // CHECK3-NEXT: [[TMP8:%.*]] = load i32, i32* [[P_UPPERBOUND29]], align 4 // CHECK3-NEXT: [[TMP9:%.*]] = sub i32 [[TMP8]], [[TMP7]] @@ -1988,7 +1988,7 @@ // CHECK4-NEXT: store i32 0, i32* [[P_UPPERBOUND]], align 4 // CHECK4-NEXT: store i32 1, i32* [[P_STRIDE]], align 4 // CHECK4-NEXT: [[OMP_GLOBAL_THREAD_NUM11:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) -// CHECK4-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM11]], i32 34, i32* [[P_LASTITER]], i32* [[P_LOWERBOUND]], i32* [[P_UPPERBOUND]], i32* [[P_STRIDE]], i32 1, i32 1) +// CHECK4-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM11]], i32 34, i32* [[P_LASTITER]], i32* [[P_LOWERBOUND]], i32* [[P_UPPERBOUND]], i32* [[P_STRIDE]], i32 1, i32 0) // CHECK4-NEXT: [[TMP0:%.*]] = load i32, i32* [[P_LOWERBOUND]], align 4 // CHECK4-NEXT: [[TMP1:%.*]] = load i32, i32* [[P_UPPERBOUND]], align 4 // CHECK4-NEXT: [[TMP2:%.*]] = sub i32 [[TMP1]], [[TMP0]] @@ -2024,7 +2024,7 @@ // CHECK4-NEXT: store i32 1, i32* [[P_UPPERBOUND29]], align 4 // CHECK4-NEXT: store i32 1, i32* [[P_STRIDE30]], align 4 // CHECK4-NEXT: [[OMP_GLOBAL_THREAD_NUM31:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) -// CHECK4-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM31]], i32 34, i32* [[P_LASTITER27]], i32* [[P_LOWERBOUND28]], i32* [[P_UPPERBOUND29]], i32* [[P_STRIDE30]], i32 1, i32 1) +// CHECK4-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM31]], i32 34, i32* [[P_LASTITER27]], i32* [[P_LOWERBOUND28]], i32* [[P_UPPERBOUND29]], i32* [[P_STRIDE30]], i32 1, i32 0) // CHECK4-NEXT: [[TMP7:%.*]] = load i32, i32* [[P_LOWERBOUND28]], align 4 // CHECK4-NEXT: [[TMP8:%.*]] = load i32, i32* [[P_UPPERBOUND29]], align 4 // CHECK4-NEXT: [[TMP9:%.*]] = sub i32 [[TMP8]], [[TMP7]] @@ -3855,7 +3855,7 @@ // CHECK9-NEXT: store i32 0, i32* [[P_UPPERBOUND]], align 4 // CHECK9-NEXT: store i32 1, i32* [[P_STRIDE]], align 4 // CHECK9-NEXT: [[OMP_GLOBAL_THREAD_NUM11:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) -// CHECK9-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM11]], i32 34, i32* [[P_LASTITER]], i32* [[P_LOWERBOUND]], i32* [[P_UPPERBOUND]], i32* [[P_STRIDE]], i32 1, i32 1) +// CHECK9-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM11]], i32 34, i32* [[P_LASTITER]], i32* [[P_LOWERBOUND]], i32* [[P_UPPERBOUND]], i32* [[P_STRIDE]], i32 1, i32 0) // CHECK9-NEXT: [[TMP0:%.*]] = load i32, i32* [[P_LOWERBOUND]], align 4 // CHECK9-NEXT: [[TMP1:%.*]] = load i32, i32* [[P_UPPERBOUND]], align 4 // CHECK9-NEXT: [[TMP2:%.*]] = sub i32 [[TMP1]], [[TMP0]] @@ -3891,7 +3891,7 @@ // CHECK9-NEXT: store i32 1, i32* [[P_UPPERBOUND29]], align 4 // CHECK9-NEXT: store i32 1, i32* [[P_STRIDE30]], align 4 // CHECK9-NEXT: [[OMP_GLOBAL_THREAD_NUM31:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) -// CHECK9-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM31]], i32 34, i32* [[P_LASTITER27]], i32* [[P_LOWERBOUND28]], i32* [[P_UPPERBOUND29]], i32* [[P_STRIDE30]], i32 1, i32 1) +// CHECK9-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM31]], i32 34, i32* [[P_LASTITER27]], i32* [[P_LOWERBOUND28]], i32* [[P_UPPERBOUND29]], i32* [[P_STRIDE30]], i32 1, i32 0) // CHECK9-NEXT: [[TMP7:%.*]] = load i32, i32* [[P_LOWERBOUND28]], align 4 // CHECK9-NEXT: [[TMP8:%.*]] = load i32, i32* [[P_UPPERBOUND29]], align 4 // CHECK9-NEXT: [[TMP9:%.*]] = sub i32 [[TMP8]], [[TMP7]] @@ -4482,7 +4482,7 @@ // CHECK10-NEXT: store i32 0, i32* [[P_UPPERBOUND]], align 4 // CHECK10-NEXT: store i32 1, i32* [[P_STRIDE]], align 4 // CHECK10-NEXT: [[OMP_GLOBAL_THREAD_NUM11:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) -// CHECK10-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM11]], i32 34, i32* [[P_LASTITER]], i32* [[P_LOWERBOUND]], i32* [[P_UPPERBOUND]], i32* [[P_STRIDE]], i32 1, i32 1) +// CHECK10-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM11]], i32 34, i32* [[P_LASTITER]], i32* [[P_LOWERBOUND]], i32* [[P_UPPERBOUND]], i32* [[P_STRIDE]], i32 1, i32 0) // CHECK10-NEXT: [[TMP0:%.*]] = load i32, i32* [[P_LOWERBOUND]], align 4 // CHECK10-NEXT: [[TMP1:%.*]] = load i32, i32* [[P_UPPERBOUND]], align 4 // CHECK10-NEXT: [[TMP2:%.*]] = sub i32 [[TMP1]], [[TMP0]] @@ -4518,7 +4518,7 @@ // CHECK10-NEXT: store i32 1, i32* [[P_UPPERBOUND29]], align 4 // CHECK10-NEXT: store i32 1, i32* [[P_STRIDE30]], align 4 // CHECK10-NEXT: [[OMP_GLOBAL_THREAD_NUM31:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) -// CHECK10-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM31]], i32 34, i32* [[P_LASTITER27]], i32* [[P_LOWERBOUND28]], i32* [[P_UPPERBOUND29]], i32* [[P_STRIDE30]], i32 1, i32 1) +// CHECK10-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM31]], i32 34, i32* [[P_LASTITER27]], i32* [[P_LOWERBOUND28]], i32* [[P_UPPERBOUND29]], i32* [[P_STRIDE30]], i32 1, i32 0) // CHECK10-NEXT: [[TMP7:%.*]] = load i32, i32* [[P_LOWERBOUND28]], align 4 // CHECK10-NEXT: [[TMP8:%.*]] = load i32, i32* [[P_UPPERBOUND29]], align 4 // CHECK10-NEXT: [[TMP9:%.*]] = sub i32 [[TMP8]], [[TMP7]] diff --git a/clang/test/OpenMP/irbuilder_for_iterator.cpp b/clang/test/OpenMP/irbuilder_for_iterator.cpp --- a/clang/test/OpenMP/irbuilder_for_iterator.cpp +++ b/clang/test/OpenMP/irbuilder_for_iterator.cpp @@ -18,6 +18,90 @@ unsigned operator*() const; }; +// CHECK-LABEL: define {{.*}}@workshareloop_iterator( +// CHECK-NEXT: [[ENTRY:.*]]: +// CHECK-NEXT: %[[A_ADDR:.+]] = alloca float*, align 8 +// CHECK-NEXT: %[[B_ADDR:.+]] = alloca float*, align 8 +// CHECK-NEXT: %[[C_ADDR:.+]] = alloca float*, align 8 +// CHECK-NEXT: %[[IT:.+]] = alloca %struct.MyIterator, align 1 +// CHECK-NEXT: %[[AGG_CAPTURED:.+]] = alloca %struct.anon, align 8 +// CHECK-NEXT: %[[AGG_CAPTURED1:.+]] = alloca %struct.anon.0, align 1 +// CHECK-NEXT: %[[DOTCOUNT_ADDR:.+]] = alloca i64, align 8 +// CHECK-NEXT: %[[I:.+]] = alloca i32, align 4 +// CHECK-NEXT: %[[P_LASTITER:.+]] = alloca i32, align 4 +// CHECK-NEXT: %[[P_LOWERBOUND:.+]] = alloca i64, align 8 +// CHECK-NEXT: %[[P_UPPERBOUND:.+]] = alloca i64, align 8 +// CHECK-NEXT: %[[P_STRIDE:.+]] = alloca i64, align 8 +// CHECK-NEXT: store float* %[[A:.+]], float** %[[A_ADDR]], align 8 +// CHECK-NEXT: store float* %[[B:.+]], float** %[[B_ADDR]], align 8 +// CHECK-NEXT: store float* %[[C:.+]], float** %[[C_ADDR]], align 8 +// CHECK-NEXT: call void @_ZN10MyIteratorC1Ej(%struct.MyIterator* noundef %[[IT]], i32 noundef 7) +// CHECK-NEXT: %[[TMP0:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[AGG_CAPTURED]], i32 0, i32 0 +// CHECK-NEXT: store %struct.MyIterator* %[[IT]], %struct.MyIterator** %[[TMP0]], align 8 +// CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[AGG_CAPTURED1]], i32 0, i32 0 +// CHECK-NEXT: call void @_ZN10MyIteratorC1ERKS_(%struct.MyIterator* noundef %[[TMP1]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) %[[IT]]) +// CHECK-NEXT: call void @__captured_stmt(i64* %[[DOTCOUNT_ADDR]], %struct.anon* %[[AGG_CAPTURED]]) +// CHECK-NEXT: %[[DOTCOUNT:.+]] = load i64, i64* %[[DOTCOUNT_ADDR]], align 8 +// CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_PREHEADER]]: +// CHECK-NEXT: store i64 0, i64* %[[P_LOWERBOUND]], align 8 +// CHECK-NEXT: %[[TMP2:.+]] = sub i64 %[[DOTCOUNT]], 1 +// CHECK-NEXT: store i64 %[[TMP2]], i64* %[[P_UPPERBOUND]], align 8 +// CHECK-NEXT: store i64 1, i64* %[[P_STRIDE]], align 8 +// CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) +// CHECK-NEXT: call void @__kmpc_for_static_init_8u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i64* %[[P_LOWERBOUND]], i64* %[[P_UPPERBOUND]], i64* %[[P_STRIDE]], i64 1, i64 0) +// CHECK-NEXT: %[[TMP3:.+]] = load i64, i64* %[[P_LOWERBOUND]], align 8 +// CHECK-NEXT: %[[TMP4:.+]] = load i64, i64* %[[P_UPPERBOUND]], align 8 +// CHECK-NEXT: %[[TMP5:.+]] = sub i64 %[[TMP4]], %[[TMP3]] +// CHECK-NEXT: %[[TMP6:.+]] = add i64 %[[TMP5]], 1 +// CHECK-NEXT: br label %[[OMP_LOOP_HEADER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_HEADER]]: +// CHECK-NEXT: %[[OMP_LOOP_IV:.+]] = phi i64 [ 0, %[[OMP_LOOP_PREHEADER]] ], [ %[[OMP_LOOP_NEXT:.+]], %[[OMP_LOOP_INC:.+]] ] +// CHECK-NEXT: br label %[[OMP_LOOP_COND:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_COND]]: +// CHECK-NEXT: %[[OMP_LOOP_CMP:.+]] = icmp ult i64 %[[OMP_LOOP_IV]], %[[TMP6]] +// CHECK-NEXT: br i1 %[[OMP_LOOP_CMP]], label %[[OMP_LOOP_BODY:.+]], label %[[OMP_LOOP_EXIT:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_BODY]]: +// CHECK-NEXT: %[[TMP7:.+]] = add i64 %[[OMP_LOOP_IV]], %[[TMP3]] +// CHECK-NEXT: call void @__captured_stmt.1(%struct.MyIterator* %[[IT]], i64 %[[TMP7]], %struct.anon.0* %[[AGG_CAPTURED1]]) +// CHECK-NEXT: %[[CALL:.+]] = call noundef i32 @_ZNK10MyIteratordeEv(%struct.MyIterator* noundef %[[IT]]) +// CHECK-NEXT: store i32 %[[CALL]], i32* %[[I]], align 4 +// CHECK-NEXT: %[[TMP8:.+]] = load float*, float** %[[B_ADDR]], align 8 +// CHECK-NEXT: %[[TMP9:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM:.+]] = zext i32 %[[TMP9]] to i64 +// CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP8]], i64 %[[IDXPROM]] +// CHECK-NEXT: %[[TMP10:.+]] = load float, float* %[[ARRAYIDX]], align 4 +// CHECK-NEXT: %[[TMP11:.+]] = load float*, float** %[[C_ADDR]], align 8 +// CHECK-NEXT: %[[TMP12:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM2:.+]] = zext i32 %[[TMP12]] to i64 +// CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP11]], i64 %[[IDXPROM2]] +// CHECK-NEXT: %[[TMP13:.+]] = load float, float* %[[ARRAYIDX3]], align 4 +// CHECK-NEXT: %[[MUL:.+]] = fmul float %[[TMP10]], %[[TMP13]] +// CHECK-NEXT: %[[TMP14:.+]] = load float*, float** %[[A_ADDR]], align 8 +// CHECK-NEXT: %[[TMP15:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM4:.+]] = zext i32 %[[TMP15]] to i64 +// CHECK-NEXT: %[[ARRAYIDX5:.+]] = getelementptr inbounds float, float* %[[TMP14]], i64 %[[IDXPROM4]] +// CHECK-NEXT: store float %[[MUL]], float* %[[ARRAYIDX5]], align 4 +// CHECK-NEXT: br label %[[OMP_LOOP_INC]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_INC]]: +// CHECK-NEXT: %[[OMP_LOOP_NEXT]] = add nuw i64 %[[OMP_LOOP_IV]], 1 +// CHECK-NEXT: br label %[[OMP_LOOP_HEADER]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_EXIT]]: +// CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]]) +// CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM6:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) +// CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @2, i32 %[[OMP_GLOBAL_THREAD_NUM6]]) +// CHECK-NEXT: br label %[[OMP_LOOP_AFTER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_AFTER]]: +// CHECK-NEXT: ret void +// CHECK-NEXT: } + extern "C" void workshareloop_iterator(float *a, float *b, float *c) { #pragma omp for for (MyIterator it = MyIterator(7); it != MyIterator(41); ++it) { @@ -27,140 +111,69 @@ } #endif // HEADER -// CHECK-LABEL: define {{[^@]+}}@workshareloop_iterator -// CHECK-SAME: (float* noundef [[A:%.*]], float* noundef [[B:%.*]], float* noundef [[C:%.*]]) #[[ATTR0:[0-9]+]] { -// CHECK-NEXT: entry: -// CHECK-NEXT: [[A_ADDR:%.*]] = alloca float*, align 8 -// CHECK-NEXT: [[B_ADDR:%.*]] = alloca float*, align 8 -// CHECK-NEXT: [[C_ADDR:%.*]] = alloca float*, align 8 -// CHECK-NEXT: [[IT:%.*]] = alloca [[STRUCT_MYITERATOR:%.*]], align 1 -// CHECK-NEXT: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], align 8 -// CHECK-NEXT: [[AGG_CAPTURED1:%.*]] = alloca [[STRUCT_ANON_0:%.*]], align 1 -// CHECK-NEXT: [[DOTCOUNT_ADDR:%.*]] = alloca i64, align 8 -// CHECK-NEXT: [[I:%.*]] = alloca i32, align 4 -// CHECK-NEXT: [[P_LASTITER:%.*]] = alloca i32, align 4 -// CHECK-NEXT: [[P_LOWERBOUND:%.*]] = alloca i64, align 8 -// CHECK-NEXT: [[P_UPPERBOUND:%.*]] = alloca i64, align 8 -// CHECK-NEXT: [[P_STRIDE:%.*]] = alloca i64, align 8 -// CHECK-NEXT: store float* [[A]], float** [[A_ADDR]], align 8 -// CHECK-NEXT: store float* [[B]], float** [[B_ADDR]], align 8 -// CHECK-NEXT: store float* [[C]], float** [[C_ADDR]], align 8 -// CHECK-NEXT: call void @_ZN10MyIteratorC1Ej(%struct.MyIterator* noundef [[IT]], i32 noundef 7) -// CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds [[STRUCT_ANON]], %struct.anon* [[AGG_CAPTURED]], i32 0, i32 0 -// CHECK-NEXT: store %struct.MyIterator* [[IT]], %struct.MyIterator** [[TMP0]], align 8 -// CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON_0]], %struct.anon.0* [[AGG_CAPTURED1]], i32 0, i32 0 -// CHECK-NEXT: call void @_ZN10MyIteratorC1ERKS_(%struct.MyIterator* noundef [[TMP1]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) [[IT]]) -// CHECK-NEXT: call void @__captured_stmt(i64* [[DOTCOUNT_ADDR]], %struct.anon* [[AGG_CAPTURED]]) -// CHECK-NEXT: [[DOTCOUNT:%.*]] = load i64, i64* [[DOTCOUNT_ADDR]], align 8 -// CHECK-NEXT: br label [[OMP_LOOP_PREHEADER:%.*]] -// CHECK: omp_loop.preheader: -// CHECK-NEXT: store i64 0, i64* [[P_LOWERBOUND]], align 8 -// CHECK-NEXT: [[TMP2:%.*]] = sub i64 [[DOTCOUNT]], 1 -// CHECK-NEXT: store i64 [[TMP2]], i64* [[P_UPPERBOUND]], align 8 -// CHECK-NEXT: store i64 1, i64* [[P_STRIDE]], align 8 -// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]]) -// CHECK-NEXT: call void @__kmpc_for_static_init_8u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* [[P_LASTITER]], i64* [[P_LOWERBOUND]], i64* [[P_UPPERBOUND]], i64* [[P_STRIDE]], i64 1, i64 1) -// CHECK-NEXT: [[TMP3:%.*]] = load i64, i64* [[P_LOWERBOUND]], align 8 -// CHECK-NEXT: [[TMP4:%.*]] = load i64, i64* [[P_UPPERBOUND]], align 8 -// CHECK-NEXT: [[TMP5:%.*]] = sub i64 [[TMP4]], [[TMP3]] -// CHECK-NEXT: [[TMP6:%.*]] = add i64 [[TMP5]], 1 -// CHECK-NEXT: br label [[OMP_LOOP_HEADER:%.*]] -// CHECK: omp_loop.header: -// CHECK-NEXT: [[OMP_LOOP_IV:%.*]] = phi i64 [ 0, [[OMP_LOOP_PREHEADER]] ], [ [[OMP_LOOP_NEXT:%.*]], [[OMP_LOOP_INC:%.*]] ] -// CHECK-NEXT: br label [[OMP_LOOP_COND:%.*]] -// CHECK: omp_loop.cond: -// CHECK-NEXT: [[OMP_LOOP_CMP:%.*]] = icmp ult i64 [[OMP_LOOP_IV]], [[TMP6]] -// CHECK-NEXT: br i1 [[OMP_LOOP_CMP]], label [[OMP_LOOP_BODY:%.*]], label [[OMP_LOOP_EXIT:%.*]] -// CHECK: omp_loop.body: -// CHECK-NEXT: [[TMP7:%.*]] = add i64 [[OMP_LOOP_IV]], [[TMP3]] -// CHECK-NEXT: call void @__captured_stmt.1(%struct.MyIterator* [[IT]], i64 [[TMP7]], %struct.anon.0* [[AGG_CAPTURED1]]) -// CHECK-NEXT: [[CALL:%.*]] = call noundef i32 @_ZNK10MyIteratordeEv(%struct.MyIterator* noundef [[IT]]) -// CHECK-NEXT: store i32 [[CALL]], i32* [[I]], align 4 -// CHECK-NEXT: [[TMP8:%.*]] = load float*, float** [[B_ADDR]], align 8 -// CHECK-NEXT: [[TMP9:%.*]] = load i32, i32* [[I]], align 4 -// CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[TMP9]] to i64 -// CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[TMP8]], i64 [[IDXPROM]] -// CHECK-NEXT: [[TMP10:%.*]] = load float, float* [[ARRAYIDX]], align 4 -// CHECK-NEXT: [[TMP11:%.*]] = load float*, float** [[C_ADDR]], align 8 -// CHECK-NEXT: [[TMP12:%.*]] = load i32, i32* [[I]], align 4 -// CHECK-NEXT: [[IDXPROM2:%.*]] = zext i32 [[TMP12]] to i64 -// CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds float, float* [[TMP11]], i64 [[IDXPROM2]] -// CHECK-NEXT: [[TMP13:%.*]] = load float, float* [[ARRAYIDX3]], align 4 -// CHECK-NEXT: [[MUL:%.*]] = fmul float [[TMP10]], [[TMP13]] -// CHECK-NEXT: [[TMP14:%.*]] = load float*, float** [[A_ADDR]], align 8 -// CHECK-NEXT: [[TMP15:%.*]] = load i32, i32* [[I]], align 4 -// CHECK-NEXT: [[IDXPROM4:%.*]] = zext i32 [[TMP15]] to i64 -// CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds float, float* [[TMP14]], i64 [[IDXPROM4]] -// CHECK-NEXT: store float [[MUL]], float* [[ARRAYIDX5]], align 4 -// CHECK-NEXT: br label [[OMP_LOOP_INC]] -// CHECK: omp_loop.inc: -// CHECK-NEXT: [[OMP_LOOP_NEXT]] = add nuw i64 [[OMP_LOOP_IV]], 1 -// CHECK-NEXT: br label [[OMP_LOOP_HEADER]] -// CHECK: omp_loop.exit: -// CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]]) -// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM6:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) -// CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @[[GLOB2:[0-9]+]], i32 [[OMP_GLOBAL_THREAD_NUM6]]) -// CHECK-NEXT: br label [[OMP_LOOP_AFTER:%.*]] -// CHECK: omp_loop.after: +// CHECK-LABEL: define {{.*}}@__captured_stmt( +// CHECK-NEXT: [[ENTRY:.*]]: +// CHECK-NEXT: %[[DISTANCE_ADDR:.+]] = alloca i64*, align 8 +// CHECK-NEXT: %[[__CONTEXT_ADDR:.+]] = alloca %struct.anon*, align 8 +// CHECK-NEXT: %[[DOTSTART:.+]] = alloca %struct.MyIterator, align 1 +// CHECK-NEXT: %[[DOTSTOP:.+]] = alloca %struct.MyIterator, align 1 +// CHECK-NEXT: %[[DOTSTEP:.+]] = alloca i64, align 8 +// CHECK-NEXT: store i64* %[[DISTANCE:.+]], i64** %[[DISTANCE_ADDR]], align 8 +// CHECK-NEXT: store %struct.anon* %[[__CONTEXT:.+]], %struct.anon** %[[__CONTEXT_ADDR]], align 8 +// CHECK-NEXT: %[[TMP0:.+]] = load %struct.anon*, %struct.anon** %[[__CONTEXT_ADDR]], align 8 +// CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[TMP0]], i32 0, i32 0 +// CHECK-NEXT: %[[TMP2:.+]] = load %struct.MyIterator*, %struct.MyIterator** %[[TMP1]], align 8 +// CHECK-NEXT: call void @_ZN10MyIteratorC1ERKS_(%struct.MyIterator* noundef %[[DOTSTART]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) %[[TMP2]]) +// CHECK-NEXT: call void @_ZN10MyIteratorC1Ej(%struct.MyIterator* noundef %[[DOTSTOP]], i32 noundef 41) +// CHECK-NEXT: store i64 1, i64* %[[DOTSTEP]], align 8 +// CHECK-NEXT: %[[TMP3:.+]] = load i64, i64* %[[DOTSTEP]], align 8 +// CHECK-NEXT: %[[CMP:.+]] = icmp ult i64 %[[TMP3]], 0 +// CHECK-NEXT: br i1 %[[CMP]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[COND_TRUE]]: +// CHECK-NEXT: %[[CALL:.+]] = call noundef i32 @_ZNK10MyIteratormiERKS_(%struct.MyIterator* noundef %[[DOTSTART]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) %[[DOTSTOP]]) +// CHECK-NEXT: %[[CONV:.+]] = sext i32 %[[CALL]] to i64 +// CHECK-NEXT: %[[TMP4:.+]] = load i64, i64* %[[DOTSTEP]], align 8 +// CHECK-NEXT: %[[SUB:.+]] = sub i64 0, %[[TMP4]] +// CHECK-NEXT: %[[DIV:.+]] = udiv i64 %[[CONV]], %[[SUB]] +// CHECK-NEXT: br label %[[COND_END:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[COND_FALSE]]: +// CHECK-NEXT: %[[CALL1:.+]] = call noundef i32 @_ZNK10MyIteratormiERKS_(%struct.MyIterator* noundef %[[DOTSTOP]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) %[[DOTSTART]]) +// CHECK-NEXT: %[[CONV2:.+]] = sext i32 %[[CALL1]] to i64 +// CHECK-NEXT: %[[TMP5:.+]] = load i64, i64* %[[DOTSTEP]], align 8 +// CHECK-NEXT: %[[DIV3:.+]] = udiv i64 %[[CONV2]], %[[TMP5]] +// CHECK-NEXT: br label %[[COND_END]] +// CHECK-EMPTY: +// CHECK-NEXT: [[COND_END]]: +// CHECK-NEXT: %[[COND:.+]] = phi i64 [ %[[DIV]], %[[COND_TRUE]] ], [ %[[DIV3]], %[[COND_FALSE]] ] +// CHECK-NEXT: %[[TMP6:.+]] = load i64*, i64** %[[DISTANCE_ADDR]], align 8 +// CHECK-NEXT: store i64 %[[COND]], i64* %[[TMP6]], align 8 // CHECK-NEXT: ret void -// -// -// CHECK-LABEL: define {{[^@]+}}@__captured_stmt -// CHECK-SAME: (i64* noundef nonnull align 8 dereferenceable(8) [[DISTANCE:%.*]], %struct.anon* noalias noundef [[__CONTEXT:%.*]]) #[[ATTR2:[0-9]+]] { -// CHECK-NEXT: entry: -// CHECK-NEXT: [[DISTANCE_ADDR:%.*]] = alloca i64*, align 8 -// CHECK-NEXT: [[__CONTEXT_ADDR:%.*]] = alloca %struct.anon*, align 8 -// CHECK-NEXT: [[DOTSTART:%.*]] = alloca [[STRUCT_MYITERATOR:%.*]], align 1 -// CHECK-NEXT: [[DOTSTOP:%.*]] = alloca [[STRUCT_MYITERATOR]], align 1 -// CHECK-NEXT: [[DOTSTEP:%.*]] = alloca i64, align 8 -// CHECK-NEXT: store i64* [[DISTANCE]], i64** [[DISTANCE_ADDR]], align 8 -// CHECK-NEXT: store %struct.anon* [[__CONTEXT]], %struct.anon** [[__CONTEXT_ADDR]], align 8 -// CHECK-NEXT: [[TMP0:%.*]] = load %struct.anon*, %struct.anon** [[__CONTEXT_ADDR]], align 8 -// CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON:%.*]], %struct.anon* [[TMP0]], i32 0, i32 0 -// CHECK-NEXT: [[TMP2:%.*]] = load %struct.MyIterator*, %struct.MyIterator** [[TMP1]], align 8 -// CHECK-NEXT: call void @_ZN10MyIteratorC1ERKS_(%struct.MyIterator* noundef [[DOTSTART]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) [[TMP2]]) -// CHECK-NEXT: call void @_ZN10MyIteratorC1Ej(%struct.MyIterator* noundef [[DOTSTOP]], i32 noundef 41) -// CHECK-NEXT: store i64 1, i64* [[DOTSTEP]], align 8 -// CHECK-NEXT: [[TMP3:%.*]] = load i64, i64* [[DOTSTEP]], align 8 -// CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[TMP3]], 0 -// CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]] -// CHECK: cond.true: -// CHECK-NEXT: [[CALL:%.*]] = call noundef i32 @_ZNK10MyIteratormiERKS_(%struct.MyIterator* noundef [[DOTSTART]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) [[DOTSTOP]]) -// CHECK-NEXT: [[CONV:%.*]] = sext i32 [[CALL]] to i64 -// CHECK-NEXT: [[TMP4:%.*]] = load i64, i64* [[DOTSTEP]], align 8 -// CHECK-NEXT: [[SUB:%.*]] = sub i64 0, [[TMP4]] -// CHECK-NEXT: [[DIV:%.*]] = udiv i64 [[CONV]], [[SUB]] -// CHECK-NEXT: br label [[COND_END:%.*]] -// CHECK: cond.false: -// CHECK-NEXT: [[CALL1:%.*]] = call noundef i32 @_ZNK10MyIteratormiERKS_(%struct.MyIterator* noundef [[DOTSTOP]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) [[DOTSTART]]) -// CHECK-NEXT: [[CONV2:%.*]] = sext i32 [[CALL1]] to i64 -// CHECK-NEXT: [[TMP5:%.*]] = load i64, i64* [[DOTSTEP]], align 8 -// CHECK-NEXT: [[DIV3:%.*]] = udiv i64 [[CONV2]], [[TMP5]] -// CHECK-NEXT: br label [[COND_END]] -// CHECK: cond.end: -// CHECK-NEXT: [[COND:%.*]] = phi i64 [ [[DIV]], [[COND_TRUE]] ], [ [[DIV3]], [[COND_FALSE]] ] -// CHECK-NEXT: [[TMP6:%.*]] = load i64*, i64** [[DISTANCE_ADDR]], align 8 -// CHECK-NEXT: store i64 [[COND]], i64* [[TMP6]], align 8 -// CHECK-NEXT: ret void -// -// -// CHECK-LABEL: define {{[^@]+}}@__captured_stmt.1 -// CHECK-SAME: (%struct.MyIterator* noundef nonnull align 1 dereferenceable(1) [[LOOPVAR:%.*]], i64 noundef [[LOGICAL:%.*]], %struct.anon.0* noalias noundef [[__CONTEXT:%.*]]) #[[ATTR2]] { -// CHECK-NEXT: entry: -// CHECK-NEXT: [[LOOPVAR_ADDR:%.*]] = alloca %struct.MyIterator*, align 8 -// CHECK-NEXT: [[LOGICAL_ADDR:%.*]] = alloca i64, align 8 -// CHECK-NEXT: [[__CONTEXT_ADDR:%.*]] = alloca %struct.anon.0*, align 8 -// CHECK-NEXT: [[REF_TMP:%.*]] = alloca [[STRUCT_MYITERATOR:%.*]], align 1 -// CHECK-NEXT: store %struct.MyIterator* [[LOOPVAR]], %struct.MyIterator** [[LOOPVAR_ADDR]], align 8 -// CHECK-NEXT: store i64 [[LOGICAL]], i64* [[LOGICAL_ADDR]], align 8 -// CHECK-NEXT: store %struct.anon.0* [[__CONTEXT]], %struct.anon.0** [[__CONTEXT_ADDR]], align 8 -// CHECK-NEXT: [[TMP0:%.*]] = load %struct.anon.0*, %struct.anon.0** [[__CONTEXT_ADDR]], align 8 -// CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON_0:%.*]], %struct.anon.0* [[TMP0]], i32 0, i32 0 -// CHECK-NEXT: [[TMP2:%.*]] = load i64, i64* [[LOGICAL_ADDR]], align 8 -// CHECK-NEXT: [[MUL:%.*]] = mul i64 1, [[TMP2]] -// CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[MUL]] to i32 -// CHECK-NEXT: call void @_ZNK10MyIteratorplEj(%struct.MyIterator* sret([[STRUCT_MYITERATOR]]) align 1 [[REF_TMP]], %struct.MyIterator* noundef [[TMP1]], i32 noundef [[CONV]]) -// CHECK-NEXT: [[TMP3:%.*]] = load %struct.MyIterator*, %struct.MyIterator** [[LOOPVAR_ADDR]], align 8 -// CHECK-NEXT: [[CALL:%.*]] = call noundef nonnull align 1 dereferenceable(1) %struct.MyIterator* @_ZN10MyIteratoraSERKS_(%struct.MyIterator* noundef [[TMP3]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) [[REF_TMP]]) +// CHECK-NEXT: } + + +// CHECK-LABEL: define {{.*}}@__captured_stmt.1( +// CHECK-NEXT: [[ENTRY:.*]]: +// CHECK-NEXT: %[[LOOPVAR_ADDR:.+]] = alloca %struct.MyIterator*, align 8 +// CHECK-NEXT: %[[LOGICAL_ADDR:.+]] = alloca i64, align 8 +// CHECK-NEXT: %[[__CONTEXT_ADDR:.+]] = alloca %struct.anon.0*, align 8 +// CHECK-NEXT: %[[REF_TMP:.+]] = alloca %struct.MyIterator, align 1 +// CHECK-NEXT: store %struct.MyIterator* %[[LOOPVAR:.+]], %struct.MyIterator** %[[LOOPVAR_ADDR]], align 8 +// CHECK-NEXT: store i64 %[[LOGICAL:.+]], i64* %[[LOGICAL_ADDR]], align 8 +// CHECK-NEXT: store %struct.anon.0* %[[__CONTEXT:.+]], %struct.anon.0** %[[__CONTEXT_ADDR]], align 8 +// CHECK-NEXT: %[[TMP0:.+]] = load %struct.anon.0*, %struct.anon.0** %[[__CONTEXT_ADDR]], align 8 +// CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[TMP0]], i32 0, i32 0 +// CHECK-NEXT: %[[TMP2:.+]] = load i64, i64* %[[LOGICAL_ADDR]], align 8 +// CHECK-NEXT: %[[MUL:.+]] = mul i64 1, %[[TMP2]] +// CHECK-NEXT: %[[CONV:.+]] = trunc i64 %[[MUL]] to i32 +// CHECK-NEXT: call void @_ZNK10MyIteratorplEj(%struct.MyIterator* sret(%struct.MyIterator) align 1 %[[REF_TMP]], %struct.MyIterator* noundef %[[TMP1]], i32 noundef %[[CONV]]) +// CHECK-NEXT: %[[TMP3:.+]] = load %struct.MyIterator*, %struct.MyIterator** %[[LOOPVAR_ADDR]], align 8 +// CHECK-NEXT: %[[CALL:.+]] = call noundef nonnull align 1 dereferenceable(1) %struct.MyIterator* @_ZN10MyIteratoraSERKS_(%struct.MyIterator* noundef %[[TMP3]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) %[[REF_TMP]]) // CHECK-NEXT: ret void -// +// CHECK-NEXT: } + + +// CHECK: ![[META0:[0-9]+]] = !{i32 1, !"wchar_size", i32 4} +// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 50} +// CHECK: ![[META2:[0-9]+]] = diff --git a/clang/test/OpenMP/irbuilder_for_rangefor.cpp b/clang/test/OpenMP/irbuilder_for_rangefor.cpp --- a/clang/test/OpenMP/irbuilder_for_rangefor.cpp +++ b/clang/test/OpenMP/irbuilder_for_rangefor.cpp @@ -25,6 +25,100 @@ MyIterator end(); }; +// CHECK-LABEL: define {{.*}}@workshareloop_rangefor( +// CHECK-NEXT: [[ENTRY:.*]]: +// CHECK-NEXT: %[[A_ADDR:.+]] = alloca float*, align 8 +// CHECK-NEXT: %[[B_ADDR:.+]] = alloca float*, align 8 +// CHECK-NEXT: %[[C_ADDR:.+]] = alloca float*, align 8 +// CHECK-NEXT: %[[__RANGE2:.+]] = alloca %struct.MyRange*, align 8 +// CHECK-NEXT: %[[REF_TMP:.+]] = alloca %struct.MyRange, align 1 +// CHECK-NEXT: %[[__BEGIN2:.+]] = alloca %struct.MyIterator, align 1 +// CHECK-NEXT: %[[__END2:.+]] = alloca %struct.MyIterator, align 1 +// CHECK-NEXT: %[[I:.+]] = alloca i32, align 4 +// CHECK-NEXT: %[[AGG_CAPTURED:.+]] = alloca %struct.anon, align 8 +// CHECK-NEXT: %[[AGG_CAPTURED1:.+]] = alloca %struct.anon.0, align 1 +// CHECK-NEXT: %[[DOTCOUNT_ADDR:.+]] = alloca i64, align 8 +// CHECK-NEXT: %[[P_LASTITER:.+]] = alloca i32, align 4 +// CHECK-NEXT: %[[P_LOWERBOUND:.+]] = alloca i64, align 8 +// CHECK-NEXT: %[[P_UPPERBOUND:.+]] = alloca i64, align 8 +// CHECK-NEXT: %[[P_STRIDE:.+]] = alloca i64, align 8 +// CHECK-NEXT: store float* %[[A:.+]], float** %[[A_ADDR]], align 8 +// CHECK-NEXT: store float* %[[B:.+]], float** %[[B_ADDR]], align 8 +// CHECK-NEXT: store float* %[[C:.+]], float** %[[C_ADDR]], align 8 +// CHECK-NEXT: call void @_ZN7MyRangeC1Ei(%struct.MyRange* noundef %[[REF_TMP]], i32 noundef 42) +// CHECK-NEXT: store %struct.MyRange* %[[REF_TMP]], %struct.MyRange** %[[__RANGE2]], align 8 +// CHECK-NEXT: %[[TMP0:.+]] = load %struct.MyRange*, %struct.MyRange** %[[__RANGE2]], align 8 +// CHECK-NEXT: call void @_ZN7MyRange5beginEv(%struct.MyIterator* sret(%struct.MyIterator) align 1 %[[__BEGIN2]], %struct.MyRange* noundef %[[TMP0]]) +// CHECK-NEXT: %[[TMP1:.+]] = load %struct.MyRange*, %struct.MyRange** %[[__RANGE2]], align 8 +// CHECK-NEXT: call void @_ZN7MyRange3endEv(%struct.MyIterator* sret(%struct.MyIterator) align 1 %[[__END2]], %struct.MyRange* noundef %[[TMP1]]) +// CHECK-NEXT: %[[CALL:.+]] = call noundef i32 @_ZNK10MyIteratordeEv(%struct.MyIterator* noundef %[[__BEGIN2]]) +// CHECK-NEXT: store i32 %[[CALL]], i32* %[[I]], align 4 +// CHECK-NEXT: %[[TMP2:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[AGG_CAPTURED]], i32 0, i32 0 +// CHECK-NEXT: store %struct.MyIterator* %[[__BEGIN2]], %struct.MyIterator** %[[TMP2]], align 8 +// CHECK-NEXT: %[[TMP3:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[AGG_CAPTURED]], i32 0, i32 1 +// CHECK-NEXT: store %struct.MyIterator* %[[__END2]], %struct.MyIterator** %[[TMP3]], align 8 +// CHECK-NEXT: %[[TMP4:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[AGG_CAPTURED1]], i32 0, i32 0 +// CHECK-NEXT: call void @_ZN10MyIteratorC1ERKS_(%struct.MyIterator* noundef %[[TMP4]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) %[[__BEGIN2]]) +// CHECK-NEXT: call void @__captured_stmt(i64* %[[DOTCOUNT_ADDR]], %struct.anon* %[[AGG_CAPTURED]]) +// CHECK-NEXT: %[[DOTCOUNT:.+]] = load i64, i64* %[[DOTCOUNT_ADDR]], align 8 +// CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_PREHEADER]]: +// CHECK-NEXT: store i64 0, i64* %[[P_LOWERBOUND]], align 8 +// CHECK-NEXT: %[[TMP5:.+]] = sub i64 %[[DOTCOUNT]], 1 +// CHECK-NEXT: store i64 %[[TMP5]], i64* %[[P_UPPERBOUND]], align 8 +// CHECK-NEXT: store i64 1, i64* %[[P_STRIDE]], align 8 +// CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) +// CHECK-NEXT: call void @__kmpc_for_static_init_8u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i64* %[[P_LOWERBOUND]], i64* %[[P_UPPERBOUND]], i64* %[[P_STRIDE]], i64 1, i64 0) +// CHECK-NEXT: %[[TMP6:.+]] = load i64, i64* %[[P_LOWERBOUND]], align 8 +// CHECK-NEXT: %[[TMP7:.+]] = load i64, i64* %[[P_UPPERBOUND]], align 8 +// CHECK-NEXT: %[[TMP8:.+]] = sub i64 %[[TMP7]], %[[TMP6]] +// CHECK-NEXT: %[[TMP9:.+]] = add i64 %[[TMP8]], 1 +// CHECK-NEXT: br label %[[OMP_LOOP_HEADER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_HEADER]]: +// CHECK-NEXT: %[[OMP_LOOP_IV:.+]] = phi i64 [ 0, %[[OMP_LOOP_PREHEADER]] ], [ %[[OMP_LOOP_NEXT:.+]], %[[OMP_LOOP_INC:.+]] ] +// CHECK-NEXT: br label %[[OMP_LOOP_COND:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_COND]]: +// CHECK-NEXT: %[[OMP_LOOP_CMP:.+]] = icmp ult i64 %[[OMP_LOOP_IV]], %[[TMP9]] +// CHECK-NEXT: br i1 %[[OMP_LOOP_CMP]], label %[[OMP_LOOP_BODY:.+]], label %[[OMP_LOOP_EXIT:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_BODY]]: +// CHECK-NEXT: %[[TMP10:.+]] = add i64 %[[OMP_LOOP_IV]], %[[TMP6]] +// CHECK-NEXT: call void @__captured_stmt.1(i32* %[[I]], i64 %[[TMP10]], %struct.anon.0* %[[AGG_CAPTURED1]]) +// CHECK-NEXT: %[[TMP11:.+]] = load float*, float** %[[B_ADDR]], align 8 +// CHECK-NEXT: %[[TMP12:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM:.+]] = zext i32 %[[TMP12]] to i64 +// CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP11]], i64 %[[IDXPROM]] +// CHECK-NEXT: %[[TMP13:.+]] = load float, float* %[[ARRAYIDX]], align 4 +// CHECK-NEXT: %[[TMP14:.+]] = load float*, float** %[[C_ADDR]], align 8 +// CHECK-NEXT: %[[TMP15:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM2:.+]] = zext i32 %[[TMP15]] to i64 +// CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP14]], i64 %[[IDXPROM2]] +// CHECK-NEXT: %[[TMP16:.+]] = load float, float* %[[ARRAYIDX3]], align 4 +// CHECK-NEXT: %[[MUL:.+]] = fmul float %[[TMP13]], %[[TMP16]] +// CHECK-NEXT: %[[TMP17:.+]] = load float*, float** %[[A_ADDR]], align 8 +// CHECK-NEXT: %[[TMP18:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM4:.+]] = zext i32 %[[TMP18]] to i64 +// CHECK-NEXT: %[[ARRAYIDX5:.+]] = getelementptr inbounds float, float* %[[TMP17]], i64 %[[IDXPROM4]] +// CHECK-NEXT: store float %[[MUL]], float* %[[ARRAYIDX5]], align 4 +// CHECK-NEXT: br label %[[OMP_LOOP_INC]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_INC]]: +// CHECK-NEXT: %[[OMP_LOOP_NEXT]] = add nuw i64 %[[OMP_LOOP_IV]], 1 +// CHECK-NEXT: br label %[[OMP_LOOP_HEADER]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_EXIT]]: +// CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]]) +// CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM6:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) +// CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @2, i32 %[[OMP_GLOBAL_THREAD_NUM6]]) +// CHECK-NEXT: br label %[[OMP_LOOP_AFTER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_AFTER]]: +// CHECK-NEXT: ret void +// CHECK-NEXT: } + extern "C" void workshareloop_rangefor(float *a, float *b, float *c) { #pragma omp for for (unsigned i : MyRange(42)) { @@ -33,153 +127,72 @@ } #endif // HEADER -// CHECK-LABEL: define {{[^@]+}}@workshareloop_rangefor -// CHECK-SAME: (float* noundef [[A:%.*]], float* noundef [[B:%.*]], float* noundef [[C:%.*]]) #[[ATTR0:[0-9]+]] { -// CHECK-NEXT: entry: -// CHECK-NEXT: [[A_ADDR:%.*]] = alloca float*, align 8 -// CHECK-NEXT: [[B_ADDR:%.*]] = alloca float*, align 8 -// CHECK-NEXT: [[C_ADDR:%.*]] = alloca float*, align 8 -// CHECK-NEXT: [[__RANGE2:%.*]] = alloca %struct.MyRange*, align 8 -// CHECK-NEXT: [[REF_TMP:%.*]] = alloca [[STRUCT_MYRANGE:%.*]], align 1 -// CHECK-NEXT: [[__BEGIN2:%.*]] = alloca [[STRUCT_MYITERATOR:%.*]], align 1 -// CHECK-NEXT: [[__END2:%.*]] = alloca [[STRUCT_MYITERATOR]], align 1 -// CHECK-NEXT: [[I:%.*]] = alloca i32, align 4 -// CHECK-NEXT: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], align 8 -// CHECK-NEXT: [[AGG_CAPTURED1:%.*]] = alloca [[STRUCT_ANON_0:%.*]], align 1 -// CHECK-NEXT: [[DOTCOUNT_ADDR:%.*]] = alloca i64, align 8 -// CHECK-NEXT: [[P_LASTITER:%.*]] = alloca i32, align 4 -// CHECK-NEXT: [[P_LOWERBOUND:%.*]] = alloca i64, align 8 -// CHECK-NEXT: [[P_UPPERBOUND:%.*]] = alloca i64, align 8 -// CHECK-NEXT: [[P_STRIDE:%.*]] = alloca i64, align 8 -// CHECK-NEXT: store float* [[A]], float** [[A_ADDR]], align 8 -// CHECK-NEXT: store float* [[B]], float** [[B_ADDR]], align 8 -// CHECK-NEXT: store float* [[C]], float** [[C_ADDR]], align 8 -// CHECK-NEXT: call void @_ZN7MyRangeC1Ei(%struct.MyRange* noundef [[REF_TMP]], i32 noundef 42) -// CHECK-NEXT: store %struct.MyRange* [[REF_TMP]], %struct.MyRange** [[__RANGE2]], align 8 -// CHECK-NEXT: [[TMP0:%.*]] = load %struct.MyRange*, %struct.MyRange** [[__RANGE2]], align 8 -// CHECK-NEXT: call void @_ZN7MyRange5beginEv(%struct.MyIterator* sret([[STRUCT_MYITERATOR]]) align 1 [[__BEGIN2]], %struct.MyRange* noundef [[TMP0]]) -// CHECK-NEXT: [[TMP1:%.*]] = load %struct.MyRange*, %struct.MyRange** [[__RANGE2]], align 8 -// CHECK-NEXT: call void @_ZN7MyRange3endEv(%struct.MyIterator* sret([[STRUCT_MYITERATOR]]) align 1 [[__END2]], %struct.MyRange* noundef [[TMP1]]) -// CHECK-NEXT: [[CALL:%.*]] = call noundef i32 @_ZNK10MyIteratordeEv(%struct.MyIterator* noundef [[__BEGIN2]]) -// CHECK-NEXT: store i32 [[CALL]], i32* [[I]], align 4 -// CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [[STRUCT_ANON]], %struct.anon* [[AGG_CAPTURED]], i32 0, i32 0 -// CHECK-NEXT: store %struct.MyIterator* [[__BEGIN2]], %struct.MyIterator** [[TMP2]], align 8 -// CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [[STRUCT_ANON]], %struct.anon* [[AGG_CAPTURED]], i32 0, i32 1 -// CHECK-NEXT: store %struct.MyIterator* [[__END2]], %struct.MyIterator** [[TMP3]], align 8 -// CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds [[STRUCT_ANON_0]], %struct.anon.0* [[AGG_CAPTURED1]], i32 0, i32 0 -// CHECK-NEXT: call void @_ZN10MyIteratorC1ERKS_(%struct.MyIterator* noundef [[TMP4]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) [[__BEGIN2]]) -// CHECK-NEXT: call void @__captured_stmt(i64* [[DOTCOUNT_ADDR]], %struct.anon* [[AGG_CAPTURED]]) -// CHECK-NEXT: [[DOTCOUNT:%.*]] = load i64, i64* [[DOTCOUNT_ADDR]], align 8 -// CHECK-NEXT: br label [[OMP_LOOP_PREHEADER:%.*]] -// CHECK: omp_loop.preheader: -// CHECK-NEXT: store i64 0, i64* [[P_LOWERBOUND]], align 8 -// CHECK-NEXT: [[TMP5:%.*]] = sub i64 [[DOTCOUNT]], 1 -// CHECK-NEXT: store i64 [[TMP5]], i64* [[P_UPPERBOUND]], align 8 -// CHECK-NEXT: store i64 1, i64* [[P_STRIDE]], align 8 -// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]]) -// CHECK-NEXT: call void @__kmpc_for_static_init_8u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* [[P_LASTITER]], i64* [[P_LOWERBOUND]], i64* [[P_UPPERBOUND]], i64* [[P_STRIDE]], i64 1, i64 1) -// CHECK-NEXT: [[TMP6:%.*]] = load i64, i64* [[P_LOWERBOUND]], align 8 -// CHECK-NEXT: [[TMP7:%.*]] = load i64, i64* [[P_UPPERBOUND]], align 8 -// CHECK-NEXT: [[TMP8:%.*]] = sub i64 [[TMP7]], [[TMP6]] -// CHECK-NEXT: [[TMP9:%.*]] = add i64 [[TMP8]], 1 -// CHECK-NEXT: br label [[OMP_LOOP_HEADER:%.*]] -// CHECK: omp_loop.header: -// CHECK-NEXT: [[OMP_LOOP_IV:%.*]] = phi i64 [ 0, [[OMP_LOOP_PREHEADER]] ], [ [[OMP_LOOP_NEXT:%.*]], [[OMP_LOOP_INC:%.*]] ] -// CHECK-NEXT: br label [[OMP_LOOP_COND:%.*]] -// CHECK: omp_loop.cond: -// CHECK-NEXT: [[OMP_LOOP_CMP:%.*]] = icmp ult i64 [[OMP_LOOP_IV]], [[TMP9]] -// CHECK-NEXT: br i1 [[OMP_LOOP_CMP]], label [[OMP_LOOP_BODY:%.*]], label [[OMP_LOOP_EXIT:%.*]] -// CHECK: omp_loop.body: -// CHECK-NEXT: [[TMP10:%.*]] = add i64 [[OMP_LOOP_IV]], [[TMP6]] -// CHECK-NEXT: call void @__captured_stmt.1(i32* [[I]], i64 [[TMP10]], %struct.anon.0* [[AGG_CAPTURED1]]) -// CHECK-NEXT: [[TMP11:%.*]] = load float*, float** [[B_ADDR]], align 8 -// CHECK-NEXT: [[TMP12:%.*]] = load i32, i32* [[I]], align 4 -// CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[TMP12]] to i64 -// CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[TMP11]], i64 [[IDXPROM]] -// CHECK-NEXT: [[TMP13:%.*]] = load float, float* [[ARRAYIDX]], align 4 -// CHECK-NEXT: [[TMP14:%.*]] = load float*, float** [[C_ADDR]], align 8 -// CHECK-NEXT: [[TMP15:%.*]] = load i32, i32* [[I]], align 4 -// CHECK-NEXT: [[IDXPROM2:%.*]] = zext i32 [[TMP15]] to i64 -// CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds float, float* [[TMP14]], i64 [[IDXPROM2]] -// CHECK-NEXT: [[TMP16:%.*]] = load float, float* [[ARRAYIDX3]], align 4 -// CHECK-NEXT: [[MUL:%.*]] = fmul float [[TMP13]], [[TMP16]] -// CHECK-NEXT: [[TMP17:%.*]] = load float*, float** [[A_ADDR]], align 8 -// CHECK-NEXT: [[TMP18:%.*]] = load i32, i32* [[I]], align 4 -// CHECK-NEXT: [[IDXPROM4:%.*]] = zext i32 [[TMP18]] to i64 -// CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds float, float* [[TMP17]], i64 [[IDXPROM4]] -// CHECK-NEXT: store float [[MUL]], float* [[ARRAYIDX5]], align 4 -// CHECK-NEXT: br label [[OMP_LOOP_INC]] -// CHECK: omp_loop.inc: -// CHECK-NEXT: [[OMP_LOOP_NEXT]] = add nuw i64 [[OMP_LOOP_IV]], 1 -// CHECK-NEXT: br label [[OMP_LOOP_HEADER]] -// CHECK: omp_loop.exit: -// CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]]) -// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM6:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) -// CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @[[GLOB2:[0-9]+]], i32 [[OMP_GLOBAL_THREAD_NUM6]]) -// CHECK-NEXT: br label [[OMP_LOOP_AFTER:%.*]] -// CHECK: omp_loop.after: +// CHECK-LABEL: define {{.*}}@__captured_stmt( +// CHECK-NEXT: [[ENTRY:.*]]: +// CHECK-NEXT: %[[DISTANCE_ADDR:.+]] = alloca i64*, align 8 +// CHECK-NEXT: %[[__CONTEXT_ADDR:.+]] = alloca %struct.anon*, align 8 +// CHECK-NEXT: %[[DOTSTART:.+]] = alloca %struct.MyIterator, align 1 +// CHECK-NEXT: %[[DOTSTOP:.+]] = alloca %struct.MyIterator, align 1 +// CHECK-NEXT: %[[DOTSTEP:.+]] = alloca i64, align 8 +// CHECK-NEXT: store i64* %[[DISTANCE:.+]], i64** %[[DISTANCE_ADDR]], align 8 +// CHECK-NEXT: store %struct.anon* %[[__CONTEXT:.+]], %struct.anon** %[[__CONTEXT_ADDR]], align 8 +// CHECK-NEXT: %[[TMP0:.+]] = load %struct.anon*, %struct.anon** %[[__CONTEXT_ADDR]], align 8 +// CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[TMP0]], i32 0, i32 0 +// CHECK-NEXT: %[[TMP2:.+]] = load %struct.MyIterator*, %struct.MyIterator** %[[TMP1]], align 8 +// CHECK-NEXT: call void @_ZN10MyIteratorC1ERKS_(%struct.MyIterator* noundef %[[DOTSTART]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) %[[TMP2]]) +// CHECK-NEXT: %[[TMP3:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[TMP0]], i32 0, i32 1 +// CHECK-NEXT: %[[TMP4:.+]] = load %struct.MyIterator*, %struct.MyIterator** %[[TMP3]], align 8 +// CHECK-NEXT: call void @_ZN10MyIteratorC1ERKS_(%struct.MyIterator* noundef %[[DOTSTOP]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) %[[TMP4]]) +// CHECK-NEXT: store i64 1, i64* %[[DOTSTEP]], align 8 +// CHECK-NEXT: %[[TMP5:.+]] = load i64, i64* %[[DOTSTEP]], align 8 +// CHECK-NEXT: %[[CMP:.+]] = icmp ult i64 %[[TMP5]], 0 +// CHECK-NEXT: br i1 %[[CMP]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[COND_TRUE]]: +// CHECK-NEXT: %[[CALL:.+]] = call noundef i32 @_ZNK10MyIteratormiERKS_(%struct.MyIterator* noundef %[[DOTSTART]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) %[[DOTSTOP]]) +// CHECK-NEXT: %[[CONV:.+]] = sext i32 %[[CALL]] to i64 +// CHECK-NEXT: %[[TMP6:.+]] = load i64, i64* %[[DOTSTEP]], align 8 +// CHECK-NEXT: %[[SUB:.+]] = sub i64 0, %[[TMP6]] +// CHECK-NEXT: %[[DIV:.+]] = udiv i64 %[[CONV]], %[[SUB]] +// CHECK-NEXT: br label %[[COND_END:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[COND_FALSE]]: +// CHECK-NEXT: %[[CALL1:.+]] = call noundef i32 @_ZNK10MyIteratormiERKS_(%struct.MyIterator* noundef %[[DOTSTOP]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) %[[DOTSTART]]) +// CHECK-NEXT: %[[CONV2:.+]] = sext i32 %[[CALL1]] to i64 +// CHECK-NEXT: %[[TMP7:.+]] = load i64, i64* %[[DOTSTEP]], align 8 +// CHECK-NEXT: %[[DIV3:.+]] = udiv i64 %[[CONV2]], %[[TMP7]] +// CHECK-NEXT: br label %[[COND_END]] +// CHECK-EMPTY: +// CHECK-NEXT: [[COND_END]]: +// CHECK-NEXT: %[[COND:.+]] = phi i64 [ %[[DIV]], %[[COND_TRUE]] ], [ %[[DIV3]], %[[COND_FALSE]] ] +// CHECK-NEXT: %[[TMP8:.+]] = load i64*, i64** %[[DISTANCE_ADDR]], align 8 +// CHECK-NEXT: store i64 %[[COND]], i64* %[[TMP8]], align 8 // CHECK-NEXT: ret void -// -// -// CHECK-LABEL: define {{[^@]+}}@__captured_stmt -// CHECK-SAME: (i64* noundef nonnull align 8 dereferenceable(8) [[DISTANCE:%.*]], %struct.anon* noalias noundef [[__CONTEXT:%.*]]) #[[ATTR2:[0-9]+]] { -// CHECK-NEXT: entry: -// CHECK-NEXT: [[DISTANCE_ADDR:%.*]] = alloca i64*, align 8 -// CHECK-NEXT: [[__CONTEXT_ADDR:%.*]] = alloca %struct.anon*, align 8 -// CHECK-NEXT: [[DOTSTART:%.*]] = alloca [[STRUCT_MYITERATOR:%.*]], align 1 -// CHECK-NEXT: [[DOTSTOP:%.*]] = alloca [[STRUCT_MYITERATOR]], align 1 -// CHECK-NEXT: [[DOTSTEP:%.*]] = alloca i64, align 8 -// CHECK-NEXT: store i64* [[DISTANCE]], i64** [[DISTANCE_ADDR]], align 8 -// CHECK-NEXT: store %struct.anon* [[__CONTEXT]], %struct.anon** [[__CONTEXT_ADDR]], align 8 -// CHECK-NEXT: [[TMP0:%.*]] = load %struct.anon*, %struct.anon** [[__CONTEXT_ADDR]], align 8 -// CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON:%.*]], %struct.anon* [[TMP0]], i32 0, i32 0 -// CHECK-NEXT: [[TMP2:%.*]] = load %struct.MyIterator*, %struct.MyIterator** [[TMP1]], align 8 -// CHECK-NEXT: call void @_ZN10MyIteratorC1ERKS_(%struct.MyIterator* noundef [[DOTSTART]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) [[TMP2]]) -// CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [[STRUCT_ANON]], %struct.anon* [[TMP0]], i32 0, i32 1 -// CHECK-NEXT: [[TMP4:%.*]] = load %struct.MyIterator*, %struct.MyIterator** [[TMP3]], align 8 -// CHECK-NEXT: call void @_ZN10MyIteratorC1ERKS_(%struct.MyIterator* noundef [[DOTSTOP]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) [[TMP4]]) -// CHECK-NEXT: store i64 1, i64* [[DOTSTEP]], align 8 -// CHECK-NEXT: [[TMP5:%.*]] = load i64, i64* [[DOTSTEP]], align 8 -// CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[TMP5]], 0 -// CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]] -// CHECK: cond.true: -// CHECK-NEXT: [[CALL:%.*]] = call noundef i32 @_ZNK10MyIteratormiERKS_(%struct.MyIterator* noundef [[DOTSTART]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) [[DOTSTOP]]) -// CHECK-NEXT: [[CONV:%.*]] = sext i32 [[CALL]] to i64 -// CHECK-NEXT: [[TMP6:%.*]] = load i64, i64* [[DOTSTEP]], align 8 -// CHECK-NEXT: [[SUB:%.*]] = sub i64 0, [[TMP6]] -// CHECK-NEXT: [[DIV:%.*]] = udiv i64 [[CONV]], [[SUB]] -// CHECK-NEXT: br label [[COND_END:%.*]] -// CHECK: cond.false: -// CHECK-NEXT: [[CALL1:%.*]] = call noundef i32 @_ZNK10MyIteratormiERKS_(%struct.MyIterator* noundef [[DOTSTOP]], %struct.MyIterator* noundef nonnull align 1 dereferenceable(1) [[DOTSTART]]) -// CHECK-NEXT: [[CONV2:%.*]] = sext i32 [[CALL1]] to i64 -// CHECK-NEXT: [[TMP7:%.*]] = load i64, i64* [[DOTSTEP]], align 8 -// CHECK-NEXT: [[DIV3:%.*]] = udiv i64 [[CONV2]], [[TMP7]] -// CHECK-NEXT: br label [[COND_END]] -// CHECK: cond.end: -// CHECK-NEXT: [[COND:%.*]] = phi i64 [ [[DIV]], [[COND_TRUE]] ], [ [[DIV3]], [[COND_FALSE]] ] -// CHECK-NEXT: [[TMP8:%.*]] = load i64*, i64** [[DISTANCE_ADDR]], align 8 -// CHECK-NEXT: store i64 [[COND]], i64* [[TMP8]], align 8 -// CHECK-NEXT: ret void -// -// -// CHECK-LABEL: define {{[^@]+}}@__captured_stmt.1 -// CHECK-SAME: (i32* noundef nonnull align 4 dereferenceable(4) [[LOOPVAR:%.*]], i64 noundef [[LOGICAL:%.*]], %struct.anon.0* noalias noundef [[__CONTEXT:%.*]]) #[[ATTR2]] { -// CHECK-NEXT: entry: -// CHECK-NEXT: [[LOOPVAR_ADDR:%.*]] = alloca i32*, align 8 -// CHECK-NEXT: [[LOGICAL_ADDR:%.*]] = alloca i64, align 8 -// CHECK-NEXT: [[__CONTEXT_ADDR:%.*]] = alloca %struct.anon.0*, align 8 -// CHECK-NEXT: [[REF_TMP:%.*]] = alloca [[STRUCT_MYITERATOR:%.*]], align 1 -// CHECK-NEXT: store i32* [[LOOPVAR]], i32** [[LOOPVAR_ADDR]], align 8 -// CHECK-NEXT: store i64 [[LOGICAL]], i64* [[LOGICAL_ADDR]], align 8 -// CHECK-NEXT: store %struct.anon.0* [[__CONTEXT]], %struct.anon.0** [[__CONTEXT_ADDR]], align 8 -// CHECK-NEXT: [[TMP0:%.*]] = load %struct.anon.0*, %struct.anon.0** [[__CONTEXT_ADDR]], align 8 -// CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON_0:%.*]], %struct.anon.0* [[TMP0]], i32 0, i32 0 -// CHECK-NEXT: [[TMP2:%.*]] = load i64, i64* [[LOGICAL_ADDR]], align 8 -// CHECK-NEXT: [[MUL:%.*]] = mul i64 1, [[TMP2]] -// CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[MUL]] to i32 -// CHECK-NEXT: call void @_ZNK10MyIteratorplEj(%struct.MyIterator* sret([[STRUCT_MYITERATOR]]) align 1 [[REF_TMP]], %struct.MyIterator* noundef [[TMP1]], i32 noundef [[CONV]]) -// CHECK-NEXT: [[CALL:%.*]] = call noundef i32 @_ZNK10MyIteratordeEv(%struct.MyIterator* noundef [[REF_TMP]]) -// CHECK-NEXT: [[TMP3:%.*]] = load i32*, i32** [[LOOPVAR_ADDR]], align 8 -// CHECK-NEXT: store i32 [[CALL]], i32* [[TMP3]], align 4 +// CHECK-NEXT: } + + +// CHECK-LABEL: define {{.*}}@__captured_stmt.1( +// CHECK-NEXT: [[ENTRY:.*]]: +// CHECK-NEXT: %[[LOOPVAR_ADDR:.+]] = alloca i32*, align 8 +// CHECK-NEXT: %[[LOGICAL_ADDR:.+]] = alloca i64, align 8 +// CHECK-NEXT: %[[__CONTEXT_ADDR:.+]] = alloca %struct.anon.0*, align 8 +// CHECK-NEXT: %[[REF_TMP:.+]] = alloca %struct.MyIterator, align 1 +// CHECK-NEXT: store i32* %[[LOOPVAR:.+]], i32** %[[LOOPVAR_ADDR]], align 8 +// CHECK-NEXT: store i64 %[[LOGICAL:.+]], i64* %[[LOGICAL_ADDR]], align 8 +// CHECK-NEXT: store %struct.anon.0* %[[__CONTEXT:.+]], %struct.anon.0** %[[__CONTEXT_ADDR]], align 8 +// CHECK-NEXT: %[[TMP0:.+]] = load %struct.anon.0*, %struct.anon.0** %[[__CONTEXT_ADDR]], align 8 +// CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[TMP0]], i32 0, i32 0 +// CHECK-NEXT: %[[TMP2:.+]] = load i64, i64* %[[LOGICAL_ADDR]], align 8 +// CHECK-NEXT: %[[MUL:.+]] = mul i64 1, %[[TMP2]] +// CHECK-NEXT: %[[CONV:.+]] = trunc i64 %[[MUL]] to i32 +// CHECK-NEXT: call void @_ZNK10MyIteratorplEj(%struct.MyIterator* sret(%struct.MyIterator) align 1 %[[REF_TMP]], %struct.MyIterator* noundef %[[TMP1]], i32 noundef %[[CONV]]) +// CHECK-NEXT: %[[CALL:.+]] = call noundef i32 @_ZNK10MyIteratordeEv(%struct.MyIterator* noundef %[[REF_TMP]]) +// CHECK-NEXT: %[[TMP3:.+]] = load i32*, i32** %[[LOOPVAR_ADDR]], align 8 +// CHECK-NEXT: store i32 %[[CALL]], i32* %[[TMP3]], align 4 // CHECK-NEXT: ret void -// +// CHECK-NEXT: } + + +// CHECK: ![[META0:[0-9]+]] = !{i32 1, !"wchar_size", i32 4} +// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 50} +// CHECK: ![[META2:[0-9]+]] = diff --git a/clang/test/OpenMP/irbuilder_for_unsigned.c b/clang/test/OpenMP/irbuilder_for_unsigned.c --- a/clang/test/OpenMP/irbuilder_for_unsigned.c +++ b/clang/test/OpenMP/irbuilder_for_unsigned.c @@ -5,6 +5,96 @@ #ifndef HEADER #define HEADER +// CHECK-LABEL: define {{.*}}@workshareloop_unsigned( +// CHECK-NEXT: [[ENTRY:.*]]: +// CHECK-NEXT: %[[A_ADDR:.+]] = alloca float*, align 8 +// CHECK-NEXT: %[[B_ADDR:.+]] = alloca float*, align 8 +// CHECK-NEXT: %[[C_ADDR:.+]] = alloca float*, align 8 +// CHECK-NEXT: %[[D_ADDR:.+]] = alloca float*, align 8 +// CHECK-NEXT: %[[I:.+]] = alloca i32, align 4 +// CHECK-NEXT: %[[AGG_CAPTURED:.+]] = alloca %struct.anon, align 8 +// CHECK-NEXT: %[[AGG_CAPTURED1:.+]] = alloca %struct.anon.0, align 4 +// CHECK-NEXT: %[[DOTCOUNT_ADDR:.+]] = alloca i32, align 4 +// CHECK-NEXT: %[[P_LASTITER:.+]] = alloca i32, align 4 +// CHECK-NEXT: %[[P_LOWERBOUND:.+]] = alloca i32, align 4 +// CHECK-NEXT: %[[P_UPPERBOUND:.+]] = alloca i32, align 4 +// CHECK-NEXT: %[[P_STRIDE:.+]] = alloca i32, align 4 +// CHECK-NEXT: store float* %[[A:.+]], float** %[[A_ADDR]], align 8 +// CHECK-NEXT: store float* %[[B:.+]], float** %[[B_ADDR]], align 8 +// CHECK-NEXT: store float* %[[C:.+]], float** %[[C_ADDR]], align 8 +// CHECK-NEXT: store float* %[[D:.+]], float** %[[D_ADDR]], align 8 +// CHECK-NEXT: store i32 33, i32* %[[I]], align 4 +// CHECK-NEXT: %[[TMP0:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[AGG_CAPTURED]], i32 0, i32 0 +// CHECK-NEXT: store i32* %[[I]], i32** %[[TMP0]], align 8 +// CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[AGG_CAPTURED1]], i32 0, i32 0 +// CHECK-NEXT: %[[TMP2:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: store i32 %[[TMP2]], i32* %[[TMP1]], align 4 +// CHECK-NEXT: call void @__captured_stmt(i32* %[[DOTCOUNT_ADDR]], %struct.anon* %[[AGG_CAPTURED]]) +// CHECK-NEXT: %[[DOTCOUNT:.+]] = load i32, i32* %[[DOTCOUNT_ADDR]], align 4 +// CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_PREHEADER]]: +// CHECK-NEXT: store i32 0, i32* %[[P_LOWERBOUND]], align 4 +// CHECK-NEXT: %[[TMP3:.+]] = sub i32 %[[DOTCOUNT]], 1 +// CHECK-NEXT: store i32 %[[TMP3]], i32* %[[P_UPPERBOUND]], align 4 +// CHECK-NEXT: store i32 1, i32* %[[P_STRIDE]], align 4 +// CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) +// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 0) +// CHECK-NEXT: %[[TMP4:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 +// CHECK-NEXT: %[[TMP5:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 +// CHECK-NEXT: %[[TMP6:.+]] = sub i32 %[[TMP5]], %[[TMP4]] +// CHECK-NEXT: %[[TMP7:.+]] = add i32 %[[TMP6]], 1 +// CHECK-NEXT: br label %[[OMP_LOOP_HEADER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_HEADER]]: +// CHECK-NEXT: %[[OMP_LOOP_IV:.+]] = phi i32 [ 0, %[[OMP_LOOP_PREHEADER]] ], [ %[[OMP_LOOP_NEXT:.+]], %[[OMP_LOOP_INC:.+]] ] +// CHECK-NEXT: br label %[[OMP_LOOP_COND:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_COND]]: +// CHECK-NEXT: %[[OMP_LOOP_CMP:.+]] = icmp ult i32 %[[OMP_LOOP_IV]], %[[TMP7]] +// CHECK-NEXT: br i1 %[[OMP_LOOP_CMP]], label %[[OMP_LOOP_BODY:.+]], label %[[OMP_LOOP_EXIT:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_BODY]]: +// CHECK-NEXT: %[[TMP8:.+]] = add i32 %[[OMP_LOOP_IV]], %[[TMP4]] +// CHECK-NEXT: call void @__captured_stmt.1(i32* %[[I]], i32 %[[TMP8]], %struct.anon.0* %[[AGG_CAPTURED1]]) +// CHECK-NEXT: %[[TMP9:.+]] = load float*, float** %[[B_ADDR]], align 8 +// CHECK-NEXT: %[[TMP10:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM:.+]] = zext i32 %[[TMP10]] to i64 +// CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP9]], i64 %[[IDXPROM]] +// CHECK-NEXT: %[[TMP11:.+]] = load float, float* %[[ARRAYIDX]], align 4 +// CHECK-NEXT: %[[TMP12:.+]] = load float*, float** %[[C_ADDR]], align 8 +// CHECK-NEXT: %[[TMP13:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM2:.+]] = zext i32 %[[TMP13]] to i64 +// CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP12]], i64 %[[IDXPROM2]] +// CHECK-NEXT: %[[TMP14:.+]] = load float, float* %[[ARRAYIDX3]], align 4 +// CHECK-NEXT: %[[MUL:.+]] = fmul float %[[TMP11]], %[[TMP14]] +// CHECK-NEXT: %[[TMP15:.+]] = load float*, float** %[[D_ADDR]], align 8 +// CHECK-NEXT: %[[TMP16:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM4:.+]] = zext i32 %[[TMP16]] to i64 +// CHECK-NEXT: %[[ARRAYIDX5:.+]] = getelementptr inbounds float, float* %[[TMP15]], i64 %[[IDXPROM4]] +// CHECK-NEXT: %[[TMP17:.+]] = load float, float* %[[ARRAYIDX5]], align 4 +// CHECK-NEXT: %[[MUL6:.+]] = fmul float %[[MUL]], %[[TMP17]] +// CHECK-NEXT: %[[TMP18:.+]] = load float*, float** %[[A_ADDR]], align 8 +// CHECK-NEXT: %[[TMP19:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM7:.+]] = zext i32 %[[TMP19]] to i64 +// CHECK-NEXT: %[[ARRAYIDX8:.+]] = getelementptr inbounds float, float* %[[TMP18]], i64 %[[IDXPROM7]] +// CHECK-NEXT: store float %[[MUL6]], float* %[[ARRAYIDX8]], align 4 +// CHECK-NEXT: br label %[[OMP_LOOP_INC]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_INC]]: +// CHECK-NEXT: %[[OMP_LOOP_NEXT]] = add nuw i32 %[[OMP_LOOP_IV]], 1 +// CHECK-NEXT: br label %[[OMP_LOOP_HEADER]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_EXIT]]: +// CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]]) +// CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM9:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) +// CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @2, i32 %[[OMP_GLOBAL_THREAD_NUM9]]) +// CHECK-NEXT: br label %[[OMP_LOOP_AFTER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_AFTER]]: +// CHECK-NEXT: ret void +// CHECK-NEXT: } + extern "C" void workshareloop_unsigned(float *a, float *b, float *c, float *d) { #pragma omp for for (unsigned i = 33; i < 32000000; i += 7) { @@ -13,143 +103,66 @@ } #endif // HEADER -// CHECK-LABEL: define {{[^@]+}}@workshareloop_unsigned -// CHECK-SAME: (float* noundef [[A:%.*]], float* noundef [[B:%.*]], float* noundef [[C:%.*]], float* noundef [[D:%.*]]) #[[ATTR0:[0-9]+]] { -// CHECK-NEXT: entry: -// CHECK-NEXT: [[A_ADDR:%.*]] = alloca float*, align 8 -// CHECK-NEXT: [[B_ADDR:%.*]] = alloca float*, align 8 -// CHECK-NEXT: [[C_ADDR:%.*]] = alloca float*, align 8 -// CHECK-NEXT: [[D_ADDR:%.*]] = alloca float*, align 8 -// CHECK-NEXT: [[I:%.*]] = alloca i32, align 4 -// CHECK-NEXT: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], align 8 -// CHECK-NEXT: [[AGG_CAPTURED1:%.*]] = alloca [[STRUCT_ANON_0:%.*]], align 4 -// CHECK-NEXT: [[DOTCOUNT_ADDR:%.*]] = alloca i32, align 4 -// CHECK-NEXT: [[P_LASTITER:%.*]] = alloca i32, align 4 -// CHECK-NEXT: [[P_LOWERBOUND:%.*]] = alloca i32, align 4 -// CHECK-NEXT: [[P_UPPERBOUND:%.*]] = alloca i32, align 4 -// CHECK-NEXT: [[P_STRIDE:%.*]] = alloca i32, align 4 -// CHECK-NEXT: store float* [[A]], float** [[A_ADDR]], align 8 -// CHECK-NEXT: store float* [[B]], float** [[B_ADDR]], align 8 -// CHECK-NEXT: store float* [[C]], float** [[C_ADDR]], align 8 -// CHECK-NEXT: store float* [[D]], float** [[D_ADDR]], align 8 -// CHECK-NEXT: store i32 33, i32* [[I]], align 4 -// CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds [[STRUCT_ANON]], %struct.anon* [[AGG_CAPTURED]], i32 0, i32 0 -// CHECK-NEXT: store i32* [[I]], i32** [[TMP0]], align 8 -// CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON_0]], %struct.anon.0* [[AGG_CAPTURED1]], i32 0, i32 0 -// CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[I]], align 4 -// CHECK-NEXT: store i32 [[TMP2]], i32* [[TMP1]], align 4 -// CHECK-NEXT: call void @__captured_stmt(i32* [[DOTCOUNT_ADDR]], %struct.anon* [[AGG_CAPTURED]]) -// CHECK-NEXT: [[DOTCOUNT:%.*]] = load i32, i32* [[DOTCOUNT_ADDR]], align 4 -// CHECK-NEXT: br label [[OMP_LOOP_PREHEADER:%.*]] -// CHECK: omp_loop.preheader: -// CHECK-NEXT: store i32 0, i32* [[P_LOWERBOUND]], align 4 -// CHECK-NEXT: [[TMP3:%.*]] = sub i32 [[DOTCOUNT]], 1 -// CHECK-NEXT: store i32 [[TMP3]], i32* [[P_UPPERBOUND]], align 4 -// CHECK-NEXT: store i32 1, i32* [[P_STRIDE]], align 4 -// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]]) -// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* [[P_LASTITER]], i32* [[P_LOWERBOUND]], i32* [[P_UPPERBOUND]], i32* [[P_STRIDE]], i32 1, i32 1) -// CHECK-NEXT: [[TMP4:%.*]] = load i32, i32* [[P_LOWERBOUND]], align 4 -// CHECK-NEXT: [[TMP5:%.*]] = load i32, i32* [[P_UPPERBOUND]], align 4 -// CHECK-NEXT: [[TMP6:%.*]] = sub i32 [[TMP5]], [[TMP4]] -// CHECK-NEXT: [[TMP7:%.*]] = add i32 [[TMP6]], 1 -// CHECK-NEXT: br label [[OMP_LOOP_HEADER:%.*]] -// CHECK: omp_loop.header: -// CHECK-NEXT: [[OMP_LOOP_IV:%.*]] = phi i32 [ 0, [[OMP_LOOP_PREHEADER]] ], [ [[OMP_LOOP_NEXT:%.*]], [[OMP_LOOP_INC:%.*]] ] -// CHECK-NEXT: br label [[OMP_LOOP_COND:%.*]] -// CHECK: omp_loop.cond: -// CHECK-NEXT: [[OMP_LOOP_CMP:%.*]] = icmp ult i32 [[OMP_LOOP_IV]], [[TMP7]] -// CHECK-NEXT: br i1 [[OMP_LOOP_CMP]], label [[OMP_LOOP_BODY:%.*]], label [[OMP_LOOP_EXIT:%.*]] -// CHECK: omp_loop.body: -// CHECK-NEXT: [[TMP8:%.*]] = add i32 [[OMP_LOOP_IV]], [[TMP4]] -// CHECK-NEXT: call void @__captured_stmt.1(i32* [[I]], i32 [[TMP8]], %struct.anon.0* [[AGG_CAPTURED1]]) -// CHECK-NEXT: [[TMP9:%.*]] = load float*, float** [[B_ADDR]], align 8 -// CHECK-NEXT: [[TMP10:%.*]] = load i32, i32* [[I]], align 4 -// CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[TMP10]] to i64 -// CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[TMP9]], i64 [[IDXPROM]] -// CHECK-NEXT: [[TMP11:%.*]] = load float, float* [[ARRAYIDX]], align 4 -// CHECK-NEXT: [[TMP12:%.*]] = load float*, float** [[C_ADDR]], align 8 -// CHECK-NEXT: [[TMP13:%.*]] = load i32, i32* [[I]], align 4 -// CHECK-NEXT: [[IDXPROM2:%.*]] = zext i32 [[TMP13]] to i64 -// CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds float, float* [[TMP12]], i64 [[IDXPROM2]] -// CHECK-NEXT: [[TMP14:%.*]] = load float, float* [[ARRAYIDX3]], align 4 -// CHECK-NEXT: [[MUL:%.*]] = fmul float [[TMP11]], [[TMP14]] -// CHECK-NEXT: [[TMP15:%.*]] = load float*, float** [[D_ADDR]], align 8 -// CHECK-NEXT: [[TMP16:%.*]] = load i32, i32* [[I]], align 4 -// CHECK-NEXT: [[IDXPROM4:%.*]] = zext i32 [[TMP16]] to i64 -// CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds float, float* [[TMP15]], i64 [[IDXPROM4]] -// CHECK-NEXT: [[TMP17:%.*]] = load float, float* [[ARRAYIDX5]], align 4 -// CHECK-NEXT: [[MUL6:%.*]] = fmul float [[MUL]], [[TMP17]] -// CHECK-NEXT: [[TMP18:%.*]] = load float*, float** [[A_ADDR]], align 8 -// CHECK-NEXT: [[TMP19:%.*]] = load i32, i32* [[I]], align 4 -// CHECK-NEXT: [[IDXPROM7:%.*]] = zext i32 [[TMP19]] to i64 -// CHECK-NEXT: [[ARRAYIDX8:%.*]] = getelementptr inbounds float, float* [[TMP18]], i64 [[IDXPROM7]] -// CHECK-NEXT: store float [[MUL6]], float* [[ARRAYIDX8]], align 4 -// CHECK-NEXT: br label [[OMP_LOOP_INC]] -// CHECK: omp_loop.inc: -// CHECK-NEXT: [[OMP_LOOP_NEXT]] = add nuw i32 [[OMP_LOOP_IV]], 1 -// CHECK-NEXT: br label [[OMP_LOOP_HEADER]] -// CHECK: omp_loop.exit: -// CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]]) -// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM9:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) -// CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @[[GLOB2:[0-9]+]], i32 [[OMP_GLOBAL_THREAD_NUM9]]) -// CHECK-NEXT: br label [[OMP_LOOP_AFTER:%.*]] -// CHECK: omp_loop.after: +// CHECK-LABEL: define {{.*}}@__captured_stmt( +// CHECK-NEXT: [[ENTRY:.*]]: +// CHECK-NEXT: %[[DISTANCE_ADDR:.+]] = alloca i32*, align 8 +// CHECK-NEXT: %[[__CONTEXT_ADDR:.+]] = alloca %struct.anon*, align 8 +// CHECK-NEXT: %[[DOTSTART:.+]] = alloca i32, align 4 +// CHECK-NEXT: %[[DOTSTOP:.+]] = alloca i32, align 4 +// CHECK-NEXT: %[[DOTSTEP:.+]] = alloca i32, align 4 +// CHECK-NEXT: store i32* %[[DISTANCE:.+]], i32** %[[DISTANCE_ADDR]], align 8 +// CHECK-NEXT: store %struct.anon* %[[__CONTEXT:.+]], %struct.anon** %[[__CONTEXT_ADDR]], align 8 +// CHECK-NEXT: %[[TMP0:.+]] = load %struct.anon*, %struct.anon** %[[__CONTEXT_ADDR]], align 8 +// CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[TMP0]], i32 0, i32 0 +// CHECK-NEXT: %[[TMP2:.+]] = load i32*, i32** %[[TMP1]], align 8 +// CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[TMP2]], align 4 +// CHECK-NEXT: store i32 %[[TMP3]], i32* %[[DOTSTART]], align 4 +// CHECK-NEXT: store i32 32000000, i32* %[[DOTSTOP]], align 4 +// CHECK-NEXT: store i32 7, i32* %[[DOTSTEP]], align 4 +// CHECK-NEXT: %[[TMP4:.+]] = load i32, i32* %[[DOTSTART]], align 4 +// CHECK-NEXT: %[[TMP5:.+]] = load i32, i32* %[[DOTSTOP]], align 4 +// CHECK-NEXT: %[[CMP:.+]] = icmp ult i32 %[[TMP4]], %[[TMP5]] +// CHECK-NEXT: br i1 %[[CMP]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[COND_TRUE]]: +// CHECK-NEXT: %[[TMP6:.+]] = load i32, i32* %[[DOTSTOP]], align 4 +// CHECK-NEXT: %[[TMP7:.+]] = load i32, i32* %[[DOTSTART]], align 4 +// CHECK-NEXT: %[[SUB:.+]] = sub i32 %[[TMP6]], %[[TMP7]] +// CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[DOTSTEP]], align 4 +// CHECK-NEXT: %[[DIV:.+]] = udiv i32 %[[SUB]], %[[TMP8]] +// CHECK-NEXT: br label %[[COND_END:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[COND_FALSE]]: +// CHECK-NEXT: br label %[[COND_END]] +// CHECK-EMPTY: +// CHECK-NEXT: [[COND_END]]: +// CHECK-NEXT: %[[COND:.+]] = phi i32 [ %[[DIV]], %[[COND_TRUE]] ], [ 0, %[[COND_FALSE]] ] +// CHECK-NEXT: %[[TMP9:.+]] = load i32*, i32** %[[DISTANCE_ADDR]], align 8 +// CHECK-NEXT: store i32 %[[COND]], i32* %[[TMP9]], align 4 // CHECK-NEXT: ret void -// -// -// CHECK-LABEL: define {{[^@]+}}@__captured_stmt -// CHECK-SAME: (i32* noundef nonnull align 4 dereferenceable(4) [[DISTANCE:%.*]], %struct.anon* noalias noundef [[__CONTEXT:%.*]]) #[[ATTR1:[0-9]+]] { -// CHECK-NEXT: entry: -// CHECK-NEXT: [[DISTANCE_ADDR:%.*]] = alloca i32*, align 8 -// CHECK-NEXT: [[__CONTEXT_ADDR:%.*]] = alloca %struct.anon*, align 8 -// CHECK-NEXT: [[DOTSTART:%.*]] = alloca i32, align 4 -// CHECK-NEXT: [[DOTSTOP:%.*]] = alloca i32, align 4 -// CHECK-NEXT: [[DOTSTEP:%.*]] = alloca i32, align 4 -// CHECK-NEXT: store i32* [[DISTANCE]], i32** [[DISTANCE_ADDR]], align 8 -// CHECK-NEXT: store %struct.anon* [[__CONTEXT]], %struct.anon** [[__CONTEXT_ADDR]], align 8 -// CHECK-NEXT: [[TMP0:%.*]] = load %struct.anon*, %struct.anon** [[__CONTEXT_ADDR]], align 8 -// CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON:%.*]], %struct.anon* [[TMP0]], i32 0, i32 0 -// CHECK-NEXT: [[TMP2:%.*]] = load i32*, i32** [[TMP1]], align 8 -// CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* [[TMP2]], align 4 -// CHECK-NEXT: store i32 [[TMP3]], i32* [[DOTSTART]], align 4 -// CHECK-NEXT: store i32 32000000, i32* [[DOTSTOP]], align 4 -// CHECK-NEXT: store i32 7, i32* [[DOTSTEP]], align 4 -// CHECK-NEXT: [[TMP4:%.*]] = load i32, i32* [[DOTSTART]], align 4 -// CHECK-NEXT: [[TMP5:%.*]] = load i32, i32* [[DOTSTOP]], align 4 -// CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[TMP4]], [[TMP5]] -// CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]] -// CHECK: cond.true: -// CHECK-NEXT: [[TMP6:%.*]] = load i32, i32* [[DOTSTOP]], align 4 -// CHECK-NEXT: [[TMP7:%.*]] = load i32, i32* [[DOTSTART]], align 4 -// CHECK-NEXT: [[SUB:%.*]] = sub i32 [[TMP6]], [[TMP7]] -// CHECK-NEXT: [[TMP8:%.*]] = load i32, i32* [[DOTSTEP]], align 4 -// CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[SUB]], [[TMP8]] -// CHECK-NEXT: br label [[COND_END:%.*]] -// CHECK: cond.false: -// CHECK-NEXT: br label [[COND_END]] -// CHECK: cond.end: -// CHECK-NEXT: [[COND:%.*]] = phi i32 [ [[DIV]], [[COND_TRUE]] ], [ 0, [[COND_FALSE]] ] -// CHECK-NEXT: [[TMP9:%.*]] = load i32*, i32** [[DISTANCE_ADDR]], align 8 -// CHECK-NEXT: store i32 [[COND]], i32* [[TMP9]], align 4 -// CHECK-NEXT: ret void -// -// -// CHECK-LABEL: define {{[^@]+}}@__captured_stmt.1 -// CHECK-SAME: (i32* noundef nonnull align 4 dereferenceable(4) [[LOOPVAR:%.*]], i32 noundef [[LOGICAL:%.*]], %struct.anon.0* noalias noundef [[__CONTEXT:%.*]]) #[[ATTR1]] { -// CHECK-NEXT: entry: -// CHECK-NEXT: [[LOOPVAR_ADDR:%.*]] = alloca i32*, align 8 -// CHECK-NEXT: [[LOGICAL_ADDR:%.*]] = alloca i32, align 4 -// CHECK-NEXT: [[__CONTEXT_ADDR:%.*]] = alloca %struct.anon.0*, align 8 -// CHECK-NEXT: store i32* [[LOOPVAR]], i32** [[LOOPVAR_ADDR]], align 8 -// CHECK-NEXT: store i32 [[LOGICAL]], i32* [[LOGICAL_ADDR]], align 4 -// CHECK-NEXT: store %struct.anon.0* [[__CONTEXT]], %struct.anon.0** [[__CONTEXT_ADDR]], align 8 -// CHECK-NEXT: [[TMP0:%.*]] = load %struct.anon.0*, %struct.anon.0** [[__CONTEXT_ADDR]], align 8 -// CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON_0:%.*]], %struct.anon.0* [[TMP0]], i32 0, i32 0 -// CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[TMP1]], align 4 -// CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* [[LOGICAL_ADDR]], align 4 -// CHECK-NEXT: [[MUL:%.*]] = mul i32 7, [[TMP3]] -// CHECK-NEXT: [[ADD:%.*]] = add i32 [[TMP2]], [[MUL]] -// CHECK-NEXT: [[TMP4:%.*]] = load i32*, i32** [[LOOPVAR_ADDR]], align 8 -// CHECK-NEXT: store i32 [[ADD]], i32* [[TMP4]], align 4 +// CHECK-NEXT: } + + +// CHECK-LABEL: define {{.*}}@__captured_stmt.1( +// CHECK-NEXT: [[ENTRY:.*]]: +// CHECK-NEXT: %[[LOOPVAR_ADDR:.+]] = alloca i32*, align 8 +// CHECK-NEXT: %[[LOGICAL_ADDR:.+]] = alloca i32, align 4 +// CHECK-NEXT: %[[__CONTEXT_ADDR:.+]] = alloca %struct.anon.0*, align 8 +// CHECK-NEXT: store i32* %[[LOOPVAR:.+]], i32** %[[LOOPVAR_ADDR]], align 8 +// CHECK-NEXT: store i32 %[[LOGICAL:.+]], i32* %[[LOGICAL_ADDR]], align 4 +// CHECK-NEXT: store %struct.anon.0* %[[__CONTEXT:.+]], %struct.anon.0** %[[__CONTEXT_ADDR]], align 8 +// CHECK-NEXT: %[[TMP0:.+]] = load %struct.anon.0*, %struct.anon.0** %[[__CONTEXT_ADDR]], align 8 +// CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[TMP0]], i32 0, i32 0 +// CHECK-NEXT: %[[TMP2:.+]] = load i32, i32* %[[TMP1]], align 4 +// CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[LOGICAL_ADDR]], align 4 +// CHECK-NEXT: %[[MUL:.+]] = mul i32 7, %[[TMP3]] +// CHECK-NEXT: %[[ADD:.+]] = add i32 %[[TMP2]], %[[MUL]] +// CHECK-NEXT: %[[TMP4:.+]] = load i32*, i32** %[[LOOPVAR_ADDR]], align 8 +// CHECK-NEXT: store i32 %[[ADD]], i32* %[[TMP4]], align 4 // CHECK-NEXT: ret void -// +// CHECK-NEXT: } + + +// CHECK: ![[META0:[0-9]+]] = !{i32 1, !"wchar_size", i32 4} +// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 45} +// CHECK: ![[META2:[0-9]+]] = diff --git a/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c b/clang/test/OpenMP/irbuilder_for_unsigned_auto.c copy from clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c copy to clang/test/OpenMP/irbuilder_for_unsigned_auto.c --- a/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c +++ b/clang/test/OpenMP/irbuilder_for_unsigned_auto.c @@ -1,11 +1,11 @@ // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs -// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=51 -x c -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s // expected-no-diagnostics #ifndef HEADER #define HEADER -// CHECK-LABEL: define {{.*}}@unroll_partial_factor_for( +// CHECK-LABEL: define {{.*}}@workshareloop_unsigned_auto( // CHECK-NEXT: [[ENTRY:.*]]: // CHECK-NEXT: %[[A_ADDR:.+]] = alloca float*, align 8 // CHECK-NEXT: %[[B_ADDR:.+]] = alloca float*, align 8 @@ -23,7 +23,7 @@ // CHECK-NEXT: store float* %[[B:.+]], float** %[[B_ADDR]], align 8 // CHECK-NEXT: store float* %[[C:.+]], float** %[[C_ADDR]], align 8 // CHECK-NEXT: store float* %[[D:.+]], float** %[[D_ADDR]], align 8 -// CHECK-NEXT: store i32 0, i32* %[[I]], align 4 +// CHECK-NEXT: store i32 33, i32* %[[I]], align 4 // CHECK-NEXT: %[[TMP0:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[AGG_CAPTURED]], i32 0, i32 0 // CHECK-NEXT: store i32* %[[I]], i32** %[[TMP0]], align 8 // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[AGG_CAPTURED1]], i32 0, i32 0 @@ -34,113 +34,71 @@ // CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_PREHEADER]]: -// CHECK-NEXT: %[[TMP3:.+]] = udiv i32 %[[DOTCOUNT]], 2 -// CHECK-NEXT: %[[TMP4:.+]] = urem i32 %[[DOTCOUNT]], 2 -// CHECK-NEXT: %[[TMP5:.+]] = icmp ne i32 %[[TMP4]], 0 -// CHECK-NEXT: %[[TMP6:.+]] = zext i1 %[[TMP5]] to i32 -// CHECK-NEXT: %[[OMP_FLOOR0_TRIPCOUNT:.+]] = add nuw i32 %[[TMP3]], %[[TMP6]] -// CHECK-NEXT: br label %[[OMP_FLOOR0_PREHEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_PREHEADER]]: -// CHECK-NEXT: store i32 0, i32* %[[P_LOWERBOUND]], align 4 -// CHECK-NEXT: %[[TMP7:.+]] = sub i32 %[[OMP_FLOOR0_TRIPCOUNT]], 1 -// CHECK-NEXT: store i32 %[[TMP7]], i32* %[[P_UPPERBOUND]], align 4 +// CHECK-NEXT: store i32 1, i32* %[[P_LOWERBOUND]], align 4 +// CHECK-NEXT: store i32 %[[DOTCOUNT]], i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: store i32 1, i32* %[[P_STRIDE]], align 4 // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) -// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 1) -// CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 -// CHECK-NEXT: %[[TMP9:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 -// CHECK-NEXT: %[[TMP10:.+]] = sub i32 %[[TMP9]], %[[TMP8]] -// CHECK-NEXT: %[[TMP11:.+]] = add i32 %[[TMP10]], 1 -// CHECK-NEXT: br label %[[OMP_FLOOR0_HEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_HEADER]]: -// CHECK-NEXT: %[[OMP_FLOOR0_IV:.+]] = phi i32 [ 0, %[[OMP_FLOOR0_PREHEADER]] ], [ %[[OMP_FLOOR0_NEXT:.+]], %[[OMP_FLOOR0_INC:.+]] ] -// CHECK-NEXT: br label %[[OMP_FLOOR0_COND:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_COND]]: -// CHECK-NEXT: %[[OMP_FLOOR0_CMP:.+]] = icmp ult i32 %[[OMP_FLOOR0_IV]], %[[TMP11]] -// CHECK-NEXT: br i1 %[[OMP_FLOOR0_CMP]], label %[[OMP_FLOOR0_BODY:.+]], label %[[OMP_FLOOR0_EXIT:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_BODY]]: -// CHECK-NEXT: %[[TMP12:.+]] = add i32 %[[OMP_FLOOR0_IV]], %[[TMP8]] -// CHECK-NEXT: %[[TMP13:.+]] = icmp eq i32 %[[TMP12]], %[[OMP_FLOOR0_TRIPCOUNT]] -// CHECK-NEXT: %[[TMP14:.+]] = select i1 %[[TMP13]], i32 %[[TMP4]], i32 2 -// CHECK-NEXT: br label %[[OMP_TILE0_PREHEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_PREHEADER]]: -// CHECK-NEXT: br label %[[OMP_TILE0_HEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_HEADER]]: -// CHECK-NEXT: %[[OMP_TILE0_IV:.+]] = phi i32 [ 0, %[[OMP_TILE0_PREHEADER]] ], [ %[[OMP_TILE0_NEXT:.+]], %[[OMP_TILE0_INC:.+]] ] -// CHECK-NEXT: br label %[[OMP_TILE0_COND:.+]] +// CHECK-NEXT: call void @__kmpc_dispatch_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 38, i32 1, i32 %[[DOTCOUNT]], i32 1, i32 1) +// CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER_OUTER_COND:.+]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_COND]]: -// CHECK-NEXT: %[[OMP_TILE0_CMP:.+]] = icmp ult i32 %[[OMP_TILE0_IV]], %[[TMP14]] -// CHECK-NEXT: br i1 %[[OMP_TILE0_CMP]], label %[[OMP_TILE0_BODY:.+]], label %[[OMP_TILE0_EXIT:.+]] +// CHECK-NEXT: [[OMP_LOOP_HEADER:.*]]: +// CHECK-NEXT: %[[OMP_LOOP_IV:.+]] = phi i32 [ %[[LB:.+]], %[[OMP_LOOP_PREHEADER_OUTER_COND]] ], [ %[[OMP_LOOP_NEXT:.+]], %[[OMP_LOOP_INC:.+]] ] +// CHECK-NEXT: br label %[[OMP_LOOP_COND:.+]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_BODY]]: -// CHECK-NEXT: %[[TMP15:.+]] = mul nuw i32 2, %[[TMP12]] -// CHECK-NEXT: %[[TMP16:.+]] = add nuw i32 %[[TMP15]], %[[OMP_TILE0_IV]] -// CHECK-NEXT: br label %[[OMP_LOOP_BODY:.+]] +// CHECK-NEXT: [[OMP_LOOP_COND]]: +// CHECK-NEXT: %[[UB:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 +// CHECK-NEXT: %[[OMP_LOOP_CMP:.+]] = icmp ult i32 %[[OMP_LOOP_IV]], %[[UB]] +// CHECK-NEXT: br i1 %[[OMP_LOOP_CMP]], label %[[OMP_LOOP_BODY:.+]], label %[[OMP_LOOP_PREHEADER_OUTER_COND]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_BODY]]: -// CHECK-NEXT: call void @__captured_stmt.1(i32* %[[I]], i32 %[[TMP16]], %struct.anon.0* %[[AGG_CAPTURED1]]) -// CHECK-NEXT: %[[TMP17:.+]] = load float*, float** %[[B_ADDR]], align 8 -// CHECK-NEXT: %[[TMP18:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM:.+]] = sext i32 %[[TMP18]] to i64 -// CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP17]], i64 %[[IDXPROM]] -// CHECK-NEXT: %[[TMP19:.+]] = load float, float* %[[ARRAYIDX]], align 4 -// CHECK-NEXT: %[[TMP20:.+]] = load float*, float** %[[C_ADDR]], align 8 -// CHECK-NEXT: %[[TMP21:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM2:.+]] = sext i32 %[[TMP21]] to i64 -// CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP20]], i64 %[[IDXPROM2]] -// CHECK-NEXT: %[[TMP22:.+]] = load float, float* %[[ARRAYIDX3]], align 4 -// CHECK-NEXT: %[[MUL:.+]] = fmul float %[[TMP19]], %[[TMP22]] -// CHECK-NEXT: %[[TMP23:.+]] = load float*, float** %[[D_ADDR]], align 8 -// CHECK-NEXT: %[[TMP24:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM4:.+]] = sext i32 %[[TMP24]] to i64 -// CHECK-NEXT: %[[ARRAYIDX5:.+]] = getelementptr inbounds float, float* %[[TMP23]], i64 %[[IDXPROM4]] -// CHECK-NEXT: %[[TMP25:.+]] = load float, float* %[[ARRAYIDX5]], align 4 -// CHECK-NEXT: %[[MUL6:.+]] = fmul float %[[MUL]], %[[TMP25]] -// CHECK-NEXT: %[[TMP26:.+]] = load float*, float** %[[A_ADDR]], align 8 -// CHECK-NEXT: %[[TMP27:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM7:.+]] = sext i32 %[[TMP27]] to i64 -// CHECK-NEXT: %[[ARRAYIDX8:.+]] = getelementptr inbounds float, float* %[[TMP26]], i64 %[[IDXPROM7]] +// CHECK-NEXT: call void @__captured_stmt.1(i32* %[[I]], i32 %[[OMP_LOOP_IV]], %struct.anon.0* %[[AGG_CAPTURED1]]) +// CHECK-NEXT: %[[TMP3:.+]] = load float*, float** %[[B_ADDR]], align 8 +// CHECK-NEXT: %[[TMP4:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM:.+]] = zext i32 %[[TMP4]] to i64 +// CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP3]], i64 %[[IDXPROM]] +// CHECK-NEXT: %[[TMP5:.+]] = load float, float* %[[ARRAYIDX]], align 4 +// CHECK-NEXT: %[[TMP6:.+]] = load float*, float** %[[C_ADDR]], align 8 +// CHECK-NEXT: %[[TMP7:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM2:.+]] = zext i32 %[[TMP7]] to i64 +// CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP6]], i64 %[[IDXPROM2]] +// CHECK-NEXT: %[[TMP8:.+]] = load float, float* %[[ARRAYIDX3]], align 4 +// CHECK-NEXT: %[[MUL:.+]] = fmul float %[[TMP5]], %[[TMP8]] +// CHECK-NEXT: %[[TMP9:.+]] = load float*, float** %[[D_ADDR]], align 8 +// CHECK-NEXT: %[[TMP10:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM4:.+]] = zext i32 %[[TMP10]] to i64 +// CHECK-NEXT: %[[ARRAYIDX5:.+]] = getelementptr inbounds float, float* %[[TMP9]], i64 %[[IDXPROM4]] +// CHECK-NEXT: %[[TMP11:.+]] = load float, float* %[[ARRAYIDX5]], align 4 +// CHECK-NEXT: %[[MUL6:.+]] = fmul float %[[MUL]], %[[TMP11]] +// CHECK-NEXT: %[[TMP12:.+]] = load float*, float** %[[A_ADDR]], align 8 +// CHECK-NEXT: %[[TMP13:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM7:.+]] = zext i32 %[[TMP13]] to i64 +// CHECK-NEXT: %[[ARRAYIDX8:.+]] = getelementptr inbounds float, float* %[[TMP12]], i64 %[[IDXPROM7]] // CHECK-NEXT: store float %[[MUL6]], float* %[[ARRAYIDX8]], align 4 -// CHECK-NEXT: br label %[[OMP_TILE0_INC]] +// CHECK-NEXT: br label %[[OMP_LOOP_INC]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_INC]]: -// CHECK-NEXT: %[[OMP_TILE0_NEXT]] = add nuw i32 %[[OMP_TILE0_IV]], 1 -// CHECK-NEXT: br label %[[OMP_TILE0_HEADER]], !llvm.loop ![[LOOP3:[0-9]+]] +// CHECK-NEXT: [[OMP_LOOP_INC]]: +// CHECK-NEXT: %[[OMP_LOOP_NEXT]] = add nuw i32 %[[OMP_LOOP_IV]], 1 +// CHECK-NEXT: br label %[[OMP_LOOP_HEADER]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_EXIT]]: -// CHECK-NEXT: br label %[[OMP_TILE0_AFTER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_AFTER]]: -// CHECK-NEXT: br label %[[OMP_FLOOR0_INC]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_INC]]: -// CHECK-NEXT: %[[OMP_FLOOR0_NEXT]] = add nuw i32 %[[OMP_FLOOR0_IV]], 1 -// CHECK-NEXT: br label %[[OMP_FLOOR0_HEADER]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_EXIT]]: -// CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]]) +// CHECK-NEXT: [[OMP_LOOP_EXIT:.*]]: // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM9:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) // CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @2, i32 %[[OMP_GLOBAL_THREAD_NUM9]]) -// CHECK-NEXT: br label %[[OMP_FLOOR0_AFTER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_AFTER]]: // CHECK-NEXT: br label %[[OMP_LOOP_AFTER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_AFTER]]: // CHECK-NEXT: ret void +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_PREHEADER_OUTER_COND]]: +// CHECK-NEXT: %[[TMP14:.+]] = call i32 @__kmpc_dispatch_next_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]]) +// CHECK-NEXT: %[[TMP15:.+]] = icmp ne i32 %[[TMP14]], 0 +// CHECK-NEXT: %[[TMP16:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 +// CHECK-NEXT: %[[LB]] = sub i32 %[[TMP16]], 1 +// CHECK-NEXT: br i1 %[[TMP15]], label %[[OMP_LOOP_HEADER]], label %[[OMP_LOOP_EXIT]] // CHECK-NEXT: } -void unroll_partial_factor_for(float *a, float *b, float *c, float *d) { -#pragma omp for -#pragma omp unroll partial(2) - for (int i = 0; i < 2; i++) { +extern "C" void workshareloop_unsigned_auto(float *a, float *b, float *c, float *d) { +#pragma omp for schedule(auto) + for (unsigned i = 33; i < 32000000; i += 7) { a[i] = b[i] * c[i] * d[i]; } } @@ -161,17 +119,17 @@ // CHECK-NEXT: %[[TMP2:.+]] = load i32*, i32** %[[TMP1]], align 8 // CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[TMP2]], align 4 // CHECK-NEXT: store i32 %[[TMP3]], i32* %[[DOTSTART]], align 4 -// CHECK-NEXT: store i32 2, i32* %[[DOTSTOP]], align 4 -// CHECK-NEXT: store i32 1, i32* %[[DOTSTEP]], align 4 +// CHECK-NEXT: store i32 32000000, i32* %[[DOTSTOP]], align 4 +// CHECK-NEXT: store i32 7, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[TMP4:.+]] = load i32, i32* %[[DOTSTART]], align 4 // CHECK-NEXT: %[[TMP5:.+]] = load i32, i32* %[[DOTSTOP]], align 4 -// CHECK-NEXT: %[[CMP:.+]] = icmp slt i32 %[[TMP4]], %[[TMP5]] +// CHECK-NEXT: %[[CMP:.+]] = icmp ult i32 %[[TMP4]], %[[TMP5]] // CHECK-NEXT: br i1 %[[CMP]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[COND_TRUE]]: // CHECK-NEXT: %[[TMP6:.+]] = load i32, i32* %[[DOTSTOP]], align 4 // CHECK-NEXT: %[[TMP7:.+]] = load i32, i32* %[[DOTSTART]], align 4 -// CHECK-NEXT: %[[SUB:.+]] = sub nsw i32 %[[TMP6]], %[[TMP7]] +// CHECK-NEXT: %[[SUB:.+]] = sub i32 %[[TMP6]], %[[TMP7]] // CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[DIV:.+]] = udiv i32 %[[SUB]], %[[TMP8]] // CHECK-NEXT: br label %[[COND_END:.+]] @@ -199,7 +157,7 @@ // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[TMP0]], i32 0, i32 0 // CHECK-NEXT: %[[TMP2:.+]] = load i32, i32* %[[TMP1]], align 4 // CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[LOGICAL_ADDR]], align 4 -// CHECK-NEXT: %[[MUL:.+]] = mul i32 1, %[[TMP3]] +// CHECK-NEXT: %[[MUL:.+]] = mul i32 7, %[[TMP3]] // CHECK-NEXT: %[[ADD:.+]] = add i32 %[[TMP2]], %[[MUL]] // CHECK-NEXT: %[[TMP4:.+]] = load i32*, i32** %[[LOOPVAR_ADDR]], align 8 // CHECK-NEXT: store i32 %[[ADD]], i32* %[[TMP4]], align 4 @@ -208,8 +166,5 @@ // CHECK: ![[META0:[0-9]+]] = !{i32 1, !"wchar_size", i32 4} -// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 51} +// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 45} // CHECK: ![[META2:[0-9]+]] = -// CHECK: ![[LOOP3]] = distinct !{![[LOOP3]], ![[LOOPPROP4:[0-9]+]], ![[LOOPPROP5:[0-9]+]]} -// CHECK: ![[LOOPPROP4]] = !{!"llvm.loop.unroll.enable"} -// CHECK: ![[LOOPPROP5]] = !{!"llvm.loop.unroll.count", i32 2} diff --git a/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c b/clang/test/OpenMP/irbuilder_for_unsigned_dynamic.c copy from clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c copy to clang/test/OpenMP/irbuilder_for_unsigned_dynamic.c --- a/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c +++ b/clang/test/OpenMP/irbuilder_for_unsigned_dynamic.c @@ -1,11 +1,11 @@ // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs -// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=51 -x c -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s // expected-no-diagnostics #ifndef HEADER #define HEADER -// CHECK-LABEL: define {{.*}}@unroll_partial_factor_for( +// CHECK-LABEL: define {{.*}}@workshareloop_unsigned_dynamic( // CHECK-NEXT: [[ENTRY:.*]]: // CHECK-NEXT: %[[A_ADDR:.+]] = alloca float*, align 8 // CHECK-NEXT: %[[B_ADDR:.+]] = alloca float*, align 8 @@ -23,7 +23,7 @@ // CHECK-NEXT: store float* %[[B:.+]], float** %[[B_ADDR]], align 8 // CHECK-NEXT: store float* %[[C:.+]], float** %[[C_ADDR]], align 8 // CHECK-NEXT: store float* %[[D:.+]], float** %[[D_ADDR]], align 8 -// CHECK-NEXT: store i32 0, i32* %[[I]], align 4 +// CHECK-NEXT: store i32 33, i32* %[[I]], align 4 // CHECK-NEXT: %[[TMP0:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[AGG_CAPTURED]], i32 0, i32 0 // CHECK-NEXT: store i32* %[[I]], i32** %[[TMP0]], align 8 // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[AGG_CAPTURED1]], i32 0, i32 0 @@ -34,113 +34,71 @@ // CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_PREHEADER]]: -// CHECK-NEXT: %[[TMP3:.+]] = udiv i32 %[[DOTCOUNT]], 2 -// CHECK-NEXT: %[[TMP4:.+]] = urem i32 %[[DOTCOUNT]], 2 -// CHECK-NEXT: %[[TMP5:.+]] = icmp ne i32 %[[TMP4]], 0 -// CHECK-NEXT: %[[TMP6:.+]] = zext i1 %[[TMP5]] to i32 -// CHECK-NEXT: %[[OMP_FLOOR0_TRIPCOUNT:.+]] = add nuw i32 %[[TMP3]], %[[TMP6]] -// CHECK-NEXT: br label %[[OMP_FLOOR0_PREHEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_PREHEADER]]: -// CHECK-NEXT: store i32 0, i32* %[[P_LOWERBOUND]], align 4 -// CHECK-NEXT: %[[TMP7:.+]] = sub i32 %[[OMP_FLOOR0_TRIPCOUNT]], 1 -// CHECK-NEXT: store i32 %[[TMP7]], i32* %[[P_UPPERBOUND]], align 4 +// CHECK-NEXT: store i32 1, i32* %[[P_LOWERBOUND]], align 4 +// CHECK-NEXT: store i32 %[[DOTCOUNT]], i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: store i32 1, i32* %[[P_STRIDE]], align 4 // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) -// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 1) -// CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 -// CHECK-NEXT: %[[TMP9:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 -// CHECK-NEXT: %[[TMP10:.+]] = sub i32 %[[TMP9]], %[[TMP8]] -// CHECK-NEXT: %[[TMP11:.+]] = add i32 %[[TMP10]], 1 -// CHECK-NEXT: br label %[[OMP_FLOOR0_HEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_HEADER]]: -// CHECK-NEXT: %[[OMP_FLOOR0_IV:.+]] = phi i32 [ 0, %[[OMP_FLOOR0_PREHEADER]] ], [ %[[OMP_FLOOR0_NEXT:.+]], %[[OMP_FLOOR0_INC:.+]] ] -// CHECK-NEXT: br label %[[OMP_FLOOR0_COND:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_COND]]: -// CHECK-NEXT: %[[OMP_FLOOR0_CMP:.+]] = icmp ult i32 %[[OMP_FLOOR0_IV]], %[[TMP11]] -// CHECK-NEXT: br i1 %[[OMP_FLOOR0_CMP]], label %[[OMP_FLOOR0_BODY:.+]], label %[[OMP_FLOOR0_EXIT:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_BODY]]: -// CHECK-NEXT: %[[TMP12:.+]] = add i32 %[[OMP_FLOOR0_IV]], %[[TMP8]] -// CHECK-NEXT: %[[TMP13:.+]] = icmp eq i32 %[[TMP12]], %[[OMP_FLOOR0_TRIPCOUNT]] -// CHECK-NEXT: %[[TMP14:.+]] = select i1 %[[TMP13]], i32 %[[TMP4]], i32 2 -// CHECK-NEXT: br label %[[OMP_TILE0_PREHEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_PREHEADER]]: -// CHECK-NEXT: br label %[[OMP_TILE0_HEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_HEADER]]: -// CHECK-NEXT: %[[OMP_TILE0_IV:.+]] = phi i32 [ 0, %[[OMP_TILE0_PREHEADER]] ], [ %[[OMP_TILE0_NEXT:.+]], %[[OMP_TILE0_INC:.+]] ] -// CHECK-NEXT: br label %[[OMP_TILE0_COND:.+]] +// CHECK-NEXT: call void @__kmpc_dispatch_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 35, i32 1, i32 %[[DOTCOUNT]], i32 1, i32 1) +// CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER_OUTER_COND:.+]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_COND]]: -// CHECK-NEXT: %[[OMP_TILE0_CMP:.+]] = icmp ult i32 %[[OMP_TILE0_IV]], %[[TMP14]] -// CHECK-NEXT: br i1 %[[OMP_TILE0_CMP]], label %[[OMP_TILE0_BODY:.+]], label %[[OMP_TILE0_EXIT:.+]] +// CHECK-NEXT: [[OMP_LOOP_HEADER:.*]]: +// CHECK-NEXT: %[[OMP_LOOP_IV:.+]] = phi i32 [ %[[LB:.+]], %[[OMP_LOOP_PREHEADER_OUTER_COND]] ], [ %[[OMP_LOOP_NEXT:.+]], %[[OMP_LOOP_INC:.+]] ] +// CHECK-NEXT: br label %[[OMP_LOOP_COND:.+]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_BODY]]: -// CHECK-NEXT: %[[TMP15:.+]] = mul nuw i32 2, %[[TMP12]] -// CHECK-NEXT: %[[TMP16:.+]] = add nuw i32 %[[TMP15]], %[[OMP_TILE0_IV]] -// CHECK-NEXT: br label %[[OMP_LOOP_BODY:.+]] +// CHECK-NEXT: [[OMP_LOOP_COND]]: +// CHECK-NEXT: %[[UB:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 +// CHECK-NEXT: %[[OMP_LOOP_CMP:.+]] = icmp ult i32 %[[OMP_LOOP_IV]], %[[UB]] +// CHECK-NEXT: br i1 %[[OMP_LOOP_CMP]], label %[[OMP_LOOP_BODY:.+]], label %[[OMP_LOOP_PREHEADER_OUTER_COND]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_BODY]]: -// CHECK-NEXT: call void @__captured_stmt.1(i32* %[[I]], i32 %[[TMP16]], %struct.anon.0* %[[AGG_CAPTURED1]]) -// CHECK-NEXT: %[[TMP17:.+]] = load float*, float** %[[B_ADDR]], align 8 -// CHECK-NEXT: %[[TMP18:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM:.+]] = sext i32 %[[TMP18]] to i64 -// CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP17]], i64 %[[IDXPROM]] -// CHECK-NEXT: %[[TMP19:.+]] = load float, float* %[[ARRAYIDX]], align 4 -// CHECK-NEXT: %[[TMP20:.+]] = load float*, float** %[[C_ADDR]], align 8 -// CHECK-NEXT: %[[TMP21:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM2:.+]] = sext i32 %[[TMP21]] to i64 -// CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP20]], i64 %[[IDXPROM2]] -// CHECK-NEXT: %[[TMP22:.+]] = load float, float* %[[ARRAYIDX3]], align 4 -// CHECK-NEXT: %[[MUL:.+]] = fmul float %[[TMP19]], %[[TMP22]] -// CHECK-NEXT: %[[TMP23:.+]] = load float*, float** %[[D_ADDR]], align 8 -// CHECK-NEXT: %[[TMP24:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM4:.+]] = sext i32 %[[TMP24]] to i64 -// CHECK-NEXT: %[[ARRAYIDX5:.+]] = getelementptr inbounds float, float* %[[TMP23]], i64 %[[IDXPROM4]] -// CHECK-NEXT: %[[TMP25:.+]] = load float, float* %[[ARRAYIDX5]], align 4 -// CHECK-NEXT: %[[MUL6:.+]] = fmul float %[[MUL]], %[[TMP25]] -// CHECK-NEXT: %[[TMP26:.+]] = load float*, float** %[[A_ADDR]], align 8 -// CHECK-NEXT: %[[TMP27:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM7:.+]] = sext i32 %[[TMP27]] to i64 -// CHECK-NEXT: %[[ARRAYIDX8:.+]] = getelementptr inbounds float, float* %[[TMP26]], i64 %[[IDXPROM7]] +// CHECK-NEXT: call void @__captured_stmt.1(i32* %[[I]], i32 %[[OMP_LOOP_IV]], %struct.anon.0* %[[AGG_CAPTURED1]]) +// CHECK-NEXT: %[[TMP3:.+]] = load float*, float** %[[B_ADDR]], align 8 +// CHECK-NEXT: %[[TMP4:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM:.+]] = zext i32 %[[TMP4]] to i64 +// CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP3]], i64 %[[IDXPROM]] +// CHECK-NEXT: %[[TMP5:.+]] = load float, float* %[[ARRAYIDX]], align 4 +// CHECK-NEXT: %[[TMP6:.+]] = load float*, float** %[[C_ADDR]], align 8 +// CHECK-NEXT: %[[TMP7:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM2:.+]] = zext i32 %[[TMP7]] to i64 +// CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP6]], i64 %[[IDXPROM2]] +// CHECK-NEXT: %[[TMP8:.+]] = load float, float* %[[ARRAYIDX3]], align 4 +// CHECK-NEXT: %[[MUL:.+]] = fmul float %[[TMP5]], %[[TMP8]] +// CHECK-NEXT: %[[TMP9:.+]] = load float*, float** %[[D_ADDR]], align 8 +// CHECK-NEXT: %[[TMP10:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM4:.+]] = zext i32 %[[TMP10]] to i64 +// CHECK-NEXT: %[[ARRAYIDX5:.+]] = getelementptr inbounds float, float* %[[TMP9]], i64 %[[IDXPROM4]] +// CHECK-NEXT: %[[TMP11:.+]] = load float, float* %[[ARRAYIDX5]], align 4 +// CHECK-NEXT: %[[MUL6:.+]] = fmul float %[[MUL]], %[[TMP11]] +// CHECK-NEXT: %[[TMP12:.+]] = load float*, float** %[[A_ADDR]], align 8 +// CHECK-NEXT: %[[TMP13:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM7:.+]] = zext i32 %[[TMP13]] to i64 +// CHECK-NEXT: %[[ARRAYIDX8:.+]] = getelementptr inbounds float, float* %[[TMP12]], i64 %[[IDXPROM7]] // CHECK-NEXT: store float %[[MUL6]], float* %[[ARRAYIDX8]], align 4 -// CHECK-NEXT: br label %[[OMP_TILE0_INC]] +// CHECK-NEXT: br label %[[OMP_LOOP_INC]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_INC]]: -// CHECK-NEXT: %[[OMP_TILE0_NEXT]] = add nuw i32 %[[OMP_TILE0_IV]], 1 -// CHECK-NEXT: br label %[[OMP_TILE0_HEADER]], !llvm.loop ![[LOOP3:[0-9]+]] +// CHECK-NEXT: [[OMP_LOOP_INC]]: +// CHECK-NEXT: %[[OMP_LOOP_NEXT]] = add nuw i32 %[[OMP_LOOP_IV]], 1 +// CHECK-NEXT: br label %[[OMP_LOOP_HEADER]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_EXIT]]: -// CHECK-NEXT: br label %[[OMP_TILE0_AFTER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_AFTER]]: -// CHECK-NEXT: br label %[[OMP_FLOOR0_INC]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_INC]]: -// CHECK-NEXT: %[[OMP_FLOOR0_NEXT]] = add nuw i32 %[[OMP_FLOOR0_IV]], 1 -// CHECK-NEXT: br label %[[OMP_FLOOR0_HEADER]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_EXIT]]: -// CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]]) +// CHECK-NEXT: [[OMP_LOOP_EXIT:.*]]: // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM9:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) // CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @2, i32 %[[OMP_GLOBAL_THREAD_NUM9]]) -// CHECK-NEXT: br label %[[OMP_FLOOR0_AFTER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_AFTER]]: // CHECK-NEXT: br label %[[OMP_LOOP_AFTER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_AFTER]]: // CHECK-NEXT: ret void +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_PREHEADER_OUTER_COND]]: +// CHECK-NEXT: %[[TMP14:.+]] = call i32 @__kmpc_dispatch_next_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]]) +// CHECK-NEXT: %[[TMP15:.+]] = icmp ne i32 %[[TMP14]], 0 +// CHECK-NEXT: %[[TMP16:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 +// CHECK-NEXT: %[[LB]] = sub i32 %[[TMP16]], 1 +// CHECK-NEXT: br i1 %[[TMP15]], label %[[OMP_LOOP_HEADER]], label %[[OMP_LOOP_EXIT]] // CHECK-NEXT: } -void unroll_partial_factor_for(float *a, float *b, float *c, float *d) { -#pragma omp for -#pragma omp unroll partial(2) - for (int i = 0; i < 2; i++) { +extern "C" void workshareloop_unsigned_dynamic(float *a, float *b, float *c, float *d) { +#pragma omp for schedule(dynamic) + for (unsigned i = 33; i < 32000000; i += 7) { a[i] = b[i] * c[i] * d[i]; } } @@ -161,17 +119,17 @@ // CHECK-NEXT: %[[TMP2:.+]] = load i32*, i32** %[[TMP1]], align 8 // CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[TMP2]], align 4 // CHECK-NEXT: store i32 %[[TMP3]], i32* %[[DOTSTART]], align 4 -// CHECK-NEXT: store i32 2, i32* %[[DOTSTOP]], align 4 -// CHECK-NEXT: store i32 1, i32* %[[DOTSTEP]], align 4 +// CHECK-NEXT: store i32 32000000, i32* %[[DOTSTOP]], align 4 +// CHECK-NEXT: store i32 7, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[TMP4:.+]] = load i32, i32* %[[DOTSTART]], align 4 // CHECK-NEXT: %[[TMP5:.+]] = load i32, i32* %[[DOTSTOP]], align 4 -// CHECK-NEXT: %[[CMP:.+]] = icmp slt i32 %[[TMP4]], %[[TMP5]] +// CHECK-NEXT: %[[CMP:.+]] = icmp ult i32 %[[TMP4]], %[[TMP5]] // CHECK-NEXT: br i1 %[[CMP]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[COND_TRUE]]: // CHECK-NEXT: %[[TMP6:.+]] = load i32, i32* %[[DOTSTOP]], align 4 // CHECK-NEXT: %[[TMP7:.+]] = load i32, i32* %[[DOTSTART]], align 4 -// CHECK-NEXT: %[[SUB:.+]] = sub nsw i32 %[[TMP6]], %[[TMP7]] +// CHECK-NEXT: %[[SUB:.+]] = sub i32 %[[TMP6]], %[[TMP7]] // CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[DIV:.+]] = udiv i32 %[[SUB]], %[[TMP8]] // CHECK-NEXT: br label %[[COND_END:.+]] @@ -199,7 +157,7 @@ // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[TMP0]], i32 0, i32 0 // CHECK-NEXT: %[[TMP2:.+]] = load i32, i32* %[[TMP1]], align 4 // CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[LOGICAL_ADDR]], align 4 -// CHECK-NEXT: %[[MUL:.+]] = mul i32 1, %[[TMP3]] +// CHECK-NEXT: %[[MUL:.+]] = mul i32 7, %[[TMP3]] // CHECK-NEXT: %[[ADD:.+]] = add i32 %[[TMP2]], %[[MUL]] // CHECK-NEXT: %[[TMP4:.+]] = load i32*, i32** %[[LOOPVAR_ADDR]], align 8 // CHECK-NEXT: store i32 %[[ADD]], i32* %[[TMP4]], align 4 @@ -208,8 +166,5 @@ // CHECK: ![[META0:[0-9]+]] = !{i32 1, !"wchar_size", i32 4} -// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 51} +// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 45} // CHECK: ![[META2:[0-9]+]] = -// CHECK: ![[LOOP3]] = distinct !{![[LOOP3]], ![[LOOPPROP4:[0-9]+]], ![[LOOPPROP5:[0-9]+]]} -// CHECK: ![[LOOPPROP4]] = !{!"llvm.loop.unroll.enable"} -// CHECK: ![[LOOPPROP5]] = !{!"llvm.loop.unroll.count", i32 2} diff --git a/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c b/clang/test/OpenMP/irbuilder_for_unsigned_dynamic_chunked.c copy from clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c copy to clang/test/OpenMP/irbuilder_for_unsigned_dynamic_chunked.c --- a/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c +++ b/clang/test/OpenMP/irbuilder_for_unsigned_dynamic_chunked.c @@ -1,11 +1,11 @@ // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs -// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=51 -x c -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s // expected-no-diagnostics #ifndef HEADER #define HEADER -// CHECK-LABEL: define {{.*}}@unroll_partial_factor_for( +// CHECK-LABEL: define {{.*}}@workshareloop_unsigned_dynamic_chunked( // CHECK-NEXT: [[ENTRY:.*]]: // CHECK-NEXT: %[[A_ADDR:.+]] = alloca float*, align 8 // CHECK-NEXT: %[[B_ADDR:.+]] = alloca float*, align 8 @@ -23,7 +23,7 @@ // CHECK-NEXT: store float* %[[B:.+]], float** %[[B_ADDR]], align 8 // CHECK-NEXT: store float* %[[C:.+]], float** %[[C_ADDR]], align 8 // CHECK-NEXT: store float* %[[D:.+]], float** %[[D_ADDR]], align 8 -// CHECK-NEXT: store i32 0, i32* %[[I]], align 4 +// CHECK-NEXT: store i32 33, i32* %[[I]], align 4 // CHECK-NEXT: %[[TMP0:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[AGG_CAPTURED]], i32 0, i32 0 // CHECK-NEXT: store i32* %[[I]], i32** %[[TMP0]], align 8 // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[AGG_CAPTURED1]], i32 0, i32 0 @@ -34,113 +34,71 @@ // CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_PREHEADER]]: -// CHECK-NEXT: %[[TMP3:.+]] = udiv i32 %[[DOTCOUNT]], 2 -// CHECK-NEXT: %[[TMP4:.+]] = urem i32 %[[DOTCOUNT]], 2 -// CHECK-NEXT: %[[TMP5:.+]] = icmp ne i32 %[[TMP4]], 0 -// CHECK-NEXT: %[[TMP6:.+]] = zext i1 %[[TMP5]] to i32 -// CHECK-NEXT: %[[OMP_FLOOR0_TRIPCOUNT:.+]] = add nuw i32 %[[TMP3]], %[[TMP6]] -// CHECK-NEXT: br label %[[OMP_FLOOR0_PREHEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_PREHEADER]]: -// CHECK-NEXT: store i32 0, i32* %[[P_LOWERBOUND]], align 4 -// CHECK-NEXT: %[[TMP7:.+]] = sub i32 %[[OMP_FLOOR0_TRIPCOUNT]], 1 -// CHECK-NEXT: store i32 %[[TMP7]], i32* %[[P_UPPERBOUND]], align 4 +// CHECK-NEXT: store i32 1, i32* %[[P_LOWERBOUND]], align 4 +// CHECK-NEXT: store i32 %[[DOTCOUNT]], i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: store i32 1, i32* %[[P_STRIDE]], align 4 // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) -// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 1) -// CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 -// CHECK-NEXT: %[[TMP9:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 -// CHECK-NEXT: %[[TMP10:.+]] = sub i32 %[[TMP9]], %[[TMP8]] -// CHECK-NEXT: %[[TMP11:.+]] = add i32 %[[TMP10]], 1 -// CHECK-NEXT: br label %[[OMP_FLOOR0_HEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_HEADER]]: -// CHECK-NEXT: %[[OMP_FLOOR0_IV:.+]] = phi i32 [ 0, %[[OMP_FLOOR0_PREHEADER]] ], [ %[[OMP_FLOOR0_NEXT:.+]], %[[OMP_FLOOR0_INC:.+]] ] -// CHECK-NEXT: br label %[[OMP_FLOOR0_COND:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_COND]]: -// CHECK-NEXT: %[[OMP_FLOOR0_CMP:.+]] = icmp ult i32 %[[OMP_FLOOR0_IV]], %[[TMP11]] -// CHECK-NEXT: br i1 %[[OMP_FLOOR0_CMP]], label %[[OMP_FLOOR0_BODY:.+]], label %[[OMP_FLOOR0_EXIT:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_BODY]]: -// CHECK-NEXT: %[[TMP12:.+]] = add i32 %[[OMP_FLOOR0_IV]], %[[TMP8]] -// CHECK-NEXT: %[[TMP13:.+]] = icmp eq i32 %[[TMP12]], %[[OMP_FLOOR0_TRIPCOUNT]] -// CHECK-NEXT: %[[TMP14:.+]] = select i1 %[[TMP13]], i32 %[[TMP4]], i32 2 -// CHECK-NEXT: br label %[[OMP_TILE0_PREHEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_PREHEADER]]: -// CHECK-NEXT: br label %[[OMP_TILE0_HEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_HEADER]]: -// CHECK-NEXT: %[[OMP_TILE0_IV:.+]] = phi i32 [ 0, %[[OMP_TILE0_PREHEADER]] ], [ %[[OMP_TILE0_NEXT:.+]], %[[OMP_TILE0_INC:.+]] ] -// CHECK-NEXT: br label %[[OMP_TILE0_COND:.+]] +// CHECK-NEXT: call void @__kmpc_dispatch_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 35, i32 1, i32 %[[DOTCOUNT]], i32 1, i32 5) +// CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER_OUTER_COND:.+]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_COND]]: -// CHECK-NEXT: %[[OMP_TILE0_CMP:.+]] = icmp ult i32 %[[OMP_TILE0_IV]], %[[TMP14]] -// CHECK-NEXT: br i1 %[[OMP_TILE0_CMP]], label %[[OMP_TILE0_BODY:.+]], label %[[OMP_TILE0_EXIT:.+]] +// CHECK-NEXT: [[OMP_LOOP_HEADER:.*]]: +// CHECK-NEXT: %[[OMP_LOOP_IV:.+]] = phi i32 [ %[[LB:.+]], %[[OMP_LOOP_PREHEADER_OUTER_COND]] ], [ %[[OMP_LOOP_NEXT:.+]], %[[OMP_LOOP_INC:.+]] ] +// CHECK-NEXT: br label %[[OMP_LOOP_COND:.+]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_BODY]]: -// CHECK-NEXT: %[[TMP15:.+]] = mul nuw i32 2, %[[TMP12]] -// CHECK-NEXT: %[[TMP16:.+]] = add nuw i32 %[[TMP15]], %[[OMP_TILE0_IV]] -// CHECK-NEXT: br label %[[OMP_LOOP_BODY:.+]] +// CHECK-NEXT: [[OMP_LOOP_COND]]: +// CHECK-NEXT: %[[UB:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 +// CHECK-NEXT: %[[OMP_LOOP_CMP:.+]] = icmp ult i32 %[[OMP_LOOP_IV]], %[[UB]] +// CHECK-NEXT: br i1 %[[OMP_LOOP_CMP]], label %[[OMP_LOOP_BODY:.+]], label %[[OMP_LOOP_PREHEADER_OUTER_COND]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_BODY]]: -// CHECK-NEXT: call void @__captured_stmt.1(i32* %[[I]], i32 %[[TMP16]], %struct.anon.0* %[[AGG_CAPTURED1]]) -// CHECK-NEXT: %[[TMP17:.+]] = load float*, float** %[[B_ADDR]], align 8 -// CHECK-NEXT: %[[TMP18:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM:.+]] = sext i32 %[[TMP18]] to i64 -// CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP17]], i64 %[[IDXPROM]] -// CHECK-NEXT: %[[TMP19:.+]] = load float, float* %[[ARRAYIDX]], align 4 -// CHECK-NEXT: %[[TMP20:.+]] = load float*, float** %[[C_ADDR]], align 8 -// CHECK-NEXT: %[[TMP21:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM2:.+]] = sext i32 %[[TMP21]] to i64 -// CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP20]], i64 %[[IDXPROM2]] -// CHECK-NEXT: %[[TMP22:.+]] = load float, float* %[[ARRAYIDX3]], align 4 -// CHECK-NEXT: %[[MUL:.+]] = fmul float %[[TMP19]], %[[TMP22]] -// CHECK-NEXT: %[[TMP23:.+]] = load float*, float** %[[D_ADDR]], align 8 -// CHECK-NEXT: %[[TMP24:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM4:.+]] = sext i32 %[[TMP24]] to i64 -// CHECK-NEXT: %[[ARRAYIDX5:.+]] = getelementptr inbounds float, float* %[[TMP23]], i64 %[[IDXPROM4]] -// CHECK-NEXT: %[[TMP25:.+]] = load float, float* %[[ARRAYIDX5]], align 4 -// CHECK-NEXT: %[[MUL6:.+]] = fmul float %[[MUL]], %[[TMP25]] -// CHECK-NEXT: %[[TMP26:.+]] = load float*, float** %[[A_ADDR]], align 8 -// CHECK-NEXT: %[[TMP27:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM7:.+]] = sext i32 %[[TMP27]] to i64 -// CHECK-NEXT: %[[ARRAYIDX8:.+]] = getelementptr inbounds float, float* %[[TMP26]], i64 %[[IDXPROM7]] +// CHECK-NEXT: call void @__captured_stmt.1(i32* %[[I]], i32 %[[OMP_LOOP_IV]], %struct.anon.0* %[[AGG_CAPTURED1]]) +// CHECK-NEXT: %[[TMP3:.+]] = load float*, float** %[[B_ADDR]], align 8 +// CHECK-NEXT: %[[TMP4:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM:.+]] = zext i32 %[[TMP4]] to i64 +// CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP3]], i64 %[[IDXPROM]] +// CHECK-NEXT: %[[TMP5:.+]] = load float, float* %[[ARRAYIDX]], align 4 +// CHECK-NEXT: %[[TMP6:.+]] = load float*, float** %[[C_ADDR]], align 8 +// CHECK-NEXT: %[[TMP7:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM2:.+]] = zext i32 %[[TMP7]] to i64 +// CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP6]], i64 %[[IDXPROM2]] +// CHECK-NEXT: %[[TMP8:.+]] = load float, float* %[[ARRAYIDX3]], align 4 +// CHECK-NEXT: %[[MUL:.+]] = fmul float %[[TMP5]], %[[TMP8]] +// CHECK-NEXT: %[[TMP9:.+]] = load float*, float** %[[D_ADDR]], align 8 +// CHECK-NEXT: %[[TMP10:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM4:.+]] = zext i32 %[[TMP10]] to i64 +// CHECK-NEXT: %[[ARRAYIDX5:.+]] = getelementptr inbounds float, float* %[[TMP9]], i64 %[[IDXPROM4]] +// CHECK-NEXT: %[[TMP11:.+]] = load float, float* %[[ARRAYIDX5]], align 4 +// CHECK-NEXT: %[[MUL6:.+]] = fmul float %[[MUL]], %[[TMP11]] +// CHECK-NEXT: %[[TMP12:.+]] = load float*, float** %[[A_ADDR]], align 8 +// CHECK-NEXT: %[[TMP13:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM7:.+]] = zext i32 %[[TMP13]] to i64 +// CHECK-NEXT: %[[ARRAYIDX8:.+]] = getelementptr inbounds float, float* %[[TMP12]], i64 %[[IDXPROM7]] // CHECK-NEXT: store float %[[MUL6]], float* %[[ARRAYIDX8]], align 4 -// CHECK-NEXT: br label %[[OMP_TILE0_INC]] +// CHECK-NEXT: br label %[[OMP_LOOP_INC]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_INC]]: -// CHECK-NEXT: %[[OMP_TILE0_NEXT]] = add nuw i32 %[[OMP_TILE0_IV]], 1 -// CHECK-NEXT: br label %[[OMP_TILE0_HEADER]], !llvm.loop ![[LOOP3:[0-9]+]] +// CHECK-NEXT: [[OMP_LOOP_INC]]: +// CHECK-NEXT: %[[OMP_LOOP_NEXT]] = add nuw i32 %[[OMP_LOOP_IV]], 1 +// CHECK-NEXT: br label %[[OMP_LOOP_HEADER]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_EXIT]]: -// CHECK-NEXT: br label %[[OMP_TILE0_AFTER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_AFTER]]: -// CHECK-NEXT: br label %[[OMP_FLOOR0_INC]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_INC]]: -// CHECK-NEXT: %[[OMP_FLOOR0_NEXT]] = add nuw i32 %[[OMP_FLOOR0_IV]], 1 -// CHECK-NEXT: br label %[[OMP_FLOOR0_HEADER]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_EXIT]]: -// CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]]) +// CHECK-NEXT: [[OMP_LOOP_EXIT:.*]]: // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM9:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) // CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @2, i32 %[[OMP_GLOBAL_THREAD_NUM9]]) -// CHECK-NEXT: br label %[[OMP_FLOOR0_AFTER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_AFTER]]: // CHECK-NEXT: br label %[[OMP_LOOP_AFTER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_AFTER]]: // CHECK-NEXT: ret void +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_PREHEADER_OUTER_COND]]: +// CHECK-NEXT: %[[TMP14:.+]] = call i32 @__kmpc_dispatch_next_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]]) +// CHECK-NEXT: %[[TMP15:.+]] = icmp ne i32 %[[TMP14]], 0 +// CHECK-NEXT: %[[TMP16:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 +// CHECK-NEXT: %[[LB]] = sub i32 %[[TMP16]], 1 +// CHECK-NEXT: br i1 %[[TMP15]], label %[[OMP_LOOP_HEADER]], label %[[OMP_LOOP_EXIT]] // CHECK-NEXT: } -void unroll_partial_factor_for(float *a, float *b, float *c, float *d) { -#pragma omp for -#pragma omp unroll partial(2) - for (int i = 0; i < 2; i++) { +extern "C" void workshareloop_unsigned_dynamic_chunked(float *a, float *b, float *c, float *d) { +#pragma omp for schedule(dynamic, 5) + for (unsigned i = 33; i < 32000000; i += 7) { a[i] = b[i] * c[i] * d[i]; } } @@ -161,17 +119,17 @@ // CHECK-NEXT: %[[TMP2:.+]] = load i32*, i32** %[[TMP1]], align 8 // CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[TMP2]], align 4 // CHECK-NEXT: store i32 %[[TMP3]], i32* %[[DOTSTART]], align 4 -// CHECK-NEXT: store i32 2, i32* %[[DOTSTOP]], align 4 -// CHECK-NEXT: store i32 1, i32* %[[DOTSTEP]], align 4 +// CHECK-NEXT: store i32 32000000, i32* %[[DOTSTOP]], align 4 +// CHECK-NEXT: store i32 7, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[TMP4:.+]] = load i32, i32* %[[DOTSTART]], align 4 // CHECK-NEXT: %[[TMP5:.+]] = load i32, i32* %[[DOTSTOP]], align 4 -// CHECK-NEXT: %[[CMP:.+]] = icmp slt i32 %[[TMP4]], %[[TMP5]] +// CHECK-NEXT: %[[CMP:.+]] = icmp ult i32 %[[TMP4]], %[[TMP5]] // CHECK-NEXT: br i1 %[[CMP]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[COND_TRUE]]: // CHECK-NEXT: %[[TMP6:.+]] = load i32, i32* %[[DOTSTOP]], align 4 // CHECK-NEXT: %[[TMP7:.+]] = load i32, i32* %[[DOTSTART]], align 4 -// CHECK-NEXT: %[[SUB:.+]] = sub nsw i32 %[[TMP6]], %[[TMP7]] +// CHECK-NEXT: %[[SUB:.+]] = sub i32 %[[TMP6]], %[[TMP7]] // CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[DIV:.+]] = udiv i32 %[[SUB]], %[[TMP8]] // CHECK-NEXT: br label %[[COND_END:.+]] @@ -199,7 +157,7 @@ // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[TMP0]], i32 0, i32 0 // CHECK-NEXT: %[[TMP2:.+]] = load i32, i32* %[[TMP1]], align 4 // CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[LOGICAL_ADDR]], align 4 -// CHECK-NEXT: %[[MUL:.+]] = mul i32 1, %[[TMP3]] +// CHECK-NEXT: %[[MUL:.+]] = mul i32 7, %[[TMP3]] // CHECK-NEXT: %[[ADD:.+]] = add i32 %[[TMP2]], %[[MUL]] // CHECK-NEXT: %[[TMP4:.+]] = load i32*, i32** %[[LOOPVAR_ADDR]], align 8 // CHECK-NEXT: store i32 %[[ADD]], i32* %[[TMP4]], align 4 @@ -208,8 +166,5 @@ // CHECK: ![[META0:[0-9]+]] = !{i32 1, !"wchar_size", i32 4} -// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 51} +// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 45} // CHECK: ![[META2:[0-9]+]] = -// CHECK: ![[LOOP3]] = distinct !{![[LOOP3]], ![[LOOPPROP4:[0-9]+]], ![[LOOPPROP5:[0-9]+]]} -// CHECK: ![[LOOPPROP4]] = !{!"llvm.loop.unroll.enable"} -// CHECK: ![[LOOPPROP5]] = !{!"llvm.loop.unroll.count", i32 2} diff --git a/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c b/clang/test/OpenMP/irbuilder_for_unsigned_runtime.c copy from clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c copy to clang/test/OpenMP/irbuilder_for_unsigned_runtime.c --- a/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c +++ b/clang/test/OpenMP/irbuilder_for_unsigned_runtime.c @@ -1,11 +1,11 @@ // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs -// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=51 -x c -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s // expected-no-diagnostics #ifndef HEADER #define HEADER -// CHECK-LABEL: define {{.*}}@unroll_partial_factor_for( +// CHECK-LABEL: define {{.*}}@workshareloop_unsigned_runtime( // CHECK-NEXT: [[ENTRY:.*]]: // CHECK-NEXT: %[[A_ADDR:.+]] = alloca float*, align 8 // CHECK-NEXT: %[[B_ADDR:.+]] = alloca float*, align 8 @@ -23,7 +23,7 @@ // CHECK-NEXT: store float* %[[B:.+]], float** %[[B_ADDR]], align 8 // CHECK-NEXT: store float* %[[C:.+]], float** %[[C_ADDR]], align 8 // CHECK-NEXT: store float* %[[D:.+]], float** %[[D_ADDR]], align 8 -// CHECK-NEXT: store i32 0, i32* %[[I]], align 4 +// CHECK-NEXT: store i32 33, i32* %[[I]], align 4 // CHECK-NEXT: %[[TMP0:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[AGG_CAPTURED]], i32 0, i32 0 // CHECK-NEXT: store i32* %[[I]], i32** %[[TMP0]], align 8 // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[AGG_CAPTURED1]], i32 0, i32 0 @@ -34,113 +34,71 @@ // CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_PREHEADER]]: -// CHECK-NEXT: %[[TMP3:.+]] = udiv i32 %[[DOTCOUNT]], 2 -// CHECK-NEXT: %[[TMP4:.+]] = urem i32 %[[DOTCOUNT]], 2 -// CHECK-NEXT: %[[TMP5:.+]] = icmp ne i32 %[[TMP4]], 0 -// CHECK-NEXT: %[[TMP6:.+]] = zext i1 %[[TMP5]] to i32 -// CHECK-NEXT: %[[OMP_FLOOR0_TRIPCOUNT:.+]] = add nuw i32 %[[TMP3]], %[[TMP6]] -// CHECK-NEXT: br label %[[OMP_FLOOR0_PREHEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_PREHEADER]]: -// CHECK-NEXT: store i32 0, i32* %[[P_LOWERBOUND]], align 4 -// CHECK-NEXT: %[[TMP7:.+]] = sub i32 %[[OMP_FLOOR0_TRIPCOUNT]], 1 -// CHECK-NEXT: store i32 %[[TMP7]], i32* %[[P_UPPERBOUND]], align 4 +// CHECK-NEXT: store i32 1, i32* %[[P_LOWERBOUND]], align 4 +// CHECK-NEXT: store i32 %[[DOTCOUNT]], i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: store i32 1, i32* %[[P_STRIDE]], align 4 // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) -// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 1) -// CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 -// CHECK-NEXT: %[[TMP9:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 -// CHECK-NEXT: %[[TMP10:.+]] = sub i32 %[[TMP9]], %[[TMP8]] -// CHECK-NEXT: %[[TMP11:.+]] = add i32 %[[TMP10]], 1 -// CHECK-NEXT: br label %[[OMP_FLOOR0_HEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_HEADER]]: -// CHECK-NEXT: %[[OMP_FLOOR0_IV:.+]] = phi i32 [ 0, %[[OMP_FLOOR0_PREHEADER]] ], [ %[[OMP_FLOOR0_NEXT:.+]], %[[OMP_FLOOR0_INC:.+]] ] -// CHECK-NEXT: br label %[[OMP_FLOOR0_COND:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_COND]]: -// CHECK-NEXT: %[[OMP_FLOOR0_CMP:.+]] = icmp ult i32 %[[OMP_FLOOR0_IV]], %[[TMP11]] -// CHECK-NEXT: br i1 %[[OMP_FLOOR0_CMP]], label %[[OMP_FLOOR0_BODY:.+]], label %[[OMP_FLOOR0_EXIT:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_BODY]]: -// CHECK-NEXT: %[[TMP12:.+]] = add i32 %[[OMP_FLOOR0_IV]], %[[TMP8]] -// CHECK-NEXT: %[[TMP13:.+]] = icmp eq i32 %[[TMP12]], %[[OMP_FLOOR0_TRIPCOUNT]] -// CHECK-NEXT: %[[TMP14:.+]] = select i1 %[[TMP13]], i32 %[[TMP4]], i32 2 -// CHECK-NEXT: br label %[[OMP_TILE0_PREHEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_PREHEADER]]: -// CHECK-NEXT: br label %[[OMP_TILE0_HEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_HEADER]]: -// CHECK-NEXT: %[[OMP_TILE0_IV:.+]] = phi i32 [ 0, %[[OMP_TILE0_PREHEADER]] ], [ %[[OMP_TILE0_NEXT:.+]], %[[OMP_TILE0_INC:.+]] ] -// CHECK-NEXT: br label %[[OMP_TILE0_COND:.+]] +// CHECK-NEXT: call void @__kmpc_dispatch_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 37, i32 1, i32 %[[DOTCOUNT]], i32 1, i32 1) +// CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER_OUTER_COND:.+]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_COND]]: -// CHECK-NEXT: %[[OMP_TILE0_CMP:.+]] = icmp ult i32 %[[OMP_TILE0_IV]], %[[TMP14]] -// CHECK-NEXT: br i1 %[[OMP_TILE0_CMP]], label %[[OMP_TILE0_BODY:.+]], label %[[OMP_TILE0_EXIT:.+]] +// CHECK-NEXT: [[OMP_LOOP_HEADER:.*]]: +// CHECK-NEXT: %[[OMP_LOOP_IV:.+]] = phi i32 [ %[[LB:.+]], %[[OMP_LOOP_PREHEADER_OUTER_COND]] ], [ %[[OMP_LOOP_NEXT:.+]], %[[OMP_LOOP_INC:.+]] ] +// CHECK-NEXT: br label %[[OMP_LOOP_COND:.+]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_BODY]]: -// CHECK-NEXT: %[[TMP15:.+]] = mul nuw i32 2, %[[TMP12]] -// CHECK-NEXT: %[[TMP16:.+]] = add nuw i32 %[[TMP15]], %[[OMP_TILE0_IV]] -// CHECK-NEXT: br label %[[OMP_LOOP_BODY:.+]] +// CHECK-NEXT: [[OMP_LOOP_COND]]: +// CHECK-NEXT: %[[UB:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 +// CHECK-NEXT: %[[OMP_LOOP_CMP:.+]] = icmp ult i32 %[[OMP_LOOP_IV]], %[[UB]] +// CHECK-NEXT: br i1 %[[OMP_LOOP_CMP]], label %[[OMP_LOOP_BODY:.+]], label %[[OMP_LOOP_PREHEADER_OUTER_COND]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_BODY]]: -// CHECK-NEXT: call void @__captured_stmt.1(i32* %[[I]], i32 %[[TMP16]], %struct.anon.0* %[[AGG_CAPTURED1]]) -// CHECK-NEXT: %[[TMP17:.+]] = load float*, float** %[[B_ADDR]], align 8 -// CHECK-NEXT: %[[TMP18:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM:.+]] = sext i32 %[[TMP18]] to i64 -// CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP17]], i64 %[[IDXPROM]] -// CHECK-NEXT: %[[TMP19:.+]] = load float, float* %[[ARRAYIDX]], align 4 -// CHECK-NEXT: %[[TMP20:.+]] = load float*, float** %[[C_ADDR]], align 8 -// CHECK-NEXT: %[[TMP21:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM2:.+]] = sext i32 %[[TMP21]] to i64 -// CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP20]], i64 %[[IDXPROM2]] -// CHECK-NEXT: %[[TMP22:.+]] = load float, float* %[[ARRAYIDX3]], align 4 -// CHECK-NEXT: %[[MUL:.+]] = fmul float %[[TMP19]], %[[TMP22]] -// CHECK-NEXT: %[[TMP23:.+]] = load float*, float** %[[D_ADDR]], align 8 -// CHECK-NEXT: %[[TMP24:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM4:.+]] = sext i32 %[[TMP24]] to i64 -// CHECK-NEXT: %[[ARRAYIDX5:.+]] = getelementptr inbounds float, float* %[[TMP23]], i64 %[[IDXPROM4]] -// CHECK-NEXT: %[[TMP25:.+]] = load float, float* %[[ARRAYIDX5]], align 4 -// CHECK-NEXT: %[[MUL6:.+]] = fmul float %[[MUL]], %[[TMP25]] -// CHECK-NEXT: %[[TMP26:.+]] = load float*, float** %[[A_ADDR]], align 8 -// CHECK-NEXT: %[[TMP27:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM7:.+]] = sext i32 %[[TMP27]] to i64 -// CHECK-NEXT: %[[ARRAYIDX8:.+]] = getelementptr inbounds float, float* %[[TMP26]], i64 %[[IDXPROM7]] +// CHECK-NEXT: call void @__captured_stmt.1(i32* %[[I]], i32 %[[OMP_LOOP_IV]], %struct.anon.0* %[[AGG_CAPTURED1]]) +// CHECK-NEXT: %[[TMP3:.+]] = load float*, float** %[[B_ADDR]], align 8 +// CHECK-NEXT: %[[TMP4:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM:.+]] = zext i32 %[[TMP4]] to i64 +// CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP3]], i64 %[[IDXPROM]] +// CHECK-NEXT: %[[TMP5:.+]] = load float, float* %[[ARRAYIDX]], align 4 +// CHECK-NEXT: %[[TMP6:.+]] = load float*, float** %[[C_ADDR]], align 8 +// CHECK-NEXT: %[[TMP7:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM2:.+]] = zext i32 %[[TMP7]] to i64 +// CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP6]], i64 %[[IDXPROM2]] +// CHECK-NEXT: %[[TMP8:.+]] = load float, float* %[[ARRAYIDX3]], align 4 +// CHECK-NEXT: %[[MUL:.+]] = fmul float %[[TMP5]], %[[TMP8]] +// CHECK-NEXT: %[[TMP9:.+]] = load float*, float** %[[D_ADDR]], align 8 +// CHECK-NEXT: %[[TMP10:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM4:.+]] = zext i32 %[[TMP10]] to i64 +// CHECK-NEXT: %[[ARRAYIDX5:.+]] = getelementptr inbounds float, float* %[[TMP9]], i64 %[[IDXPROM4]] +// CHECK-NEXT: %[[TMP11:.+]] = load float, float* %[[ARRAYIDX5]], align 4 +// CHECK-NEXT: %[[MUL6:.+]] = fmul float %[[MUL]], %[[TMP11]] +// CHECK-NEXT: %[[TMP12:.+]] = load float*, float** %[[A_ADDR]], align 8 +// CHECK-NEXT: %[[TMP13:.+]] = load i32, i32* %[[I]], align 4 +// CHECK-NEXT: %[[IDXPROM7:.+]] = zext i32 %[[TMP13]] to i64 +// CHECK-NEXT: %[[ARRAYIDX8:.+]] = getelementptr inbounds float, float* %[[TMP12]], i64 %[[IDXPROM7]] // CHECK-NEXT: store float %[[MUL6]], float* %[[ARRAYIDX8]], align 4 -// CHECK-NEXT: br label %[[OMP_TILE0_INC]] +// CHECK-NEXT: br label %[[OMP_LOOP_INC]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_INC]]: -// CHECK-NEXT: %[[OMP_TILE0_NEXT]] = add nuw i32 %[[OMP_TILE0_IV]], 1 -// CHECK-NEXT: br label %[[OMP_TILE0_HEADER]], !llvm.loop ![[LOOP3:[0-9]+]] +// CHECK-NEXT: [[OMP_LOOP_INC]]: +// CHECK-NEXT: %[[OMP_LOOP_NEXT]] = add nuw i32 %[[OMP_LOOP_IV]], 1 +// CHECK-NEXT: br label %[[OMP_LOOP_HEADER]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_EXIT]]: -// CHECK-NEXT: br label %[[OMP_TILE0_AFTER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_AFTER]]: -// CHECK-NEXT: br label %[[OMP_FLOOR0_INC]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_INC]]: -// CHECK-NEXT: %[[OMP_FLOOR0_NEXT]] = add nuw i32 %[[OMP_FLOOR0_IV]], 1 -// CHECK-NEXT: br label %[[OMP_FLOOR0_HEADER]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_EXIT]]: -// CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]]) +// CHECK-NEXT: [[OMP_LOOP_EXIT:.*]]: // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM9:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) // CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @2, i32 %[[OMP_GLOBAL_THREAD_NUM9]]) -// CHECK-NEXT: br label %[[OMP_FLOOR0_AFTER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_AFTER]]: // CHECK-NEXT: br label %[[OMP_LOOP_AFTER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_AFTER]]: // CHECK-NEXT: ret void +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_PREHEADER_OUTER_COND]]: +// CHECK-NEXT: %[[TMP14:.+]] = call i32 @__kmpc_dispatch_next_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]]) +// CHECK-NEXT: %[[TMP15:.+]] = icmp ne i32 %[[TMP14]], 0 +// CHECK-NEXT: %[[TMP16:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 +// CHECK-NEXT: %[[LB]] = sub i32 %[[TMP16]], 1 +// CHECK-NEXT: br i1 %[[TMP15]], label %[[OMP_LOOP_HEADER]], label %[[OMP_LOOP_EXIT]] // CHECK-NEXT: } -void unroll_partial_factor_for(float *a, float *b, float *c, float *d) { -#pragma omp for -#pragma omp unroll partial(2) - for (int i = 0; i < 2; i++) { +extern "C" void workshareloop_unsigned_runtime(float *a, float *b, float *c, float *d) { +#pragma omp for schedule(runtime) + for (unsigned i = 33; i < 32000000; i += 7) { a[i] = b[i] * c[i] * d[i]; } } @@ -161,17 +119,17 @@ // CHECK-NEXT: %[[TMP2:.+]] = load i32*, i32** %[[TMP1]], align 8 // CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[TMP2]], align 4 // CHECK-NEXT: store i32 %[[TMP3]], i32* %[[DOTSTART]], align 4 -// CHECK-NEXT: store i32 2, i32* %[[DOTSTOP]], align 4 -// CHECK-NEXT: store i32 1, i32* %[[DOTSTEP]], align 4 +// CHECK-NEXT: store i32 32000000, i32* %[[DOTSTOP]], align 4 +// CHECK-NEXT: store i32 7, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[TMP4:.+]] = load i32, i32* %[[DOTSTART]], align 4 // CHECK-NEXT: %[[TMP5:.+]] = load i32, i32* %[[DOTSTOP]], align 4 -// CHECK-NEXT: %[[CMP:.+]] = icmp slt i32 %[[TMP4]], %[[TMP5]] +// CHECK-NEXT: %[[CMP:.+]] = icmp ult i32 %[[TMP4]], %[[TMP5]] // CHECK-NEXT: br i1 %[[CMP]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[COND_TRUE]]: // CHECK-NEXT: %[[TMP6:.+]] = load i32, i32* %[[DOTSTOP]], align 4 // CHECK-NEXT: %[[TMP7:.+]] = load i32, i32* %[[DOTSTART]], align 4 -// CHECK-NEXT: %[[SUB:.+]] = sub nsw i32 %[[TMP6]], %[[TMP7]] +// CHECK-NEXT: %[[SUB:.+]] = sub i32 %[[TMP6]], %[[TMP7]] // CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[DIV:.+]] = udiv i32 %[[SUB]], %[[TMP8]] // CHECK-NEXT: br label %[[COND_END:.+]] @@ -199,7 +157,7 @@ // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[TMP0]], i32 0, i32 0 // CHECK-NEXT: %[[TMP2:.+]] = load i32, i32* %[[TMP1]], align 4 // CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[LOGICAL_ADDR]], align 4 -// CHECK-NEXT: %[[MUL:.+]] = mul i32 1, %[[TMP3]] +// CHECK-NEXT: %[[MUL:.+]] = mul i32 7, %[[TMP3]] // CHECK-NEXT: %[[ADD:.+]] = add i32 %[[TMP2]], %[[MUL]] // CHECK-NEXT: %[[TMP4:.+]] = load i32*, i32** %[[LOOPVAR_ADDR]], align 8 // CHECK-NEXT: store i32 %[[ADD]], i32* %[[TMP4]], align 4 @@ -208,8 +166,5 @@ // CHECK: ![[META0:[0-9]+]] = !{i32 1, !"wchar_size", i32 4} -// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 51} +// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 45} // CHECK: ![[META2:[0-9]+]] = -// CHECK: ![[LOOP3]] = distinct !{![[LOOP3]], ![[LOOPPROP4:[0-9]+]], ![[LOOPPROP5:[0-9]+]]} -// CHECK: ![[LOOPPROP4]] = !{!"llvm.loop.unroll.enable"} -// CHECK: ![[LOOPPROP5]] = !{!"llvm.loop.unroll.count", i32 2} diff --git a/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c b/clang/test/OpenMP/irbuilder_for_unsigned_static_chunked.c copy from clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c copy to clang/test/OpenMP/irbuilder_for_unsigned_static_chunked.c --- a/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c +++ b/clang/test/OpenMP/irbuilder_for_unsigned_static_chunked.c @@ -1,11 +1,11 @@ // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs -// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=51 -x c -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s // expected-no-diagnostics #ifndef HEADER #define HEADER -// CHECK-LABEL: define {{.*}}@unroll_partial_factor_for( +// CHECK-LABEL: define {{.*}}@workshareloop_unsigned_static_chunked( // CHECK-NEXT: [[ENTRY:.*]]: // CHECK-NEXT: %[[A_ADDR:.+]] = alloca float*, align 8 // CHECK-NEXT: %[[B_ADDR:.+]] = alloca float*, align 8 @@ -23,7 +23,7 @@ // CHECK-NEXT: store float* %[[B:.+]], float** %[[B_ADDR]], align 8 // CHECK-NEXT: store float* %[[C:.+]], float** %[[C_ADDR]], align 8 // CHECK-NEXT: store float* %[[D:.+]], float** %[[D_ADDR]], align 8 -// CHECK-NEXT: store i32 0, i32* %[[I]], align 4 +// CHECK-NEXT: store i32 33, i32* %[[I]], align 4 // CHECK-NEXT: %[[TMP0:.+]] = getelementptr inbounds %struct.anon, %struct.anon* %[[AGG_CAPTURED]], i32 0, i32 0 // CHECK-NEXT: store i32* %[[I]], i32** %[[TMP0]], align 8 // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[AGG_CAPTURED1]], i32 0, i32 0 @@ -34,113 +34,112 @@ // CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_PREHEADER]]: -// CHECK-NEXT: %[[TMP3:.+]] = udiv i32 %[[DOTCOUNT]], 2 -// CHECK-NEXT: %[[TMP4:.+]] = urem i32 %[[DOTCOUNT]], 2 -// CHECK-NEXT: %[[TMP5:.+]] = icmp ne i32 %[[TMP4]], 0 -// CHECK-NEXT: %[[TMP6:.+]] = zext i1 %[[TMP5]] to i32 -// CHECK-NEXT: %[[OMP_FLOOR0_TRIPCOUNT:.+]] = add nuw i32 %[[TMP3]], %[[TMP6]] -// CHECK-NEXT: br label %[[OMP_FLOOR0_PREHEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_PREHEADER]]: +// CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) // CHECK-NEXT: store i32 0, i32* %[[P_LOWERBOUND]], align 4 -// CHECK-NEXT: %[[TMP7:.+]] = sub i32 %[[OMP_FLOOR0_TRIPCOUNT]], 1 -// CHECK-NEXT: store i32 %[[TMP7]], i32* %[[P_UPPERBOUND]], align 4 +// CHECK-NEXT: %[[TMP3:.+]] = sub i32 %[[DOTCOUNT]], 1 +// CHECK-NEXT: store i32 %[[TMP3]], i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: store i32 1, i32* %[[P_STRIDE]], align 4 -// CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) -// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 1) -// CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 -// CHECK-NEXT: %[[TMP9:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 -// CHECK-NEXT: %[[TMP10:.+]] = sub i32 %[[TMP9]], %[[TMP8]] -// CHECK-NEXT: %[[TMP11:.+]] = add i32 %[[TMP10]], 1 -// CHECK-NEXT: br label %[[OMP_FLOOR0_HEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_HEADER]]: -// CHECK-NEXT: %[[OMP_FLOOR0_IV:.+]] = phi i32 [ 0, %[[OMP_FLOOR0_PREHEADER]] ], [ %[[OMP_FLOOR0_NEXT:.+]], %[[OMP_FLOOR0_INC:.+]] ] -// CHECK-NEXT: br label %[[OMP_FLOOR0_COND:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_COND]]: -// CHECK-NEXT: %[[OMP_FLOOR0_CMP:.+]] = icmp ult i32 %[[OMP_FLOOR0_IV]], %[[TMP11]] -// CHECK-NEXT: br i1 %[[OMP_FLOOR0_CMP]], label %[[OMP_FLOOR0_BODY:.+]], label %[[OMP_FLOOR0_EXIT:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_BODY]]: -// CHECK-NEXT: %[[TMP12:.+]] = add i32 %[[OMP_FLOOR0_IV]], %[[TMP8]] -// CHECK-NEXT: %[[TMP13:.+]] = icmp eq i32 %[[TMP12]], %[[OMP_FLOOR0_TRIPCOUNT]] -// CHECK-NEXT: %[[TMP14:.+]] = select i1 %[[TMP13]], i32 %[[TMP4]], i32 2 -// CHECK-NEXT: br label %[[OMP_TILE0_PREHEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_PREHEADER]]: -// CHECK-NEXT: br label %[[OMP_TILE0_HEADER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_HEADER]]: -// CHECK-NEXT: %[[OMP_TILE0_IV:.+]] = phi i32 [ 0, %[[OMP_TILE0_PREHEADER]] ], [ %[[OMP_TILE0_NEXT:.+]], %[[OMP_TILE0_INC:.+]] ] -// CHECK-NEXT: br label %[[OMP_TILE0_COND:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_COND]]: -// CHECK-NEXT: %[[OMP_TILE0_CMP:.+]] = icmp ult i32 %[[OMP_TILE0_IV]], %[[TMP14]] -// CHECK-NEXT: br i1 %[[OMP_TILE0_CMP]], label %[[OMP_TILE0_BODY:.+]], label %[[OMP_TILE0_EXIT:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_BODY]]: -// CHECK-NEXT: %[[TMP15:.+]] = mul nuw i32 2, %[[TMP12]] -// CHECK-NEXT: %[[TMP16:.+]] = add nuw i32 %[[TMP15]], %[[OMP_TILE0_IV]] -// CHECK-NEXT: br label %[[OMP_LOOP_BODY:.+]] +// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 33, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 5) +// CHECK-NEXT: %[[OMP_FIRSTCHUNK_LB:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 +// CHECK-NEXT: %[[OMP_FIRSTCHUNK_UB:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 +// CHECK-NEXT: %[[TMP4:.+]] = add i32 %[[OMP_FIRSTCHUNK_UB]], 1 +// CHECK-NEXT: %[[OMP_CHUNK_RANGE:.+]] = sub i32 %[[TMP4]], %[[OMP_FIRSTCHUNK_LB]] +// CHECK-NEXT: %[[OMP_DISPATCH_STRIDE:.+]] = load i32, i32* %[[P_STRIDE]], align 4 +// CHECK-NEXT: %[[TMP5:.+]] = sub nuw i32 %[[DOTCOUNT]], %[[OMP_FIRSTCHUNK_LB]] +// CHECK-NEXT: %[[TMP6:.+]] = icmp ule i32 %[[DOTCOUNT]], %[[OMP_FIRSTCHUNK_LB]] +// CHECK-NEXT: %[[TMP7:.+]] = sub i32 %[[TMP5]], 1 +// CHECK-NEXT: %[[TMP8:.+]] = udiv i32 %[[TMP7]], %[[OMP_DISPATCH_STRIDE]] +// CHECK-NEXT: %[[TMP9:.+]] = add i32 %[[TMP8]], 1 +// CHECK-NEXT: %[[TMP10:.+]] = icmp ule i32 %[[TMP5]], %[[OMP_DISPATCH_STRIDE]] +// CHECK-NEXT: %[[TMP11:.+]] = select i1 %[[TMP10]], i32 1, i32 %[[TMP9]] +// CHECK-NEXT: %[[OMP_DISPATCH_TRIPCOUNT:.+]] = select i1 %[[TMP6]], i32 0, i32 %[[TMP11]] +// CHECK-NEXT: br label %[[OMP_DISPATCH_PREHEADER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_DISPATCH_PREHEADER]]: +// CHECK-NEXT: br label %[[OMP_DISPATCH_HEADER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_DISPATCH_HEADER]]: +// CHECK-NEXT: %[[OMP_DISPATCH_IV:.+]] = phi i32 [ 0, %[[OMP_DISPATCH_PREHEADER]] ], [ %[[OMP_DISPATCH_NEXT:.+]], %[[OMP_DISPATCH_INC:.+]] ] +// CHECK-NEXT: br label %[[OMP_DISPATCH_COND:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_DISPATCH_COND]]: +// CHECK-NEXT: %[[OMP_DISPATCH_CMP:.+]] = icmp ult i32 %[[OMP_DISPATCH_IV]], %[[OMP_DISPATCH_TRIPCOUNT]] +// CHECK-NEXT: br i1 %[[OMP_DISPATCH_CMP]], label %[[OMP_DISPATCH_BODY:.+]], label %[[OMP_DISPATCH_EXIT:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_DISPATCH_BODY]]: +// CHECK-NEXT: %[[TMP12:.+]] = mul i32 %[[OMP_DISPATCH_IV]], %[[OMP_DISPATCH_STRIDE]] +// CHECK-NEXT: %[[TMP13:.+]] = add i32 %[[TMP12]], %[[OMP_FIRSTCHUNK_LB]] +// CHECK-NEXT: br label %[[OMP_LOOP_PREHEADER9:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_DISPATCH_INC]]: +// CHECK-NEXT: %[[OMP_DISPATCH_NEXT]] = add nuw i32 %[[OMP_DISPATCH_IV]], 1 +// CHECK-NEXT: br label %[[OMP_DISPATCH_HEADER]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_DISPATCH_EXIT]]: +// CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]]) +// CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM10:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) +// CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @2, i32 %[[OMP_GLOBAL_THREAD_NUM10]]) +// CHECK-NEXT: br label %[[OMP_DISPATCH_AFTER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_DISPATCH_AFTER]]: +// CHECK-NEXT: br label %[[OMP_LOOP_AFTER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_PREHEADER9]]: +// CHECK-NEXT: %[[TMP14:.+]] = add i32 %[[TMP13]], %[[OMP_CHUNK_RANGE]] +// CHECK-NEXT: %[[OMP_CHUNK_IS_LAST:.+]] = icmp uge i32 %[[TMP14]], %[[DOTCOUNT]] +// CHECK-NEXT: %[[TMP15:.+]] = sub i32 %[[DOTCOUNT]], %[[TMP13]] +// CHECK-NEXT: %[[OMP_CHUNK_TRIPCOUNT:.+]] = select i1 %[[OMP_CHUNK_IS_LAST]], i32 %[[TMP15]], i32 %[[OMP_CHUNK_RANGE]] +// CHECK-NEXT: br label %[[OMP_LOOP_HEADER:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_HEADER]]: +// CHECK-NEXT: %[[OMP_LOOP_IV:.+]] = phi i32 [ 0, %[[OMP_LOOP_PREHEADER9]] ], [ %[[OMP_LOOP_NEXT:.+]], %[[OMP_LOOP_INC:.+]] ] +// CHECK-NEXT: br label %[[OMP_LOOP_COND:.+]] +// CHECK-EMPTY: +// CHECK-NEXT: [[OMP_LOOP_COND]]: +// CHECK-NEXT: %[[OMP_LOOP_CMP:.+]] = icmp ult i32 %[[OMP_LOOP_IV]], %[[OMP_CHUNK_TRIPCOUNT]] +// CHECK-NEXT: br i1 %[[OMP_LOOP_CMP]], label %[[OMP_LOOP_BODY:.+]], label %[[OMP_LOOP_EXIT:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_BODY]]: +// CHECK-NEXT: %[[TMP16:.+]] = add i32 %[[OMP_LOOP_IV]], %[[TMP13]] // CHECK-NEXT: call void @__captured_stmt.1(i32* %[[I]], i32 %[[TMP16]], %struct.anon.0* %[[AGG_CAPTURED1]]) // CHECK-NEXT: %[[TMP17:.+]] = load float*, float** %[[B_ADDR]], align 8 // CHECK-NEXT: %[[TMP18:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM:.+]] = sext i32 %[[TMP18]] to i64 +// CHECK-NEXT: %[[IDXPROM:.+]] = zext i32 %[[TMP18]] to i64 // CHECK-NEXT: %[[ARRAYIDX:.+]] = getelementptr inbounds float, float* %[[TMP17]], i64 %[[IDXPROM]] // CHECK-NEXT: %[[TMP19:.+]] = load float, float* %[[ARRAYIDX]], align 4 // CHECK-NEXT: %[[TMP20:.+]] = load float*, float** %[[C_ADDR]], align 8 // CHECK-NEXT: %[[TMP21:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM2:.+]] = sext i32 %[[TMP21]] to i64 +// CHECK-NEXT: %[[IDXPROM2:.+]] = zext i32 %[[TMP21]] to i64 // CHECK-NEXT: %[[ARRAYIDX3:.+]] = getelementptr inbounds float, float* %[[TMP20]], i64 %[[IDXPROM2]] // CHECK-NEXT: %[[TMP22:.+]] = load float, float* %[[ARRAYIDX3]], align 4 // CHECK-NEXT: %[[MUL:.+]] = fmul float %[[TMP19]], %[[TMP22]] // CHECK-NEXT: %[[TMP23:.+]] = load float*, float** %[[D_ADDR]], align 8 // CHECK-NEXT: %[[TMP24:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM4:.+]] = sext i32 %[[TMP24]] to i64 +// CHECK-NEXT: %[[IDXPROM4:.+]] = zext i32 %[[TMP24]] to i64 // CHECK-NEXT: %[[ARRAYIDX5:.+]] = getelementptr inbounds float, float* %[[TMP23]], i64 %[[IDXPROM4]] // CHECK-NEXT: %[[TMP25:.+]] = load float, float* %[[ARRAYIDX5]], align 4 // CHECK-NEXT: %[[MUL6:.+]] = fmul float %[[MUL]], %[[TMP25]] // CHECK-NEXT: %[[TMP26:.+]] = load float*, float** %[[A_ADDR]], align 8 // CHECK-NEXT: %[[TMP27:.+]] = load i32, i32* %[[I]], align 4 -// CHECK-NEXT: %[[IDXPROM7:.+]] = sext i32 %[[TMP27]] to i64 +// CHECK-NEXT: %[[IDXPROM7:.+]] = zext i32 %[[TMP27]] to i64 // CHECK-NEXT: %[[ARRAYIDX8:.+]] = getelementptr inbounds float, float* %[[TMP26]], i64 %[[IDXPROM7]] // CHECK-NEXT: store float %[[MUL6]], float* %[[ARRAYIDX8]], align 4 -// CHECK-NEXT: br label %[[OMP_TILE0_INC]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_INC]]: -// CHECK-NEXT: %[[OMP_TILE0_NEXT]] = add nuw i32 %[[OMP_TILE0_IV]], 1 -// CHECK-NEXT: br label %[[OMP_TILE0_HEADER]], !llvm.loop ![[LOOP3:[0-9]+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_EXIT]]: -// CHECK-NEXT: br label %[[OMP_TILE0_AFTER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_TILE0_AFTER]]: -// CHECK-NEXT: br label %[[OMP_FLOOR0_INC]] +// CHECK-NEXT: br label %[[OMP_LOOP_INC]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_INC]]: -// CHECK-NEXT: %[[OMP_FLOOR0_NEXT]] = add nuw i32 %[[OMP_FLOOR0_IV]], 1 -// CHECK-NEXT: br label %[[OMP_FLOOR0_HEADER]] +// CHECK-NEXT: [[OMP_LOOP_INC]]: +// CHECK-NEXT: %[[OMP_LOOP_NEXT]] = add nuw i32 %[[OMP_LOOP_IV]], 1 +// CHECK-NEXT: br label %[[OMP_LOOP_HEADER]] // CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_EXIT]]: -// CHECK-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]]) -// CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM9:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) -// CHECK-NEXT: call void @__kmpc_barrier(%struct.ident_t* @2, i32 %[[OMP_GLOBAL_THREAD_NUM9]]) -// CHECK-NEXT: br label %[[OMP_FLOOR0_AFTER:.+]] -// CHECK-EMPTY: -// CHECK-NEXT: [[OMP_FLOOR0_AFTER]]: -// CHECK-NEXT: br label %[[OMP_LOOP_AFTER:.+]] +// CHECK-NEXT: [[OMP_LOOP_EXIT]]: +// CHECK-NEXT: br label %[[OMP_DISPATCH_INC]] // CHECK-EMPTY: // CHECK-NEXT: [[OMP_LOOP_AFTER]]: // CHECK-NEXT: ret void // CHECK-NEXT: } -void unroll_partial_factor_for(float *a, float *b, float *c, float *d) { -#pragma omp for -#pragma omp unroll partial(2) - for (int i = 0; i < 2; i++) { +extern "C" void workshareloop_unsigned_static_chunked(float *a, float *b, float *c, float *d) { +#pragma omp for schedule(static, 5) + for (unsigned i = 33; i < 32000000; i += 7) { a[i] = b[i] * c[i] * d[i]; } } @@ -161,17 +160,17 @@ // CHECK-NEXT: %[[TMP2:.+]] = load i32*, i32** %[[TMP1]], align 8 // CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[TMP2]], align 4 // CHECK-NEXT: store i32 %[[TMP3]], i32* %[[DOTSTART]], align 4 -// CHECK-NEXT: store i32 2, i32* %[[DOTSTOP]], align 4 -// CHECK-NEXT: store i32 1, i32* %[[DOTSTEP]], align 4 +// CHECK-NEXT: store i32 32000000, i32* %[[DOTSTOP]], align 4 +// CHECK-NEXT: store i32 7, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[TMP4:.+]] = load i32, i32* %[[DOTSTART]], align 4 // CHECK-NEXT: %[[TMP5:.+]] = load i32, i32* %[[DOTSTOP]], align 4 -// CHECK-NEXT: %[[CMP:.+]] = icmp slt i32 %[[TMP4]], %[[TMP5]] +// CHECK-NEXT: %[[CMP:.+]] = icmp ult i32 %[[TMP4]], %[[TMP5]] // CHECK-NEXT: br i1 %[[CMP]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]] // CHECK-EMPTY: // CHECK-NEXT: [[COND_TRUE]]: // CHECK-NEXT: %[[TMP6:.+]] = load i32, i32* %[[DOTSTOP]], align 4 // CHECK-NEXT: %[[TMP7:.+]] = load i32, i32* %[[DOTSTART]], align 4 -// CHECK-NEXT: %[[SUB:.+]] = sub nsw i32 %[[TMP6]], %[[TMP7]] +// CHECK-NEXT: %[[SUB:.+]] = sub i32 %[[TMP6]], %[[TMP7]] // CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[DOTSTEP]], align 4 // CHECK-NEXT: %[[DIV:.+]] = udiv i32 %[[SUB]], %[[TMP8]] // CHECK-NEXT: br label %[[COND_END:.+]] @@ -199,7 +198,7 @@ // CHECK-NEXT: %[[TMP1:.+]] = getelementptr inbounds %struct.anon.0, %struct.anon.0* %[[TMP0]], i32 0, i32 0 // CHECK-NEXT: %[[TMP2:.+]] = load i32, i32* %[[TMP1]], align 4 // CHECK-NEXT: %[[TMP3:.+]] = load i32, i32* %[[LOGICAL_ADDR]], align 4 -// CHECK-NEXT: %[[MUL:.+]] = mul i32 1, %[[TMP3]] +// CHECK-NEXT: %[[MUL:.+]] = mul i32 7, %[[TMP3]] // CHECK-NEXT: %[[ADD:.+]] = add i32 %[[TMP2]], %[[MUL]] // CHECK-NEXT: %[[TMP4:.+]] = load i32*, i32** %[[LOOPVAR_ADDR]], align 8 // CHECK-NEXT: store i32 %[[ADD]], i32* %[[TMP4]], align 4 @@ -208,8 +207,5 @@ // CHECK: ![[META0:[0-9]+]] = !{i32 1, !"wchar_size", i32 4} -// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 51} +// CHECK: ![[META1:[0-9]+]] = !{i32 7, !"openmp", i32 45} // CHECK: ![[META2:[0-9]+]] = -// CHECK: ![[LOOP3]] = distinct !{![[LOOP3]], ![[LOOPPROP4:[0-9]+]], ![[LOOPPROP5:[0-9]+]]} -// CHECK: ![[LOOPPROP4]] = !{!"llvm.loop.unroll.enable"} -// CHECK: ![[LOOPPROP5]] = !{!"llvm.loop.unroll.count", i32 2} diff --git a/clang/test/OpenMP/irbuilder_nested_parallel_for.c b/clang/test/OpenMP/irbuilder_nested_parallel_for.c --- a/clang/test/OpenMP/irbuilder_nested_parallel_for.c +++ b/clang/test/OpenMP/irbuilder_nested_parallel_for.c @@ -23,15 +23,15 @@ // // CHECK-DEBUG-LABEL: @_Z14parallel_for_0v( // CHECK-DEBUG-NEXT: entry: -// CHECK-DEBUG-NEXT: [[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]]), !dbg [[DBG12:![0-9]+]] +// CHECK-DEBUG-NEXT: [[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]]), !dbg [[DBG13:![0-9]+]] // CHECK-DEBUG-NEXT: br label [[OMP_PARALLEL:%.*]] // CHECK-DEBUG: omp_parallel: -// CHECK-DEBUG-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* @_Z14parallel_for_0v..omp_par to void (i32*, i32*, ...)*)), !dbg [[DBG13:![0-9]+]] +// CHECK-DEBUG-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* @_Z14parallel_for_0v..omp_par to void (i32*, i32*, ...)*)), !dbg [[DBG14:![0-9]+]] // CHECK-DEBUG-NEXT: br label [[OMP_PAR_OUTLINED_EXIT:%.*]] // CHECK-DEBUG: omp.par.outlined.exit: // CHECK-DEBUG-NEXT: br label [[OMP_PAR_EXIT_SPLIT:%.*]] // CHECK-DEBUG: omp.par.exit.split: -// CHECK-DEBUG-NEXT: ret void, !dbg [[DBG17:![0-9]+]] +// CHECK-DEBUG-NEXT: ret void, !dbg [[DBG18:![0-9]+]] // void parallel_for_0(void) { #pragma omp parallel @@ -66,20 +66,20 @@ // CHECK-DEBUG-NEXT: [[A_ADDR:%.*]] = alloca i32, align 4 // CHECK-DEBUG-NEXT: [[B_ADDR:%.*]] = alloca double, align 8 // CHECK-DEBUG-NEXT: store float* [[R:%.*]], float** [[R_ADDR]], align 8 -// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata float** [[R_ADDR]], metadata [[META71:![0-9]+]], metadata !DIExpression()), !dbg [[DBG72:![0-9]+]] +// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata float** [[R_ADDR]], metadata [[META73:![0-9]+]], metadata !DIExpression()), !dbg [[DBG74:![0-9]+]] // CHECK-DEBUG-NEXT: store i32 [[A:%.*]], i32* [[A_ADDR]], align 4 -// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata i32* [[A_ADDR]], metadata [[META73:![0-9]+]], metadata !DIExpression()), !dbg [[DBG74:![0-9]+]] +// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata i32* [[A_ADDR]], metadata [[META75:![0-9]+]], metadata !DIExpression()), !dbg [[DBG76:![0-9]+]] // CHECK-DEBUG-NEXT: store double [[B:%.*]], double* [[B_ADDR]], align 8 -// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata double* [[B_ADDR]], metadata [[META75:![0-9]+]], metadata !DIExpression()), !dbg [[DBG76:![0-9]+]] -// CHECK-DEBUG-NEXT: [[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB6:[0-9]+]]), !dbg [[DBG77:![0-9]+]] +// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata double* [[B_ADDR]], metadata [[META77:![0-9]+]], metadata !DIExpression()), !dbg [[DBG78:![0-9]+]] +// CHECK-DEBUG-NEXT: [[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB6:[0-9]+]]), !dbg [[DBG79:![0-9]+]] // CHECK-DEBUG-NEXT: br label [[OMP_PARALLEL:%.*]] // CHECK-DEBUG: omp_parallel: -// CHECK-DEBUG-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB6]], i32 3, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*, double*, float**)* @_Z14parallel_for_1Pfid..omp_par.4 to void (i32*, i32*, ...)*), i32* [[A_ADDR]], double* [[B_ADDR]], float** [[R_ADDR]]), !dbg [[DBG78:![0-9]+]] +// CHECK-DEBUG-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB6]], i32 3, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*, double*, float**)* @_Z14parallel_for_1Pfid..omp_par.4 to void (i32*, i32*, ...)*), i32* [[A_ADDR]], double* [[B_ADDR]], float** [[R_ADDR]]), !dbg [[DBG80:![0-9]+]] // CHECK-DEBUG-NEXT: br label [[OMP_PAR_OUTLINED_EXIT16:%.*]] // CHECK-DEBUG: omp.par.outlined.exit16: // CHECK-DEBUG-NEXT: br label [[OMP_PAR_EXIT_SPLIT:%.*]] // CHECK-DEBUG: omp.par.exit.split: -// CHECK-DEBUG-NEXT: ret void, !dbg [[DBG80:![0-9]+]] +// CHECK-DEBUG-NEXT: ret void, !dbg [[DBG82:![0-9]+]] // void parallel_for_1(float *r, int a, double b) { #pragma omp parallel @@ -133,7 +133,7 @@ // CHECK-NEXT: store i32 [[TMP3]], i32* [[P_UPPERBOUND205]], align 4 // CHECK-NEXT: store i32 1, i32* [[P_STRIDE206]], align 4 // CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM207:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]]) -// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM207]], i32 34, i32* [[P_LASTITER203]], i32* [[P_LOWERBOUND204]], i32* [[P_UPPERBOUND205]], i32* [[P_STRIDE206]], i32 1, i32 1) +// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM207]], i32 34, i32* [[P_LASTITER203]], i32* [[P_LOWERBOUND204]], i32* [[P_UPPERBOUND205]], i32* [[P_STRIDE206]], i32 1, i32 0) // CHECK-NEXT: [[TMP4:%.*]] = load i32, i32* [[P_LOWERBOUND204]], align 4 // CHECK-NEXT: [[TMP5:%.*]] = load i32, i32* [[P_UPPERBOUND205]], align 4 // CHECK-NEXT: [[TMP6:%.*]] = sub i32 [[TMP5]], [[TMP4]] @@ -181,68 +181,68 @@ // CHECK-DEBUG-NEXT: [[P_UPPERBOUND205:%.*]] = alloca i32, align 4 // CHECK-DEBUG-NEXT: [[P_STRIDE206:%.*]] = alloca i32, align 4 // CHECK-DEBUG-NEXT: store float* [[R:%.*]], float** [[R_ADDR]], align 8 -// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata float** [[R_ADDR]], metadata [[META132:![0-9]+]], metadata !DIExpression()), !dbg [[DBG133:![0-9]+]] +// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata float** [[R_ADDR]], metadata [[META134:![0-9]+]], metadata !DIExpression()), !dbg [[DBG135:![0-9]+]] // CHECK-DEBUG-NEXT: store i32 [[A:%.*]], i32* [[A_ADDR]], align 4 -// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata i32* [[A_ADDR]], metadata [[META134:![0-9]+]], metadata !DIExpression()), !dbg [[DBG135:![0-9]+]] +// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata i32* [[A_ADDR]], metadata [[META136:![0-9]+]], metadata !DIExpression()), !dbg [[DBG137:![0-9]+]] // CHECK-DEBUG-NEXT: store double [[B:%.*]], double* [[B_ADDR]], align 8 -// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata double* [[B_ADDR]], metadata [[META136:![0-9]+]], metadata !DIExpression()), !dbg [[DBG137:![0-9]+]] -// CHECK-DEBUG-NEXT: [[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB13:[0-9]+]]), !dbg [[DBG138:![0-9]+]] +// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata double* [[B_ADDR]], metadata [[META138:![0-9]+]], metadata !DIExpression()), !dbg [[DBG139:![0-9]+]] +// CHECK-DEBUG-NEXT: [[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB13:[0-9]+]]), !dbg [[DBG140:![0-9]+]] // CHECK-DEBUG-NEXT: br label [[OMP_PARALLEL:%.*]] // CHECK-DEBUG: omp_parallel: -// CHECK-DEBUG-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB13]], i32 3, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*, double*, float**)* @_Z14parallel_for_2Pfid..omp_par.23 to void (i32*, i32*, ...)*), i32* [[A_ADDR]], double* [[B_ADDR]], float** [[R_ADDR]]), !dbg [[DBG139:![0-9]+]] +// CHECK-DEBUG-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB13]], i32 3, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*, double*, float**)* @_Z14parallel_for_2Pfid..omp_par.23 to void (i32*, i32*, ...)*), i32* [[A_ADDR]], double* [[B_ADDR]], float** [[R_ADDR]]), !dbg [[DBG141:![0-9]+]] // CHECK-DEBUG-NEXT: br label [[OMP_PAR_OUTLINED_EXIT184:%.*]] // CHECK-DEBUG: omp.par.outlined.exit184: // CHECK-DEBUG-NEXT: br label [[OMP_PAR_EXIT_SPLIT:%.*]] // CHECK-DEBUG: omp.par.exit.split: -// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata i32* [[I185]], metadata [[META143:![0-9]+]], metadata !DIExpression()), !dbg [[DBG146:![0-9]+]] -// CHECK-DEBUG-NEXT: store i32 0, i32* [[I185]], align 4, !dbg [[DBG146]] -// CHECK-DEBUG-NEXT: [[TMP0:%.*]] = getelementptr inbounds [[STRUCT_ANON_17]], %struct.anon.17* [[AGG_CAPTURED186]], i32 0, i32 0, !dbg [[DBG147:![0-9]+]] -// CHECK-DEBUG-NEXT: store i32* [[I185]], i32** [[TMP0]], align 8, !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON_18]], %struct.anon.18* [[AGG_CAPTURED187]], i32 0, i32 0, !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: [[TMP2:%.*]] = load i32, i32* [[I185]], align 4, !dbg [[DBG148:![0-9]+]] -// CHECK-DEBUG-NEXT: store i32 [[TMP2]], i32* [[TMP1]], align 4, !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: call void @__captured_stmt.19(i32* [[DOTCOUNT_ADDR188]], %struct.anon.17* [[AGG_CAPTURED186]]), !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: [[DOTCOUNT189:%.*]] = load i32, i32* [[DOTCOUNT_ADDR188]], align 4, !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: br label [[OMP_LOOP_PREHEADER190:%.*]], !dbg [[DBG147]] +// CHECK-DEBUG-NEXT: call void @llvm.dbg.declare(metadata i32* [[I185]], metadata [[META145:![0-9]+]], metadata !DIExpression()), !dbg [[DBG148:![0-9]+]] +// CHECK-DEBUG-NEXT: store i32 0, i32* [[I185]], align 4, !dbg [[DBG148]] +// CHECK-DEBUG-NEXT: [[TMP0:%.*]] = getelementptr inbounds [[STRUCT_ANON_17]], %struct.anon.17* [[AGG_CAPTURED186]], i32 0, i32 0, !dbg [[DBG149:![0-9]+]] +// CHECK-DEBUG-NEXT: store i32* [[I185]], i32** [[TMP0]], align 8, !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON_18]], %struct.anon.18* [[AGG_CAPTURED187]], i32 0, i32 0, !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: [[TMP2:%.*]] = load i32, i32* [[I185]], align 4, !dbg [[DBG150:![0-9]+]] +// CHECK-DEBUG-NEXT: store i32 [[TMP2]], i32* [[TMP1]], align 4, !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: call void @__captured_stmt.19(i32* [[DOTCOUNT_ADDR188]], %struct.anon.17* [[AGG_CAPTURED186]]), !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: [[DOTCOUNT189:%.*]] = load i32, i32* [[DOTCOUNT_ADDR188]], align 4, !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: br label [[OMP_LOOP_PREHEADER190:%.*]], !dbg [[DBG149]] // CHECK-DEBUG: omp_loop.preheader190: -// CHECK-DEBUG-NEXT: store i32 0, i32* [[P_LOWERBOUND204]], align 4, !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: [[TMP3:%.*]] = sub i32 [[DOTCOUNT189]], 1, !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: store i32 [[TMP3]], i32* [[P_UPPERBOUND205]], align 4, !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: store i32 1, i32* [[P_STRIDE206]], align 4, !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: [[OMP_GLOBAL_THREAD_NUM207:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB42:[0-9]+]]), !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB42]], i32 [[OMP_GLOBAL_THREAD_NUM207]], i32 34, i32* [[P_LASTITER203]], i32* [[P_LOWERBOUND204]], i32* [[P_UPPERBOUND205]], i32* [[P_STRIDE206]], i32 1, i32 1), !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: [[TMP4:%.*]] = load i32, i32* [[P_LOWERBOUND204]], align 4, !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: [[TMP5:%.*]] = load i32, i32* [[P_UPPERBOUND205]], align 4, !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: [[TMP6:%.*]] = sub i32 [[TMP5]], [[TMP4]], !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: [[TMP7:%.*]] = add i32 [[TMP6]], 1, !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: br label [[OMP_LOOP_HEADER191:%.*]], !dbg [[DBG147]] +// CHECK-DEBUG-NEXT: store i32 0, i32* [[P_LOWERBOUND204]], align 4, !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: [[TMP3:%.*]] = sub i32 [[DOTCOUNT189]], 1, !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: store i32 [[TMP3]], i32* [[P_UPPERBOUND205]], align 4, !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: store i32 1, i32* [[P_STRIDE206]], align 4, !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: [[OMP_GLOBAL_THREAD_NUM207:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB42:[0-9]+]]), !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @[[GLOB42]], i32 [[OMP_GLOBAL_THREAD_NUM207]], i32 34, i32* [[P_LASTITER203]], i32* [[P_LOWERBOUND204]], i32* [[P_UPPERBOUND205]], i32* [[P_STRIDE206]], i32 1, i32 0), !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: [[TMP4:%.*]] = load i32, i32* [[P_LOWERBOUND204]], align 4, !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: [[TMP5:%.*]] = load i32, i32* [[P_UPPERBOUND205]], align 4, !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: [[TMP6:%.*]] = sub i32 [[TMP5]], [[TMP4]], !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: [[TMP7:%.*]] = add i32 [[TMP6]], 1, !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: br label [[OMP_LOOP_HEADER191:%.*]], !dbg [[DBG149]] // CHECK-DEBUG: omp_loop.header191: -// CHECK-DEBUG-NEXT: [[OMP_LOOP_IV197:%.*]] = phi i32 [ 0, [[OMP_LOOP_PREHEADER190]] ], [ [[OMP_LOOP_NEXT199:%.*]], [[OMP_LOOP_INC194:%.*]] ], !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: br label [[OMP_LOOP_COND192:%.*]], !dbg [[DBG147]] +// CHECK-DEBUG-NEXT: [[OMP_LOOP_IV197:%.*]] = phi i32 [ 0, [[OMP_LOOP_PREHEADER190]] ], [ [[OMP_LOOP_NEXT199:%.*]], [[OMP_LOOP_INC194:%.*]] ], !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: br label [[OMP_LOOP_COND192:%.*]], !dbg [[DBG149]] // CHECK-DEBUG: omp_loop.cond192: -// CHECK-DEBUG-NEXT: [[OMP_LOOP_CMP198:%.*]] = icmp ult i32 [[OMP_LOOP_IV197]], [[TMP7]], !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: br i1 [[OMP_LOOP_CMP198]], label [[OMP_LOOP_BODY193:%.*]], label [[OMP_LOOP_EXIT195:%.*]], !dbg [[DBG147]] +// CHECK-DEBUG-NEXT: [[OMP_LOOP_CMP198:%.*]] = icmp ult i32 [[OMP_LOOP_IV197]], [[TMP7]], !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: br i1 [[OMP_LOOP_CMP198]], label [[OMP_LOOP_BODY193:%.*]], label [[OMP_LOOP_EXIT195:%.*]], !dbg [[DBG149]] // CHECK-DEBUG: omp_loop.body193: -// CHECK-DEBUG-NEXT: [[TMP8:%.*]] = add i32 [[OMP_LOOP_IV197]], [[TMP4]], !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: call void @__captured_stmt.20(i32* [[I185]], i32 [[TMP8]], %struct.anon.18* [[AGG_CAPTURED187]]), !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: [[TMP9:%.*]] = load i32, i32* [[A_ADDR]], align 4, !dbg [[DBG149:![0-9]+]] -// CHECK-DEBUG-NEXT: [[CONV200:%.*]] = sitofp i32 [[TMP9]] to double, !dbg [[DBG149]] -// CHECK-DEBUG-NEXT: [[TMP10:%.*]] = load double, double* [[B_ADDR]], align 8, !dbg [[DBG150:![0-9]+]] -// CHECK-DEBUG-NEXT: [[ADD201:%.*]] = fadd double [[CONV200]], [[TMP10]], !dbg [[DBG151:![0-9]+]] -// CHECK-DEBUG-NEXT: [[CONV202:%.*]] = fptrunc double [[ADD201]] to float, !dbg [[DBG149]] -// CHECK-DEBUG-NEXT: [[TMP11:%.*]] = load float*, float** [[R_ADDR]], align 8, !dbg [[DBG152:![0-9]+]] -// CHECK-DEBUG-NEXT: store float [[CONV202]], float* [[TMP11]], align 4, !dbg [[DBG153:![0-9]+]] -// CHECK-DEBUG-NEXT: br label [[OMP_LOOP_INC194]], !dbg [[DBG147]] +// CHECK-DEBUG-NEXT: [[TMP8:%.*]] = add i32 [[OMP_LOOP_IV197]], [[TMP4]], !dbg [[DBG151:![0-9]+]] +// CHECK-DEBUG-NEXT: call void @__captured_stmt.20(i32* [[I185]], i32 [[TMP8]], %struct.anon.18* [[AGG_CAPTURED187]]), !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: [[TMP9:%.*]] = load i32, i32* [[A_ADDR]], align 4, !dbg [[DBG152:![0-9]+]] +// CHECK-DEBUG-NEXT: [[CONV200:%.*]] = sitofp i32 [[TMP9]] to double, !dbg [[DBG152]] +// CHECK-DEBUG-NEXT: [[TMP10:%.*]] = load double, double* [[B_ADDR]], align 8, !dbg [[DBG151]] +// CHECK-DEBUG-NEXT: [[ADD201:%.*]] = fadd double [[CONV200]], [[TMP10]], !dbg [[DBG153:![0-9]+]] +// CHECK-DEBUG-NEXT: [[CONV202:%.*]] = fptrunc double [[ADD201]] to float, !dbg [[DBG152]] +// CHECK-DEBUG-NEXT: [[TMP11:%.*]] = load float*, float** [[R_ADDR]], align 8, !dbg [[DBG154:![0-9]+]] +// CHECK-DEBUG-NEXT: store float [[CONV202]], float* [[TMP11]], align 4, !dbg [[DBG155:![0-9]+]] +// CHECK-DEBUG-NEXT: br label [[OMP_LOOP_INC194]], !dbg [[DBG149]] // CHECK-DEBUG: omp_loop.inc194: -// CHECK-DEBUG-NEXT: [[OMP_LOOP_NEXT199]] = add nuw i32 [[OMP_LOOP_IV197]], 1, !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: br label [[OMP_LOOP_HEADER191]], !dbg [[DBG147]] +// CHECK-DEBUG-NEXT: [[OMP_LOOP_NEXT199]] = add nuw i32 [[OMP_LOOP_IV197]], 1, !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: br label [[OMP_LOOP_HEADER191]], !dbg [[DBG149]] // CHECK-DEBUG: omp_loop.exit195: -// CHECK-DEBUG-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @[[GLOB42]], i32 [[OMP_GLOBAL_THREAD_NUM207]]), !dbg [[DBG147]] -// CHECK-DEBUG-NEXT: [[OMP_GLOBAL_THREAD_NUM208:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB42]]), !dbg [[DBG150]] -// CHECK-DEBUG-NEXT: call void @__kmpc_barrier(%struct.ident_t* @[[GLOB43:[0-9]+]], i32 [[OMP_GLOBAL_THREAD_NUM208]]), !dbg [[DBG150]] -// CHECK-DEBUG-NEXT: br label [[OMP_LOOP_AFTER196:%.*]], !dbg [[DBG147]] +// CHECK-DEBUG-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @[[GLOB42]], i32 [[OMP_GLOBAL_THREAD_NUM207]]), !dbg [[DBG149]] +// CHECK-DEBUG-NEXT: [[OMP_GLOBAL_THREAD_NUM208:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB42]]), !dbg [[DBG151]] +// CHECK-DEBUG-NEXT: call void @__kmpc_barrier(%struct.ident_t* @[[GLOB43:[0-9]+]], i32 [[OMP_GLOBAL_THREAD_NUM208]]), !dbg [[DBG151]] +// CHECK-DEBUG-NEXT: br label [[OMP_LOOP_AFTER196:%.*]], !dbg [[DBG149]] // CHECK-DEBUG: omp_loop.after196: -// CHECK-DEBUG-NEXT: ret void, !dbg [[DBG154:![0-9]+]] +// CHECK-DEBUG-NEXT: ret void, !dbg [[DBG156:![0-9]+]] // void parallel_for_2(float *r, int a, double b) { #pragma omp parallel diff --git a/clang/test/OpenMP/irbuilder_unroll_partial_factor_for.c b/clang/test/OpenMP/irbuilder_unroll_partial_factor_for.c --- a/clang/test/OpenMP/irbuilder_unroll_partial_factor_for.c +++ b/clang/test/OpenMP/irbuilder_unroll_partial_factor_for.c @@ -51,7 +51,7 @@ // CHECK-NEXT: store i32 %[[TMP8]], i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: store i32 1, i32* %[[P_STRIDE]], align 4 // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) -// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 1) +// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 0) // CHECK-NEXT: %[[TMP9:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 // CHECK-NEXT: %[[TMP10:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: %[[TMP11:.+]] = sub i32 %[[TMP10]], %[[TMP9]] diff --git a/clang/test/OpenMP/irbuilder_unroll_partial_heuristic_constant_for.c b/clang/test/OpenMP/irbuilder_unroll_partial_heuristic_constant_for.c --- a/clang/test/OpenMP/irbuilder_unroll_partial_heuristic_constant_for.c +++ b/clang/test/OpenMP/irbuilder_unroll_partial_heuristic_constant_for.c @@ -57,7 +57,7 @@ // CHECK-NEXT: store i32 %[[TMP7]], i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: store i32 1, i32* %[[P_STRIDE]], align 4 // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) -// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 1) +// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 0) // CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 // CHECK-NEXT: %[[TMP9:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: %[[TMP10:.+]] = sub i32 %[[TMP9]], %[[TMP8]] diff --git a/clang/test/OpenMP/irbuilder_unroll_partial_heuristic_runtime_for.c b/clang/test/OpenMP/irbuilder_unroll_partial_heuristic_runtime_for.c --- a/clang/test/OpenMP/irbuilder_unroll_partial_heuristic_runtime_for.c +++ b/clang/test/OpenMP/irbuilder_unroll_partial_heuristic_runtime_for.c @@ -59,7 +59,7 @@ // CHECK-NEXT: store i32 %[[TMP8]], i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: store i32 1, i32* %[[P_STRIDE]], align 4 // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) -// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 1) +// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 0) // CHECK-NEXT: %[[TMP9:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 // CHECK-NEXT: %[[TMP10:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: %[[TMP11:.+]] = sub i32 %[[TMP10]], %[[TMP9]] diff --git a/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c b/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c --- a/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c +++ b/clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c @@ -47,7 +47,7 @@ // CHECK-NEXT: store i32 %[[TMP7]], i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: store i32 1, i32* %[[P_STRIDE]], align 4 // CHECK-NEXT: %[[OMP_GLOBAL_THREAD_NUM:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @1) -// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 1) +// CHECK-NEXT: call void @__kmpc_for_static_init_4u(%struct.ident_t* @1, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 34, i32* %[[P_LASTITER]], i32* %[[P_LOWERBOUND]], i32* %[[P_UPPERBOUND]], i32* %[[P_STRIDE]], i32 1, i32 0) // CHECK-NEXT: %[[TMP8:.+]] = load i32, i32* %[[P_LOWERBOUND]], align 4 // CHECK-NEXT: %[[TMP9:.+]] = load i32, i32* %[[P_UPPERBOUND]], align 4 // CHECK-NEXT: %[[TMP10:.+]] = sub i32 %[[TMP9]], %[[TMP8]] diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h --- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -357,14 +357,6 @@ /// the current thread, updates the relevant instructions in the canonical /// loop and calls to an OpenMP runtime finalization function after the loop. /// - /// TODO: Workshare loops with static scheduling may contain up to two loops - /// that fulfill the requirements of an OpenMP canonical loop. One for - /// iterating over all iterations of a chunk and another one for iterating - /// over all chunks that are executed on the same thread. Returning - /// CanonicalLoopInfo objects representing them may eventually be useful for - /// the apply clause planned in OpenMP 6.0, but currently whether these are - /// canonical loops is irrelevant. - /// /// \param DL Debug location for instructions added for the /// workshare-loop construct itself. /// \param CLI A descriptor of the canonical loop to workshare. @@ -372,14 +364,30 @@ /// preheader of the loop. /// \param NeedsBarrier Indicates whether a barrier must be inserted after /// the loop. - /// \param Chunk The size of loop chunk considered as a unit when - /// scheduling. If \p nullptr, defaults to 1. /// /// \returns Point where to insert code after the workshare construct. InsertPointTy applyStaticWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, - bool NeedsBarrier, - Value *Chunk = nullptr); + bool NeedsBarrier); + + /// Modifies the canonical loop a statically-scheduled workshare loop with a + /// user-specified chunk size. + /// + /// \param DL Debug location for instructions added for the + /// workshare-loop construct itself. + /// \param CLI A descriptor of the canonical loop to workshare. + /// \param AllocaIP An insertion point for Alloca instructions usable in + /// the preheader of the loop. + /// \param NeedsBarrier Indicates whether a barrier must be inserted after the + /// loop. + /// \param ChunkSize The user-specified chunk size. + /// + /// \returns Point where to insert code after the workshare construct. + InsertPointTy applyStaticChunkedWorkshareLoop(DebugLoc DL, + CanonicalLoopInfo *CLI, + InsertPointTy AllocaIP, + bool NeedsBarrier, + Value *ChunkSize); /// Modifies the canonical loop to be a dynamically-scheduled workshare loop. /// @@ -416,6 +424,10 @@ /// the current thread, updates the relevant instructions in the canonical /// loop and calls to an OpenMP runtime finalization function after the loop. /// + /// The concrete transformation is done by applyStaticWorkshareLoop, + /// applyStaticChunkedWorkshareLoop, or applyDynamicWorkshareLoop, depending + /// on the value of \p SchedKind and \p ChunkSize. + /// /// \param DL Debug location for instructions added for the /// workshare-loop construct itself. /// \param CLI A descriptor of the canonical loop to workshare. @@ -423,10 +435,15 @@ /// preheader of the loop. /// \param NeedsBarrier Indicates whether a barrier must be insterted after /// the loop. + /// \param SchedKind Scheduling algorithm to use. + /// \param ChunkSize The chunk size for the inner loop. /// /// \returns Point where to insert code after the workshare construct. - InsertPointTy applyWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI, - InsertPointTy AllocaIP, bool NeedsBarrier); + InsertPointTy applyWorkshareLoop( + DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, + bool NeedsBarrier, + llvm::omp::ScheduleKind SchedKind = llvm::omp::OMP_SCHEDULE_Default, + Value *ChunkSize = nullptr); /// Tile a loop nest. /// @@ -1429,6 +1446,27 @@ /// Re-evaluated whether this makes sense. void collectControlBlocks(SmallVectorImpl &BBs); + /// Sets the number of loop iterations to the given value. This value must be + /// valid in the condition block (i.e., defined in the preheader) and is + /// interpreted as an unsigned integer. + void setTripCount(Value *TripCount); + + /// Replace all uses of the canonical induction variable in the loop body with + /// a new one. + /// + /// The intended use case is to update the induction variable for an updated + /// iteration space such that it can stay normalized in the 0...tripcount-1 + /// range. + /// + /// The \p Updater is called with the (presumable updated) current normalized + /// induction variable and is expected to return the value that uses of the + /// pre-updated induction values should use instead, typically dependent on + /// the new induction variable. This is a lambda (instead of e.g. just passing + /// the new value) to be able to distinguish the uses of the pre-updated + /// induction variable and uses of the induction varible to compute the + /// updated induction variable value. + void mapIndVar(llvm::function_ref Updater); + public: /// Returns whether this object currently represents the IR of a loop. If /// returning false, it may have been consumed by a loop transformation or not diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -59,6 +59,106 @@ "simplifications still taking place"), cl::init(1.5)); +/// Make \p Source branch to \p Target. +/// +/// Handles two situations: +/// * \p Source already has an unconditional branch. +/// * \p Source is a degenerate block (no terminator because the BB is +/// the current head of the IR construction). +static void redirectTo(BasicBlock *Source, BasicBlock *Target, DebugLoc DL) { + if (Instruction *Term = Source->getTerminator()) { + auto *Br = cast(Term); + assert(!Br->isConditional() && + "BB's terminator must be an unconditional branch (or degenerate)"); + BasicBlock *Succ = Br->getSuccessor(0); + Succ->removePredecessor(Source, /*KeepOneInputPHIs=*/true); + Br->setSuccessor(0, Target); + return; + } + + auto *NewBr = BranchInst::Create(Target, Source); + NewBr->setDebugLoc(DL); +} + +/// Move the instruction after an InsertPoint to the beginning of another +/// BasicBlock. +/// +/// The instructions after \p IP are moved to the beginning of \p New which must +/// not have any PHINodes. If \p CreateBranch is true, a branch instruction to +/// \p New will be added such that there is no semantic change. Otherwise, the +/// \p IP insert block remains degenerate and it is up to the caller to insert a +/// terminator. +static void spliceBB(OpenMPIRBuilder::InsertPointTy IP, BasicBlock *New, + bool CreateBranch) { + assert(New->getFirstInsertionPt() == New->begin() && + "Target BB must not have PHI nodes"); + + // Move instructions to new block. + BasicBlock *Old = IP.getBlock(); + New->getInstList().splice(New->begin(), Old->getInstList(), IP.getPoint(), + Old->end()); + + if (CreateBranch) + BranchInst::Create(New, Old); +} + +/// Splice a BasicBlock at an IRBuilder's current insertion point. Its new +/// insert location will stick to after the instruction before the insertion +/// point (instead of moving with the instruction the InsertPoint stores +/// internally). +static void spliceBB(IRBuilder<> &Builder, BasicBlock *New, bool CreateBranch) { + DebugLoc DebugLoc = Builder.getCurrentDebugLocation(); + BasicBlock *Old = Builder.GetInsertBlock(); + + spliceBB(Builder.saveIP(), New, CreateBranch); + if (CreateBranch) + Builder.SetInsertPoint(Old->getTerminator()); + else + Builder.SetInsertPoint(Old); + + // SetInsertPoint also updates the Builder's debug location, but we want to + // keep the one the Builder was configured to use. + Builder.SetCurrentDebugLocation(DebugLoc); +} + +/// Split a BasicBlock at an InsertPoint, even if the block is degenerate +/// (missing the terminator). +/// +/// llvm::SplitBasicBlock and BasicBlock::splitBasicBlock require a well-formed +/// BasicBlock. \p Name is used for the new successor block. If \p CreateBranch +/// is true, a branch to the new successor will new created such that +/// semantically there is no change; otherwise the block of the insertion point +/// remains degenerate and it is the caller's responsibility to insert a +/// terminator. Returns the new successor block. +static BasicBlock *splitBB(OpenMPIRBuilder::InsertPointTy IP, bool CreateBranch, + llvm::Twine Name = {}) { + BasicBlock *Old = IP.getBlock(); + BasicBlock *New = BasicBlock::Create( + Old->getContext(), Name.isTriviallyEmpty() ? Old->getName() : Name, + Old->getParent(), Old->getNextNode()); + spliceBB(IP, New, CreateBranch); + New->replaceSuccessorsPhiUsesWith(Old, New); + return New; +} + +/// Split a BasicBlock at \p Builder's insertion point, even if the block is +/// degenerate (missing the terminator). Its new insert location will stick to +/// after the instruction before the insertion point (instead of moving with the +/// instruction the InsertPoint stores internally). +static BasicBlock *splitBB(IRBuilder<> &Builder, bool CreateBranch, + llvm::Twine Name = {}) { + DebugLoc DebugLoc = Builder.getCurrentDebugLocation(); + BasicBlock *New = splitBB(Builder.saveIP(), CreateBranch, Name); + if (CreateBranch) + Builder.SetInsertPoint(Builder.GetInsertBlock()->getTerminator()); + else + Builder.SetInsertPoint(Builder.GetInsertBlock()); + // SetInsertPoint also updates the Builder's debug location, but we want to + // keep the one the Builder was configured to use. + Builder.SetCurrentDebugLocation(DebugLoc); + return New; +} + void OpenMPIRBuilder::addAttributes(omp::RuntimeFunction FnID, Function &Fn) { LLVMContext &Ctx = Fn.getContext(); @@ -1379,10 +1479,8 @@ // Split the loop at the insertion point: Branch to the preheader and move // every following instruction to after the loop (the After BB). Also, the // new successor is the loop's after block. + spliceBB(Builder, After, /*CreateBranch=*/false); Builder.CreateBr(CL->getPreheader()); - After->getInstList().splice(After->begin(), BB->getInstList(), - Builder.GetInsertPoint(), BB->end()); - After->replaceSuccessorsPhiUsesWith(BB, After); } // Emit the body content. We do it after connecting the loop to the CFG to @@ -1483,20 +1581,10 @@ llvm_unreachable("unknown OpenMP loop iterator bitwidth"); } -// Sets the number of loop iterations to the given value. This value must be -// valid in the condition block (i.e., defined in the preheader) and is -// interpreted as an unsigned integer. -void setCanonicalLoopTripCount(CanonicalLoopInfo *CLI, Value *TripCount) { - Instruction *CmpI = &CLI->getCond()->front(); - assert(isa(CmpI) && "First inst must compare IV with TripCount"); - CmpI->setOperand(1, TripCount); - CLI->assertOK(); -} - OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::applyStaticWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, - bool NeedsBarrier, Value *Chunk) { + bool NeedsBarrier) { assert(CLI->isValid() && "Requires a valid canonical loop"); // Set up the source location value for OpenMP runtime. @@ -1534,10 +1622,6 @@ Builder.CreateStore(UpperBound, PUpperBound); Builder.CreateStore(One, PStride); - // FIXME: schedule(static) is NOT the same as schedule(static,1) - if (!Chunk) - Chunk = One; - Value *ThreadNum = getOrCreateThreadID(SrcLoc); Constant *SchedulingType = @@ -1547,25 +1631,22 @@ // value it produced. Builder.CreateCall(StaticInit, {SrcLoc, ThreadNum, SchedulingType, PLastIter, PLowerBound, - PUpperBound, PStride, One, Chunk}); + PUpperBound, PStride, One, Zero}); Value *LowerBound = Builder.CreateLoad(IVTy, PLowerBound); Value *InclusiveUpperBound = Builder.CreateLoad(IVTy, PUpperBound); Value *TripCountMinusOne = Builder.CreateSub(InclusiveUpperBound, LowerBound); Value *TripCount = Builder.CreateAdd(TripCountMinusOne, One); - setCanonicalLoopTripCount(CLI, TripCount); + CLI->setTripCount(TripCount); // Update all uses of the induction variable except the one in the condition // block that compares it with the actual upper bound, and the increment in // the latch block. - // TODO: this can eventually move to CanonicalLoopInfo or to a new - // CanonicalLoopInfoUpdater interface. - Builder.SetInsertPoint(CLI->getBody(), CLI->getBody()->getFirstInsertionPt()); - Value *UpdatedIV = Builder.CreateAdd(IV, LowerBound); - IV->replaceUsesWithIf(UpdatedIV, [&](Use &U) { - auto *Instr = dyn_cast(U.getUser()); - return !Instr || - (Instr->getParent() != CLI->getCond() && - Instr->getParent() != CLI->getLatch() && Instr != UpdatedIV); + + CLI->mapIndVar([&](Instruction *OldIV) -> Value * { + Builder.SetInsertPoint(CLI->getBody(), + CLI->getBody()->getFirstInsertionPt()); + Builder.SetCurrentDebugLocation(DL); + return Builder.CreateAdd(OldIV, LowerBound); }); // In the "exit" block, call the "fini" function. @@ -1585,11 +1666,165 @@ return AfterIP; } +OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::applyStaticChunkedWorkshareLoop( + DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, + bool NeedsBarrier, Value *ChunkSize) { + assert(CLI->isValid() && "Requires a valid canonical loop"); + assert(ChunkSize && "Chunk size is required"); + + Value *IV = CLI->getIndVar(); + Value *OrigTripCount = CLI->getTripCount(); + Type *IVTy = IV->getType(); + Type *I32Type = Type::getInt32Ty(M.getContext()); + Constant *Zero = ConstantInt::get(IVTy, 0); + Constant *One = ConstantInt::get(IVTy, 1); + + // Declare useful OpenMP runtime functions. + FunctionCallee StaticInit = getKmpcForStaticInitForType(IVTy, M, *this); + FunctionCallee StaticFini = + getOrCreateRuntimeFunction(M, omp::OMPRTL___kmpc_for_static_fini); + + // Allocate space for computed loop bounds as expected by the "init" function. + Builder.restoreIP(AllocaIP); + Builder.SetCurrentDebugLocation(DL); + Value *PLastIter = Builder.CreateAlloca(I32Type, nullptr, "p.lastiter"); + Value *PLowerBound = Builder.CreateAlloca(IVTy, nullptr, "p.lowerbound"); + Value *PUpperBound = Builder.CreateAlloca(IVTy, nullptr, "p.upperbound"); + Value *PStride = Builder.CreateAlloca(IVTy, nullptr, "p.stride"); + + // Set up the source location value for the OpenMP runtime. + Builder.restoreIP(CLI->getPreheaderIP()); + Builder.SetCurrentDebugLocation(DL); + + // Call the "init" function and update the trip count of the loop with the + // value it produced. + uint32_t SrcLocStrSize; + Constant *SrcLocStr = getOrCreateSrcLocStr(DL, SrcLocStrSize); + Value *SrcLoc = getOrCreateIdent(SrcLocStr, SrcLocStrSize); + Value *ThreadNum = getOrCreateThreadID(SrcLoc); + Constant *SchedulingType = ConstantInt::get( + I32Type, static_cast(OMPScheduleType::StaticChunked)); + Builder.CreateStore(Zero, PLowerBound); + Value *OrigUpperBound = Builder.CreateSub(OrigTripCount, One); + Builder.CreateStore(OrigUpperBound, PUpperBound); + Builder.CreateStore(One, PStride); + Builder.CreateCall(StaticInit, + {/*loc=*/SrcLoc, /*global_tid=*/ThreadNum, + /*schedtype=*/SchedulingType, /*plastiter=*/PLastIter, + /*plower=*/PLowerBound, /*pupper=*/PUpperBound, + /*pstride=*/PStride, /*incr=*/One, /*chunk=*/ChunkSize}); + + // Load values written by the "init" function. + Value *FirstChunkStart = + Builder.CreateLoad(IVTy, PLowerBound, "omp_firstchunk.lb"); + Value *FirstChunkStop = + Builder.CreateLoad(IVTy, PUpperBound, "omp_firstchunk.ub"); + Value *FirstChunkEnd = + Builder.CreateAdd(FirstChunkStop, One); + Value *ChunkRange = + Builder.CreateSub(FirstChunkEnd, FirstChunkStart, "omp_chunk.range"); + Value *NextChunkStride = + Builder.CreateLoad(IVTy, PStride, "omp_dispatch.stride"); + + // Create outer "dispatch" loop for enumerating the chunks. + BasicBlock *DispatchEnter = splitBB(Builder, true); + Value *DispatchCounter; + CanonicalLoopInfo *DispatchCLI = createCanonicalLoop( + {Builder.saveIP(), DL}, + [&](InsertPointTy BodyIP, Value *Counter) { DispatchCounter = Counter; }, + FirstChunkStart, OrigTripCount, NextChunkStride, + /*IsSigned=*/false, /*InclusiveStop=*/false, /*ComputeIP=*/{}, + "dispatch"); + + // Remember the BasicBlocks of the dispatch loop we need, then invalidate to + // not have to preserve the canonical invariant. + BasicBlock *DispatchBody = DispatchCLI->getBody(); + BasicBlock *DispatchLatch = DispatchCLI->getLatch(); + BasicBlock *DispatchExit = DispatchCLI->getExit(); + BasicBlock *DispatchAfter = DispatchCLI->getAfter(); + DispatchCLI->invalidate(); + + // Rewire the original loop to become the chunk loop inside the dispatch loop. + redirectTo(DispatchAfter, CLI->getAfter(), DL); + redirectTo(CLI->getExit(), DispatchLatch, DL); + redirectTo(DispatchBody, DispatchEnter, DL); + + // Prepare the prolog of the chunk loop. + Builder.restoreIP(CLI->getPreheaderIP()); + Builder.SetCurrentDebugLocation(DL); + + // Compute the number of iterations of the chunk loop. + Builder.SetInsertPoint(CLI->getPreheader()->getTerminator()); + Value *ChunkEnd = Builder.CreateAdd(DispatchCounter, ChunkRange); + Value *IsLastChunk = + Builder.CreateICmpUGE(ChunkEnd, OrigTripCount, "omp_chunk.is_last"); + Value *CountUntilOrigTripCount = + Builder.CreateSub(OrigTripCount, DispatchCounter); + Value *ChunkTripCount = Builder.CreateSelect( + IsLastChunk, CountUntilOrigTripCount, ChunkRange, "omp_chunk.tripcount"); + CLI->setTripCount(ChunkTripCount); + + // Update all uses of the induction variable except the one in the condition + // block that compares it with the actual upper bound, and the increment in + // the latch block. + CLI->mapIndVar([&](Instruction *) -> Value * { + Builder.restoreIP(CLI->getBodyIP()); + return Builder.CreateAdd(IV, DispatchCounter); + }); + + // In the "exit" block, call the "fini" function. + Builder.SetInsertPoint(DispatchExit, DispatchExit->getFirstInsertionPt()); + Builder.CreateCall(StaticFini, {SrcLoc, ThreadNum}); + + // Add the barrier if requested. + if (NeedsBarrier) + createBarrier(LocationDescription(Builder.saveIP(), DL), OMPD_for, + /* ForceSimpleCall */ false, /* CheckCancelFlag */ false); + +#ifndef NDEBUG + // Even though we currently do not support applying additional methods to it, + // the chunk loop should remain a canonical loop. + CLI->assertOK(); +#endif + + return {DispatchAfter, DispatchAfter->getFirstInsertionPt()}; +} + OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::applyWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI, - InsertPointTy AllocaIP, bool NeedsBarrier) { - // Currently only supports static schedules. - return applyStaticWorkshareLoop(DL, CLI, AllocaIP, NeedsBarrier); + InsertPointTy AllocaIP, bool NeedsBarrier, + llvm::omp::ScheduleKind SchedKind, + llvm::Value *ChunkSize) { + switch (SchedKind) { + case llvm::omp::ScheduleKind ::OMP_SCHEDULE_Default: + assert(!ChunkSize && "No chunk size with default schedule (which for clang " + "is static non-chunked)"); + LLVM_FALLTHROUGH; + case llvm::omp::ScheduleKind ::OMP_SCHEDULE_Static: + if (ChunkSize) + return applyStaticChunkedWorkshareLoop(DL, CLI, AllocaIP, NeedsBarrier, + ChunkSize); + return applyStaticWorkshareLoop(DL, CLI, AllocaIP, NeedsBarrier); + case llvm::omp::ScheduleKind ::OMP_SCHEDULE_Auto: + assert(!ChunkSize && "Chunk size with auto scheduling not user-defined"); + return applyDynamicWorkshareLoop(DL, CLI, AllocaIP, OMPScheduleType::Auto, + NeedsBarrier, nullptr); + case llvm::omp::ScheduleKind ::OMP_SCHEDULE_Dynamic: + return applyDynamicWorkshareLoop(DL, CLI, AllocaIP, + OMPScheduleType::DynamicChunked, + NeedsBarrier, ChunkSize); + case llvm::omp::ScheduleKind ::OMP_SCHEDULE_Guided: + return applyDynamicWorkshareLoop(DL, CLI, AllocaIP, + OMPScheduleType::GuidedChunked, + NeedsBarrier, ChunkSize); + case llvm::omp::ScheduleKind ::OMP_SCHEDULE_Runtime: + assert(!ChunkSize && + "Chunk size with runtime scheduling implied to be one"); + return applyDynamicWorkshareLoop( + DL, CLI, AllocaIP, OMPScheduleType::Runtime, NeedsBarrier, nullptr); + } + + llvm_unreachable("Unknown/unimplemented schedule kind"); } /// Returns an LLVM function to call for initializing loop bounds using OpenMP @@ -1736,27 +1971,6 @@ return AfterIP; } -/// Make \p Source branch to \p Target. -/// -/// Handles two situations: -/// * \p Source already has an unconditional branch. -/// * \p Source is a degenerate block (no terminator because the BB is -/// the current head of the IR construction). -static void redirectTo(BasicBlock *Source, BasicBlock *Target, DebugLoc DL) { - if (Instruction *Term = Source->getTerminator()) { - auto *Br = cast(Term); - assert(!Br->isConditional() && - "BB's terminator must be an unconditional branch (or degenerate)"); - BasicBlock *Succ = Br->getSuccessor(0); - Succ->removePredecessor(Source, /*KeepOneInputPHIs=*/true); - Br->setSuccessor(0, Target); - return; - } - - auto *NewBr = BranchInst::Create(Target, Source); - NewBr->setDebugLoc(DL); -} - /// Redirect all edges that branch to \p OldTarget to \p NewTarget. That is, /// after this \p OldTarget will be orphaned. static void redirectAllPredecessorsTo(BasicBlock *OldTarget, @@ -3373,6 +3587,51 @@ llvm_unreachable("Missing preheader"); } +void CanonicalLoopInfo::setTripCount(Value *TripCount) { + assert(isValid() && "Requires a valid canonical loop"); + + Instruction *CmpI = &getCond()->front(); + assert(isa(CmpI) && "First inst must compare IV with TripCount"); + CmpI->setOperand(1, TripCount); + +#ifndef NDEBUG + assertOK(); +#endif +} + +void CanonicalLoopInfo::mapIndVar( + llvm::function_ref Updater) { + assert(isValid() && "Requires a valid canonical loop"); + + Instruction *OldIV = getIndVar(); + + // Record all uses excluding those introduced by the updater. Uses by the + // CanonicalLoopInfo itself to keep track of the number of iterations are + // excluded. + SmallVector ReplacableUses; + for (Use &U : OldIV->uses()) { + auto *User = dyn_cast(U.getUser()); + if (!User) + continue; + if (User->getParent() == getCond()) + continue; + if (User->getParent() == getLatch()) + continue; + ReplacableUses.push_back(&U); + } + + // Run the updater that may introduce new uses + Value *NewIV = Updater(OldIV); + + // Replace the old uses with the value returned by the updater. + for (Use *U : ReplacableUses) + U->set(NewIV); + +#ifndef NDEBUG + assertOK(); +#endif +} + void CanonicalLoopInfo::assertOK() const { #ifndef NDEBUG // No constraints if this object currently does not describe a loop. diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -113,6 +113,33 @@ << " in function " << F->getName(); } +/// Populate Calls with call instructions calling the function with the given +/// FnID from the given function F. +static void findCalls(Function *F, omp::RuntimeFunction FnID, + OpenMPIRBuilder &OMPBuilder, + SmallVectorImpl &Calls) { + Function *Fn = OMPBuilder.getOrCreateRuntimeFunctionPtr(FnID); + for (BasicBlock &BB : *F) { + for (Instruction &I : BB) { + auto *Call = dyn_cast(&I); + if (Call && Call->getCalledFunction() == Fn) + Calls.push_back(Call); + } + } +} + +/// Assuming \p F contains only one call to the function with the given \p FnID, +/// return that call. +static CallInst *findSingleCall(Function *F, omp::RuntimeFunction FnID, + OpenMPIRBuilder &OMPBuilder) { + SmallVector Calls; + findCalls(F, FnID, OMPBuilder, Calls); + EXPECT_EQ(1u, Calls.size()); + if (Calls.size() != 1) + return nullptr; + return Calls.front(); +} + class OpenMPIRBuilderTest : public testing::Test { protected: void SetUp() override { @@ -1839,6 +1866,67 @@ EXPECT_EQ(NumCallsInExitBlock, 3u); } +TEST_F(OpenMPIRBuilderTest, StaticChunkedWorkshareLoop) { + using InsertPointTy = OpenMPIRBuilder::InsertPointTy; + OpenMPIRBuilder OMPBuilder(*M); + + BasicBlock *Body; + CanonicalLoopInfo *CLI = + buildSingleLoopFunction(DL, OMPBuilder, nullptr, &Body); + + Type *LCTy = Type::getInt32Ty(Ctx); + Value *ChunkSize = ConstantInt::get(LCTy, 5); + InsertPointTy AllocaIP{&F->getEntryBlock(), + F->getEntryBlock().getFirstInsertionPt()}; + OMPBuilder.applyStaticChunkedWorkshareLoop(DL, CLI, AllocaIP, + /*NeedsBarrier=*/true, ChunkSize); + + OMPBuilder.finalize(); + EXPECT_FALSE(verifyModule(*M, &errs())); + + BasicBlock *Entry = &F->getEntryBlock(); + BasicBlock *Preheader = Entry->getSingleSuccessor(); + + BasicBlock *DispatchPreheader = Preheader->getSingleSuccessor(); + BasicBlock *DispatchHeader = DispatchPreheader->getSingleSuccessor(); + BasicBlock *DispatchCond = DispatchHeader->getSingleSuccessor(); + BasicBlock *DispatchBody = succ_begin(DispatchCond)[0]; + BasicBlock *DispatchExit = succ_begin(DispatchCond)[1]; + BasicBlock *DispatchAfter = DispatchExit->getSingleSuccessor(); + BasicBlock *Return = DispatchAfter->getSingleSuccessor(); + + BasicBlock *ChunkPreheader = DispatchBody->getSingleSuccessor(); + BasicBlock *ChunkHeader = ChunkPreheader->getSingleSuccessor(); + BasicBlock *ChunkCond = ChunkHeader->getSingleSuccessor(); + BasicBlock *ChunkBody = succ_begin(ChunkCond)[0]; + BasicBlock *ChunkExit = succ_begin(ChunkCond)[1]; + BasicBlock *ChunkInc = ChunkBody->getSingleSuccessor(); + BasicBlock *ChunkAfter = ChunkExit->getSingleSuccessor(); + + BasicBlock *DispatchInc = ChunkAfter; + + EXPECT_EQ(ChunkBody, Body); + EXPECT_EQ(ChunkInc->getSingleSuccessor(), ChunkHeader); + EXPECT_EQ(DispatchInc->getSingleSuccessor(), DispatchHeader); + + EXPECT_TRUE(isa(Return->front())); + + CallInst *InitCall = findSingleCall( + F, omp::RuntimeFunction::OMPRTL___kmpc_for_static_init_4u, OMPBuilder); + EXPECT_EQ(InitCall->getParent(), Preheader); + EXPECT_EQ(cast(InitCall->getArgOperand(2))->getSExtValue(), 33); + EXPECT_EQ(cast(InitCall->getArgOperand(7))->getSExtValue(), 1); + EXPECT_EQ(cast(InitCall->getArgOperand(8))->getSExtValue(), 5); + + CallInst *FiniCall = findSingleCall( + F, omp::RuntimeFunction::OMPRTL___kmpc_for_static_fini, OMPBuilder); + EXPECT_EQ(FiniCall->getParent(), DispatchExit); + + CallInst *BarrierCall = findSingleCall( + F, omp::RuntimeFunction::OMPRTL___kmpc_barrier, OMPBuilder); + EXPECT_EQ(BarrierCall->getParent(), DispatchExit); +} + TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) { using InsertPointTy = OpenMPIRBuilder::InsertPointTy; OpenMPIRBuilder OMPBuilder(*M); @@ -3056,21 +3144,6 @@ return Builder.saveIP(); } -/// Populate Calls with call instructions calling the function with the given -/// FnID from the given function F. -static void findCalls(Function *F, omp::RuntimeFunction FnID, - OpenMPIRBuilder &OMPBuilder, - SmallVectorImpl &Calls) { - Function *Fn = OMPBuilder.getOrCreateRuntimeFunctionPtr(FnID); - for (BasicBlock &BB : *F) { - for (Instruction &I : BB) { - auto *Call = dyn_cast(&I); - if (Call && Call->getCalledFunction() == Fn) - Calls.push_back(Call); - } - } -} - TEST_F(OpenMPIRBuilderTest, CreateReductions) { using InsertPointTy = OpenMPIRBuilder::InsertPointTy; OpenMPIRBuilder OMPBuilder(*M); diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -636,10 +636,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); @@ -760,8 +759,9 @@ bool isSimd = loop.simd_modifier(); if (schedule == omp::ClauseScheduleKind::Static) { - ompBuilder->applyStaticWorkshareLoop(ompLoc.DL, loopInfo, allocaIP, - !loop.nowait(), chunk); + ompBuilder->applyWorkshareLoop(ompLoc.DL, loopInfo, allocaIP, + !loop.nowait(), + llvm::omp::OMP_SCHEDULE_Static, chunk); } else { llvm::omp::OMPScheduleType schedType; switch (schedule) { diff --git a/mlir/test/Target/LLVMIR/openmp-llvm.mlir b/mlir/test/Target/LLVMIR/openmp-llvm.mlir --- a/mlir/test/Target/LLVMIR/openmp-llvm.mlir +++ b/mlir/test/Target/LLVMIR/openmp-llvm.mlir @@ -423,6 +423,53 @@ // ----- +llvm.func @body(i32) + +// CHECK-LABEL: @test_omp_wsloop_static_defchunk +llvm.func @test_omp_wsloop_static_defchunk(%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 0) + // CHECK: call void @__kmpc_for_static_fini + llvm.call @body(%iv) : (i32) -> () + omp.yield + } + llvm.return +} + +// ----- + +llvm.func @body(i32) + +// CHECK-LABEL: @test_omp_wsloop_static_1 +llvm.func @test_omp_wsloop_static_1(%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) + +// CHECK-LABEL: @test_omp_wsloop_static_2 +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) -> () {