[llvm] [DFAJumpThreading] Set MadeChanges only if threading happened (PR #162241)

Hongyu Chen via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 7 01:22:31 PDT 2025


https://github.com/XChy created https://github.com/llvm/llvm-project/pull/162241

Threading may fail due to legality and profitability checks. This patch preserves the analysis if no threading happens.

>From 0cb12b65e43b53d0ac491ba26caf611e89b7ca78 Mon Sep 17 00:00:00 2001
From: XChy <xxs_chy at outlook.com>
Date: Tue, 7 Oct 2025 16:20:06 +0800
Subject: [PATCH] [DFAJumpThreading] Set MadeChanges only if threading happened

---
 llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
index 41a6c80943328..83def24eeaba6 100644
--- a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
@@ -820,11 +820,14 @@ struct TransformDFA {
       : SwitchPaths(SwitchPaths), DT(DT), AC(AC), TTI(TTI), ORE(ORE),
         EphValues(EphValues) {}
 
-  void run() {
+  bool run() {
+    bool MadeChange = false;
     if (isLegalAndProfitableToTransform()) {
       createAllExitPaths();
+      MadeChange = true;
       NumTransforms++;
     }
+    return MadeChange;
   }
 
 private:
@@ -1426,9 +1429,8 @@ bool DFAJumpThreading::run(Function &F) {
 
   for (AllSwitchPaths SwitchPaths : ThreadableLoops) {
     TransformDFA Transform(&SwitchPaths, DT, AC, TTI, ORE, EphValues);
-    Transform.run();
-    MadeChanges = true;
-    LoopInfoBroken = true;
+    if (Transform.run())
+      MadeChanges = LoopInfoBroken = true;
   }
 
 #ifdef EXPENSIVE_CHECKS



More information about the llvm-commits mailing list