Index: lib/Basic/Targets.cpp =================================================================== --- lib/Basic/Targets.cpp +++ lib/Basic/Targets.cpp @@ -618,6 +618,9 @@ if (!Target->handleTargetFeatures(Opts->Features, Diags)) return nullptr; + // Sort the features. + std::sort(Opts->Features.begin(), Opts->Features.end()); + Target->setSupportedOpenCLOpts(); Target->setOpenCLExtensionOpts(); Target->setMaxAtomicWidth(); Index: lib/Basic/Targets/AMDGPU.cpp =================================================================== --- lib/Basic/Targets/AMDGPU.cpp +++ lib/Basic/Targets/AMDGPU.cpp @@ -226,6 +226,9 @@ // Always do not flush fp64 or fp16 denorms. if (!hasFP64Denormals && hasFP64) TargetOpts.Features.push_back("+fp64-fp16-denormals"); + + // Re-sort the features for CodeGen. + std::sort(TargetOpts.Features.begin(), TargetOpts.Features.end()); } AMDGPUTargetInfo::GPUKind AMDGPUTargetInfo::parseR600Name(StringRef Name) { Index: lib/CodeGen/CGCall.cpp =================================================================== --- lib/CodeGen/CGCall.cpp +++ lib/CodeGen/CGCall.cpp @@ -1909,11 +1909,13 @@ } else { // Otherwise just add the existing target cpu and target features to the // function. - std::vector &Features = getTarget().getTargetOpts().Features; + const std::vector &Features = + getTarget().getTargetOpts().Features; if (TargetCPU != "") FuncAttrs.addAttribute("target-cpu", TargetCPU); if (!Features.empty()) { - std::sort(Features.begin(), Features.end()); + assert(std::is_sorted(Features.begin(), Features.end()) && + "Features not sorted?"); FuncAttrs.addAttribute( "target-features", llvm::join(Features, ","));