Index: clang/lib/CodeGen/CGStmtOpenMP.cpp =================================================================== --- clang/lib/CodeGen/CGStmtOpenMP.cpp +++ clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -2593,9 +2593,12 @@ static bool isSupportedByOpenMPIRBuilder(const OMPExecutableDirective &S) { // Check for unsupported clauses - if (!S.clauses().empty()) { - // Currently no clause is supported - return false; + for (OMPClause *C : S.clauses()) { + // Currently only simdlen clause is supported + if (dyn_cast(C)) + continue; + else + return false; } // Check if we have a statement with the ordered directive. @@ -2639,6 +2642,13 @@ CGM.getOpenMPRuntime().getOMPBuilder(); // Add SIMD specific metadata OMPBuilder.applySimd(DL, CLI); + if (const auto *C = S.getSingleClause()) { + RValue Len = + this->EmitAnyExpr(C->getSimdlen(), AggValueSlot::ignored(), + /*ignoreResult=*/true); + auto *Val = cast(Len.getScalarVal()); + OMPBuilder.applySimdlen(DL, CLI, Val); + } return; } }; Index: clang/test/OpenMP/irbuilder_simd.cpp =================================================================== --- clang/test/OpenMP/irbuilder_simd.cpp +++ clang/test/OpenMP/irbuilder_simd.cpp @@ -12,7 +12,7 @@ void simple(float *a, float *b, int *c) { S s, *p; P pp; -#pragma omp simd +#pragma omp simd simdlen(3) for (int i = 3; i < 32; i += 5) { // llvm.access.group test // CHECK: %[[A_ADDR:.+]] = alloca float*, align 8 @@ -49,23 +49,24 @@ for (int j = 3; j < 32; j += 5) { // test if unique access groups were used for a second loop // CHECK: %[[A22:.+]] = getelementptr inbounds %struct.P, %struct.P* %[[PP:.+]], i32 0, i32 0 - // CHECK-NEXT: %[[TMP14:.+]] = load i32, i32* %[[A22:.+]], align 4, !llvm.access.group ![[META7:[0-9]+]] - // CHECK-NEXT: %[[TMP15:.+]] = load i32*, i32** %[[C_ADDR:.+]], align 8, !llvm.access.group ![[META7:[0-9]+]] - // CHECK-NEXT: %[[TMP16:.+]] = load i32, i32* %[[J:.+]], align 4, !llvm.access.group ![[META7:[0-9]+]] + // CHECK-NEXT: %[[TMP14:.+]] = load i32, i32* %[[A22:.+]], align 4, !llvm.access.group ![[META8:[0-9]+]] + // CHECK-NEXT: %[[TMP15:.+]] = load i32*, i32** %[[C_ADDR:.+]], align 8, !llvm.access.group ![[META8:[0-9]+]] + // CHECK-NEXT: %[[TMP16:.+]] = load i32, i32* %[[J:.+]], align 4, !llvm.access.group ![[META8:[0-9]+]] // CHECK-NEXT: %[[IDXPROM23:.+]] = sext i32 %[[TMP16:.+]] to i64 // CHECK-NEXT: %[[ARRAYIDX24:.+]] = getelementptr inbounds i32, i32* %[[TMP15:.+]], i64 %[[IDXPROM23:.+]] - // CHECK-NEXT: store i32 %[[TMP14:.+]], i32* %[[ARRAYIDX24:.+]], align 4, !llvm.access.group ![[META7:[0-9]+]] + // CHECK-NEXT: store i32 %[[TMP14:.+]], i32* %[[ARRAYIDX24:.+]], align 4, !llvm.access.group ![[META8:[0-9]+]] // check llvm.loop metadata // CHECK: %[[OMP_LOOPDOTNEXT:.+]] = add nuw i32 %[[OMP_LOOPDOTIV:.+]], 1 - // CHECK-NEXT: br label %[[OMP_LLOP_BODY:.*]], !llvm.loop ![[META8:[0-9]+]] + // CHECK-NEXT: br label %[[OMP_LLOP_BODY:.*]], !llvm.loop ![[META9:[0-9]+]] c[j] = pp.a; } } // CHECK: ![[META3:[0-9]+]] = distinct !{} -// CHECK-NEXT: ![[META4]] = distinct !{![[META4]], ![[META5:[0-9]+]], ![[META6:[0-9]+]]} +// CHECK-NEXT: ![[META4]] = distinct !{![[META4]], ![[META5:[0-9]+]], ![[META6:[0-9]+]], ![[META7:[0-9]+]]} // CHECK-NEXT: ![[META5]] = !{!"llvm.loop.parallel_accesses", ![[META3]]} // CHECK-NEXT: ![[META6]] = !{!"llvm.loop.vectorize.enable", i1 true} -// CHECK-NEXT: ![[META7:[0-9]+]] = distinct !{} -// CHECK-NEXT: ![[META8]] = distinct !{![[META8]], ![[META9:[0-9]+]], ![[META6]]} -// CHECK-NEXT: ![[META9]] = !{!"llvm.loop.parallel_accesses", ![[META7]]} \ No newline at end of file +// CHECK-NEXT: ![[META7]] = !{!"llvm.loop.vectorize.width", i32 3} +// CHECK-NEXT: ![[META8:[0-9]+]] = distinct !{} +// CHECK-NEXT: ![[META9]] = distinct !{![[META9]], ![[META10:[0-9]+]], ![[META6]]} +// CHECK-NEXT: ![[META10]] = !{!"llvm.loop.parallel_accesses", ![[META8]]} \ No newline at end of file Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h =================================================================== --- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -603,6 +603,14 @@ /// \param Loop The loop to simd-ize. void applySimd(DebugLoc DL, CanonicalLoopInfo *Loop); + /// Add metadata for simdlen to a simd loop. + /// + /// \param DL Debug location for instructions added by unrolling. + /// \param Loop The loop to simd-ize. + /// \param Simdlen The Simdlen length to apply to the simd loop. + void applySimdlen(DebugLoc DL, CanonicalLoopInfo *Loop, + llvm::ConstantInt *Simdlen); + /// Generator for '#omp flush' /// /// \param Loc The location where the flush directive was encountered Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp =================================================================== --- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -2881,6 +2881,15 @@ BoolConst})}); } +void OpenMPIRBuilder::applySimdlen(DebugLoc, CanonicalLoopInfo *CanonicalLoop, + llvm::ConstantInt *Simdlen) { + LLVMContext &Ctx = Builder.getContext(); + addLoopMetadata( + CanonicalLoop, + MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.vectorize.width"), + ConstantAsMetadata::get(Simdlen)})); +} + /// Create the TargetMachine object to query the backend for optimization /// preferences. /// Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp =================================================================== --- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -1770,6 +1770,7 @@ // Simd-ize the loop. OMPBuilder.applySimd(DL, CLI); + OMPBuilder.applySimdlen(DL, CLI, ConstantInt::get(Type::getInt32Ty(Ctx), 3)); OMPBuilder.finalize(); EXPECT_FALSE(verifyModule(*M, &errs())); @@ -1785,6 +1786,7 @@ Loop *L = TopLvl.front(); EXPECT_TRUE(findStringMetadataForLoop(L, "llvm.loop.parallel_accesses")); EXPECT_TRUE(getBooleanLoopAttribute(L, "llvm.loop.vectorize.enable")); + EXPECT_EQ(getIntLoopAttribute(L, "llvm.loop.vectorize.width"), 3); // Check for llvm.access.group metadata attached to the printf // function in the loop body.