Index: llvm/lib/Transforms/Utils/Local.cpp =================================================================== --- llvm/lib/Transforms/Utils/Local.cpp +++ llvm/lib/Transforms/Utils/Local.cpp @@ -2724,6 +2724,10 @@ if (DoesKMove) K->setMetadata(Kind, JMD); break; + case LLVMContext::MD_nontemporal: + // Preserve !nontemporal if it is present on both instructions. + K->setMetadata(Kind, JMD); + break; } } // Set !invariant.group from J if J has it. If both instructions have it @@ -2746,7 +2750,8 @@ LLVMContext::MD_invariant_group, LLVMContext::MD_align, LLVMContext::MD_dereferenceable, LLVMContext::MD_dereferenceable_or_null, - LLVMContext::MD_access_group, LLVMContext::MD_preserve_access_index}; + LLVMContext::MD_access_group, LLVMContext::MD_preserve_access_index, + LLVMContext::MD_nontemporal}; combineMetadata(K, J, KnownIDs, KDominatesJ); } @@ -2831,7 +2836,7 @@ LLVMContext::MD_fpmath, LLVMContext::MD_invariant_load, LLVMContext::MD_invariant_group, LLVMContext::MD_nonnull, LLVMContext::MD_access_group, LLVMContext::MD_preserve_access_index, - LLVMContext::MD_noundef}; + LLVMContext::MD_noundef, LLVMContext::MD_nontemporal}; combineMetadata(ReplInst, I, KnownIDs, false); } Index: llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll =================================================================== --- llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll +++ llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll @@ -1559,3 +1559,47 @@ end: ret void } + +define void @nontemporal(ptr %ptr, i1 %cond) { +; CHECK-LABEL: @nontemporal( +; CHECK-NEXT: entry: +; CHECK-NEXT: store i64 0, ptr [[PTR:%.*]], align 8, !nontemporal !7 +; CHECK-NEXT: ret void +; +entry: + br i1 %cond, label %if.then, label %if.else + +if.then: + store i64 0, ptr %ptr, align 8, !nontemporal !12 + br label %if.end + +if.else: + store i64 0, ptr %ptr, align 8, !nontemporal !12 + br label %if.end + +if.end: + ret void +} + +define void @nontemporal_mismatch(ptr %ptr, i1 %cond) { +; CHECK-LABEL: @nontemporal_mismatch( +; CHECK-NEXT: entry: +; CHECK-NEXT: store i64 0, ptr [[PTR:%.*]], align 8 +; CHECK-NEXT: ret void +; +entry: + br i1 %cond, label %if.then, label %if.else + +if.then: + store i64 0, ptr %ptr, align 8, !nontemporal !12 + br label %if.end + +if.else: + store i64 0, ptr %ptr, align 8 + br label %if.end + +if.end: + ret void +} + +!12 = !{i32 1}