[llvm] [AMDGPU] AMDGPULateCodeGenPrepare Legacy PM: replace `setPreservesAll()` with `setPreservesCFG()` (PR #148167)

Jim M. R. Teichgräber via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 12 11:18:30 PDT 2025


https://github.com/J-MR-T updated https://github.com/llvm/llvm-project/pull/148167

>From 90f1d0a881a21a8b4f192622d798c290770fda63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jim=20Teichgr=C3=A4ber?= <Jim.Teichgraber at amd.com>
Date: Fri, 11 Jul 2025 10:16:25 +0200
Subject: [PATCH 1/7] set legacy PM UniformityInfoWrapperPass isCFGOnly to
 false

---
 llvm/lib/Analysis/UniformityAnalysis.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Analysis/UniformityAnalysis.cpp b/llvm/lib/Analysis/UniformityAnalysis.cpp
index 2101fdfacfc8f..0daf4041a72f3 100644
--- a/llvm/lib/Analysis/UniformityAnalysis.cpp
+++ b/llvm/lib/Analysis/UniformityAnalysis.cpp
@@ -150,8 +150,11 @@ INITIALIZE_PASS_BEGIN(UniformityInfoWrapperPass, "uniformity",
 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(CycleInfoWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
+// Though Uniformity Analysis depends on the CFG,
+// it also needs to be invalidated if values are changed, so isCFGOnly: false.
+// See NOTE on updatability at the start of GenericUniformityImpl.h
 INITIALIZE_PASS_END(UniformityInfoWrapperPass, "uniformity",
-                    "Uniformity Analysis", true, true)
+                    "Uniformity Analysis", false, true)
 
 void UniformityInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.setPreservesAll();

>From fceacd0651bdba8b8381e448a9baaf9627627d98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jim=20Teichgr=C3=A4ber?= <Jim.Teichgraber at amd.com>
Date: Fri, 11 Jul 2025 16:37:13 +0200
Subject: [PATCH 2/7] also change isCFGOnly in BEGIN macro

---
 llvm/lib/Analysis/UniformityAnalysis.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Analysis/UniformityAnalysis.cpp b/llvm/lib/Analysis/UniformityAnalysis.cpp
index 0daf4041a72f3..772a1e50934f8 100644
--- a/llvm/lib/Analysis/UniformityAnalysis.cpp
+++ b/llvm/lib/Analysis/UniformityAnalysis.cpp
@@ -146,7 +146,7 @@ char UniformityInfoWrapperPass::ID = 0;
 UniformityInfoWrapperPass::UniformityInfoWrapperPass() : FunctionPass(ID) {}
 
 INITIALIZE_PASS_BEGIN(UniformityInfoWrapperPass, "uniformity",
-                      "Uniformity Analysis", true, true)
+                      "Uniformity Analysis", false, true)
 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(CycleInfoWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)

>From d64e5cbae75df840214e2d3917dddd84948f793f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jim=20Teichgr=C3=A4ber?= <Jim.Teichgraber at amd.com>
Date: Fri, 11 Jul 2025 16:37:26 +0200
Subject: [PATCH 3/7] [NFC] get rid of comment as discussed

---
 llvm/lib/Analysis/UniformityAnalysis.cpp | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/llvm/lib/Analysis/UniformityAnalysis.cpp b/llvm/lib/Analysis/UniformityAnalysis.cpp
index 772a1e50934f8..15107c262980c 100644
--- a/llvm/lib/Analysis/UniformityAnalysis.cpp
+++ b/llvm/lib/Analysis/UniformityAnalysis.cpp
@@ -150,9 +150,6 @@ INITIALIZE_PASS_BEGIN(UniformityInfoWrapperPass, "uniformity",
 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(CycleInfoWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
-// Though Uniformity Analysis depends on the CFG,
-// it also needs to be invalidated if values are changed, so isCFGOnly: false.
-// See NOTE on updatability at the start of GenericUniformityImpl.h
 INITIALIZE_PASS_END(UniformityInfoWrapperPass, "uniformity",
                     "Uniformity Analysis", false, true)
 

>From 5912dc6bcd8ec72545c712d024c3b75d06f7caa0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jim=20Teichgr=C3=A4ber?= <Jim.Teichgraber at amd.com>
Date: Fri, 11 Jul 2025 10:33:41 +0200
Subject: [PATCH 4/7] [AMDGPU] AMDGPULateCodeGenPrepare: legacy-pm replace
 setPreservesAll() with setPreservesCFG()

---
 llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp | 4 +++-
 llvm/test/CodeGen/AMDGPU/llc-pipeline.ll            | 4 ++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
index f0d63f523088b..b109fb73deaa5 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
@@ -546,7 +546,9 @@ class AMDGPULateCodeGenPrepareLegacy : public FunctionPass {
     AU.addRequired<TargetPassConfig>();
     AU.addRequired<AssumptionCacheTracker>();
     AU.addRequired<UniformityInfoWrapperPass>();
-    AU.setPreservesAll();
+    // makes changes that can invalidate Uniformity Analysis,
+    // so don't preserveAll here (see new PM version above)
+    AU.setPreservesCFG();
   }
 
   bool runOnFunction(Function &F) override;
diff --git a/llvm/test/CodeGen/AMDGPU/llc-pipeline.ll b/llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
index dd2ff2e013cc8..b23662c63338c 100644
--- a/llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ b/llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -255,6 +255,7 @@
 ; GCN-O1-NEXT:        Uniformity Analysis
 ; GCN-O1-NEXT:        AMDGPU IR late optimizations
 ; GCN-O1-NEXT:        Post-Dominator Tree Construction
+; GCN-O1-NEXT:        Uniformity Analysis
 ; GCN-O1-NEXT:        Unify divergent function exit nodes
 ; GCN-O1-NEXT:        Dominator Tree Construction
 ; GCN-O1-NEXT:        Cycle Info Analysis
@@ -557,6 +558,7 @@
 ; GCN-O1-OPTS-NEXT:        Uniformity Analysis
 ; GCN-O1-OPTS-NEXT:        AMDGPU IR late optimizations
 ; GCN-O1-OPTS-NEXT:        Post-Dominator Tree Construction
+; GCN-O1-OPTS-NEXT:        Uniformity Analysis
 ; GCN-O1-OPTS-NEXT:        Unify divergent function exit nodes
 ; GCN-O1-OPTS-NEXT:        Dominator Tree Construction
 ; GCN-O1-OPTS-NEXT:        Cycle Info Analysis
@@ -871,6 +873,7 @@
 ; GCN-O2-NEXT:        Uniformity Analysis
 ; GCN-O2-NEXT:        AMDGPU IR late optimizations
 ; GCN-O2-NEXT:        Post-Dominator Tree Construction
+; GCN-O2-NEXT:        Uniformity Analysis
 ; GCN-O2-NEXT:        Unify divergent function exit nodes
 ; GCN-O2-NEXT:        Dominator Tree Construction
 ; GCN-O2-NEXT:        Cycle Info Analysis
@@ -1200,6 +1203,7 @@
 ; GCN-O3-NEXT:        Uniformity Analysis
 ; GCN-O3-NEXT:        AMDGPU IR late optimizations
 ; GCN-O3-NEXT:        Post-Dominator Tree Construction
+; GCN-O3-NEXT:        Uniformity Analysis
 ; GCN-O3-NEXT:        Unify divergent function exit nodes
 ; GCN-O3-NEXT:        Dominator Tree Construction
 ; GCN-O3-NEXT:        Cycle Info Analysis

>From 196cbcf4f5b66a1dcb7acfb35d6ad3f83f4f32d8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jim=20Teichgr=C3=A4ber?= <Jim.Teichgraber at amd.com>
Date: Fri, 11 Jul 2025 13:02:34 +0200
Subject: [PATCH 5/7] [NFC] comments

---
 llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
index b109fb73deaa5..c0cacab434569 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
@@ -546,8 +546,8 @@ class AMDGPULateCodeGenPrepareLegacy : public FunctionPass {
     AU.addRequired<TargetPassConfig>();
     AU.addRequired<AssumptionCacheTracker>();
     AU.addRequired<UniformityInfoWrapperPass>();
-    // makes changes that can invalidate Uniformity Analysis,
-    // so don't preserveAll here (see new PM version above)
+    // This pass makes changes that can invalidate Uniformity Analysis,
+    // so don't setPreserveAll() here (see new PM version above).
     AU.setPreservesCFG();
   }
 

>From 9b816323f6824efb92117a78e432ab5f7ab61f3b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jim=20Teichgr=C3=A4ber?= <Jim.Teichgraber at amd.com>
Date: Fri, 11 Jul 2025 16:48:46 +0200
Subject: [PATCH 6/7] [NFC] adjust comment

---
 llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
index c0cacab434569..7ac43cf223c9b 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
@@ -547,7 +547,7 @@ class AMDGPULateCodeGenPrepareLegacy : public FunctionPass {
     AU.addRequired<AssumptionCacheTracker>();
     AU.addRequired<UniformityInfoWrapperPass>();
     // This pass makes changes that can invalidate Uniformity Analysis,
-    // so don't setPreserveAll() here (see new PM version above).
+    // so don't setPreserveAll() here.
     AU.setPreservesCFG();
   }
 

>From 5f558ec7663a8f3cfe9b86384f598cf21e39ce0e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jim=20M=2E=20R=2E=20Teichgr=C3=A4ber?=
 <Jim.Teichgraber at amd.com>
Date: Sat, 12 Jul 2025 19:18:18 +0100
Subject: [PATCH 7/7] [NFC] adjust comment, see review

---
 llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
index 7ac43cf223c9b..c545a32190b8d 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp
@@ -546,8 +546,6 @@ class AMDGPULateCodeGenPrepareLegacy : public FunctionPass {
     AU.addRequired<TargetPassConfig>();
     AU.addRequired<AssumptionCacheTracker>();
     AU.addRequired<UniformityInfoWrapperPass>();
-    // This pass makes changes that can invalidate Uniformity Analysis,
-    // so don't setPreserveAll() here.
     AU.setPreservesCFG();
   }
 



More information about the llvm-commits mailing list