[PATCH] D150109: [NFC] Refactor loop metadata movemen

Nathan Sidwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 8 03:58:53 PDT 2023


urnathan created this revision.
urnathan added reviewers: rnk, hfinkel, Florian, kazu.
Herald added subscribers: hoy, hiraditya.
Herald added a project: All.
urnathan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

I happened to touch this code locally and noticed a couple of things:

1. Let's use 'if (T var = expr)' form
2. llvm.loop is one of the fixed metadata ids, let's just use that

Both #1 and #2 are used for elsewhere in the function for these exact accesses.


https://reviews.llvm.org/D150109

Files:
  llvm/lib/Transforms/Utils/Local.cpp


Index: llvm/lib/Transforms/Utils/Local.cpp
===================================================================
--- llvm/lib/Transforms/Utils/Local.cpp
+++ llvm/lib/Transforms/Utils/Local.cpp
@@ -1223,12 +1223,10 @@
 
   // If the unconditional branch we replaced contains llvm.loop metadata, we
   // add the metadata to the branch instructions in the predecessors.
-  unsigned LoopMDKind = BB->getContext().getMDKindID("llvm.loop");
-  Instruction *TI = BB->getTerminator();
-  if (TI)
-    if (MDNode *LoopMD = TI->getMetadata(LoopMDKind))
+  if (Instruction *TI = BB->getTerminator())
+    if (MDNode *LoopMD = TI->getMetadata(LLVMContext::MD_loop))
       for (BasicBlock *Pred : predecessors(BB))
-        Pred->getTerminator()->setMetadata(LoopMDKind, LoopMD);
+        Pred->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopMD);
 
   // Everything that jumped to BB now goes to Succ.
   BB->replaceAllUsesWith(Succ);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150109.520323.patch
Type: text/x-patch
Size: 930 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230508/cdfe7f6f/attachment.bin>


More information about the llvm-commits mailing list