[PATCH] D155214: Preserve important metadata in JumpThreadingPass::unfoldSelectInstr

Mark Mendell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 13 09:57:20 PDT 2023


mmendell updated this revision to Diff 540093.
mmendell added a comment.

ran git clang-format


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155214/new/

https://reviews.llvm.org/D155214

Files:
  llvm/lib/Transforms/Scalar/JumpThreading.cpp
  llvm/test/Transforms/JumpThreading/preserve-select-unfold.ll


Index: llvm/test/Transforms/JumpThreading/preserve-select-unfold.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/JumpThreading/preserve-select-unfold.ll
@@ -0,0 +1,30 @@
+; RUN: opt -passes=jump-threading -S < %s | FileCheck %s
+; Ensure that we preserve llvm.loop information
+target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
+target triple = "spir64-unknown-unknown-intelfpga"
+
+define spir_kernel void @test(i1 %Input) {
+entry:
+  br label %A
+
+; CHECK-LAB: select.unfold:
+; CHECK: br label %A, !llvm.loop ![[INFO:.*]]
+
+; CHECK-LAB: A:
+A:
+  %current_state.0.i.i = phi i32 [ 0, %entry ], [ %X, %M ]
+  %B = icmp eq i32 %current_state.0.i.i, 0
+  br i1 %B, label %M, label %B2
+
+B2:
+  ret void
+
+M:
+  %X = select i1 %Input, i32 2, i32 0
+  br label %A, !llvm.loop !0
+}
+
+; CHECK: ![[INFO]] = distinct !{![[INFO]], ![[LINFO:.*]]}
+!0 = distinct !{!0, !1}
+; CHECK: ![[LINFO]] = !{!"llvm.loop.ii.count", i32 1}
+!1 = !{!"llvm.loop.ii.count", i32 1}
Index: llvm/lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -2728,6 +2728,9 @@
   auto *BI = BranchInst::Create(NewBB, BB, SI->getCondition(), Pred);
   BI->applyMergedLocation(PredTerm->getDebugLoc(), SI->getDebugLoc());
   BI->copyMetadata(*SI, {LLVMContext::MD_prof});
+  // Also preserve the metadata from the branch
+  BI->copyMetadata(*PredTerm,
+                   {LLVMContext::MD_loop, LLVMContext::MD_annotation});
   SIUse->setIncomingValue(Idx, SI->getFalseValue());
   SIUse->addIncoming(SI->getTrueValue(), NewBB);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155214.540093.patch
Type: text/x-patch
Size: 1772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230713/79180815/attachment.bin>


More information about the llvm-commits mailing list