[NFC] Refactor loop metadata movement
authorNathan Sidwell <nathan@acm.org>
Fri, 5 May 2023 15:58:54 +0000 (11:58 -0400)
committerNathan Sidwell <nathan@acm.org>
Tue, 9 May 2023 22:43:59 +0000 (18:43 -0400)
* Use 'if (T v = expr)' idiom
* llvm.loop is a fixed metadata ID

Differential Revision: https://reviews.llvm.org/D150109

Reviewed By: kazu

llvm/lib/Transforms/Utils/Local.cpp

index 0f5d2ce..5f89c06 100644 (file)
@@ -1223,12 +1223,10 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
 
   // 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);