[llvm] [NFC] Move RemoveRedundantDbgInstrs outside of inner loop in JumpThreading (PR #123008)

William Huang via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 16 15:33:18 PST 2025


https://github.com/huangjd updated https://github.com/llvm/llvm-project/pull/123008

>From 8aecbedfe3cd2df357007b498f861a3210b2685d Mon Sep 17 00:00:00 2001
From: William Huang <williamjhuang at google.com>
Date: Tue, 14 Jan 2025 22:46:02 -0500
Subject: [PATCH 1/2] [NFC] Move RemoveRedundantDbgInstrs outside of inner loop
 in JumpThreading

This cleanup action only needs to be performed once when the entire optimization
is converged. Doing it in every iteration has a very high
time-complexity.
---
 llvm/lib/Transforms/Scalar/JumpThreading.cpp | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 300a564e222e16..aae54d9763789b 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -330,11 +330,6 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
       while (processBlock(&BB)) // Thread all of the branches we can over BB.
         Changed = ChangedSinceLastAnalysisUpdate = true;
 
-      // Jump threading may have introduced redundant debug values into BB
-      // which should be removed.
-      if (Changed)
-        RemoveRedundantDbgInstrs(&BB);
-
       // Stop processing BB if it's the entry or is now deleted. The following
       // routines attempt to eliminate BB and locating a suitable replacement
       // for the entry is non-trivial.
@@ -366,7 +361,6 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
             // detect and transform nested loops later.
             !LoopHeaders.count(&BB) && !LoopHeaders.count(Succ) &&
             TryToSimplifyUncondBranchFromEmptyBlock(&BB, DTU.get())) {
-          RemoveRedundantDbgInstrs(Succ);
           // BB is valid for cleanup here because we passed in DTU. F remains
           // BB's parent until a DTU->getDomTree() event.
           LVI->eraseBlock(&BB);
@@ -377,6 +371,13 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
     EverChanged |= Changed;
   } while (Changed);
 
+  // Jump threading may have introduced redundant debug values into BB which
+  // should be removed.
+  if (EverChanged)
+    for (auto &BB : *F) {
+      RemoveRedundantDbgInstrs(&BB);
+    }
+
   LoopHeaders.clear();
   return EverChanged;
 }

>From 4becdbd8d5305aa349f91e21c0e7818a01ad7481 Mon Sep 17 00:00:00 2001
From: William Huang <williamjhuang at google.com>
Date: Thu, 16 Jan 2025 18:33:03 -0500
Subject: [PATCH 2/2] Updated test case, now cleanup redundant dbg value
 happens once at the end of jump threading, so duplicated dbg values from
 block duplication can be removed

---
 llvm/test/Transforms/JumpThreading/thread-debug-info.ll | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/llvm/test/Transforms/JumpThreading/thread-debug-info.ll b/llvm/test/Transforms/JumpThreading/thread-debug-info.ll
index 4727413b35a60b..fcdeee6d1422cb 100644
--- a/llvm/test/Transforms/JumpThreading/thread-debug-info.ll
+++ b/llvm/test/Transforms/JumpThreading/thread-debug-info.ll
@@ -92,10 +92,6 @@ exit:                                             ; preds = %bb.f4, %bb.f3, %bb.
   ret void, !dbg !29
 }
 
-; Test for the cloning of dbg.values on elided instructions -- down one path
-; being threaded, the `and` in the function below is optimised away, but its
-; debug-info should still be preserved.
-; Similarly, the call to f1 gets cloned, its dbg.value should be cloned too.
 define void @test16(i1 %c, i1 %c2, i1 %c3, i1 %c4) nounwind ssp !dbg !30 {
 ; CHECK-LABEL: define void @test16(i1
 entry:
@@ -109,7 +105,6 @@ lor.lhs.false.i:
   br i1 %c3, label %land.end, label %land.end, !dbg !33
 
 ; CHECK-LABEL: land.end.thr_comm:
-; CHECK-NEXT:  #dbg_value(i32 0,
 ; CHECK-NEXT:  #dbg_value(i32 1,
 ; CHECK-NEXT:  call void @f1()
 ; CHECK-NEXT:  br i1 %c4,



More information about the llvm-commits mailing list