[PATCH] D144298: [Local][SimplifyCFG] Handle !nontemporal in combineMetadata

Daniel Woodworth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 17 13:44:24 PST 2023


dwoodwor-intel created this revision.
dwoodwor-intel added reviewers: nikic, StephenFan.
Herald added a subscriber: hiraditya.
Herald added a project: All.
dwoodwor-intel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

SimplifyCFG currently drops !nontemporal metadata when sinking common instructions. With this change, SimplifyCFG and similar transforms will preserve !nontemporal metadata as long as it is set on both original instructions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144298

Files:
  llvm/lib/Transforms/Utils/Local.cpp
  llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll


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}
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);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144298.498496.patch
Type: text/x-patch
Size: 2574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230217/1b62882b/attachment-0001.bin>


More information about the llvm-commits mailing list