Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -80,6 +80,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" +#include "llvm/Frontend/OpenMP/OMPIRBuilder.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" @@ -94,6 +95,7 @@ #include #include #include +#include #include #include #include @@ -2496,7 +2498,15 @@ } unsigned ASTContext::getOpenMPDefaultSimdAlign(QualType T) const { - unsigned SimdAlign = getTargetInfo().getSimdDefaultAlign(); + std::vector TargetFeatures = Target->getTargetOpts().Features; + std::string TargetFeaturesString = + std::accumulate(TargetFeatures.begin(), TargetFeatures.end(), + std::string(), [](std::string &s1, std::string &s2) { + return s1.empty() ? s2 : s1 + "," + s2; + }); + unsigned SimdAlign = llvm::OpenMPIRBuilder ::getDefaultTargetSimdAlignment( + getTargetInfo().getTriple().str(), Target->getTargetOpts().CPU, + TargetFeaturesString); return SimdAlign; } Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h =================================================================== --- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -402,6 +402,9 @@ CanonicalLoopInfo *collapseLoops(DebugLoc DL, ArrayRef Loops, InsertPointTy ComputeIP); + static unsigned getDefaultTargetSimdAlignment(const std::string &Triple, + StringRef CPU, + StringRef Features); private: /// Modifies the canonical loop to be a statically-scheduled workshare loop. Index: llvm/include/llvm/Target/TargetMachine.h =================================================================== --- llvm/include/llvm/Target/TargetMachine.h +++ llvm/include/llvm/Target/TargetMachine.h @@ -107,6 +107,9 @@ std::unique_ptr MII; std::unique_ptr STI; + /// OpenMP Target Specific information + unsigned OpenMPSimdDefaultAlignment = 0; + unsigned RequireStructuredCFG : 1; unsigned O0WantsFastISel : 1; @@ -196,6 +199,10 @@ return DL.getPointerSize(DL.getAllocaAddrSpace()); } + unsigned getSimdDefaultAlignment() const { + return OpenMPSimdDefaultAlignment; + } + /// Reset the target options based on the function's attributes. // FIXME: Remove TargetOptions that affect per-function code generation // from TargetMachine. Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp =================================================================== --- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -3061,6 +3061,22 @@ Builder.CreateBr(NewBlocks.front()); } +unsigned OpenMPIRBuilder::getDefaultTargetSimdAlignment( + const std::string &Triple, StringRef CPU, StringRef Features) { + + std::string Error; + const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error); + if (!TheTarget) { + return {}; + } + + llvm::TargetOptions Options; + std::unique_ptr TgtInfo(TheTarget->createTargetMachine( + Triple, CPU, Features, Options, None, None, CodeGenOpt::Default)); + + return TgtInfo->getSimdDefaultAlignment(); +} + void OpenMPIRBuilder::applySimd(CanonicalLoopInfo *CanonicalLoop, MapVector AlignedVars, Value *IfCond, OrderKind Order, Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp =================================================================== --- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp +++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp @@ -334,6 +334,7 @@ TLOF(createTLOF(getTargetTriple())), TargetABI(computeTargetABI(TT, Options)), Endianness(isLittleEndianTriple(TT) ? Endian::LITTLE : Endian::BIG) { + OpenMPSimdDefaultAlignment = 16; initAsmInfo(); } Index: llvm/lib/Target/X86/X86TargetMachine.cpp =================================================================== --- llvm/lib/Target/X86/X86TargetMachine.cpp +++ llvm/lib/Target/X86/X86TargetMachine.cpp @@ -243,6 +243,13 @@ setSupportsDebugEntryValues(true); initAsmInfo(); + + if (FS.contains("+avx512f")) + OpenMPSimdDefaultAlignment = 512; + else if (FS.contains("+avx")) + OpenMPSimdDefaultAlignment = 256; + else + OpenMPSimdDefaultAlignment = 128; } X86TargetMachine::~X86TargetMachine() = default;