diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -672,6 +672,15 @@ if (op.getSection().hasValue()) var->setSection(*op.getSection()); + auto TargetTriple = llvm::Triple(llvmModule->getTargetTriple()); + if (var->isWeakForLinker() && !var->hasCommonLinkage() && + TargetTriple.isOSBinFormatCOFF()) { + auto *C = llvmModule->getOrInsertComdat(var->getName()); + if (!var->isInterposable()) + C->setSelectionKind(llvm::Comdat::ExactMatch); + var->setComdat(C); + } + addRuntimePreemptionSpecifier(op.getDsoLocal(), var); Optional alignment = op.getAlignment();