Skip to content

Commit 962bef6

Browse files
J-MR-Tgithub-actions[bot]
authored andcommitted
Automerge: [AMDGPU] AMDGPULateCodeGenPrepare Legacy PM: replace setPreservesAll() with setPreservesCFG() (#148167)
This PR depends on #148165; the first commit (90f1d0a881a21a8b4f192622d798c290770fda63) belongs to that PR. The changes are distinct, so separate PRs seemed like the best option. I don't have commit access, so I couldn't use user-branches to mark the dependency. As AMDGPULateCodeGenPrepare actually performs changes that invalidate Uniformity Analysis; use `setPreservesCFG()` to mark this, instead of `setPreservesAll()` which wrongly includes preserving Uniformity Analysis. Note that before #148165, this would still have preserved Uniformity Analysis, hence the dependency. In addition, `amdgpu/llc-pipeline.cc` needs to be changed when both changes are in effect, but those changes would make the test fail if the PRs weren't based on one another. Note on why this hasn't caused issues so far: It just so happens that AMDGPULateCodeGenPrepare is always immediately followed by AMDGPUUnifyDivergentExitNodes, which *does* invalidate most analyses, including Uniformity. And because UnifyDivergentExitNodes only looks at terminators, and LateCGP seemingly does not replace uniform values with divergent values, or divergent values with uniform values, and it only *inserts new values that are not looked at by UnifyDivergentExitNodes*, this bug remained hidden. --- I ran `git-clang-format` on my changes. I tested them using the `check-llvm` target; no unexpected failures occurred after I made the change to `amdgpu/llc-pipeline.ll`.
2 parents ef4dfe5 + 5d54a57 commit 962bef6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,8 @@ class AMDGPULateCodeGenPrepareLegacy : public FunctionPass {
545545
AU.addRequired<TargetPassConfig>();
546546
AU.addRequired<AssumptionCacheTracker>();
547547
AU.addRequired<UniformityInfoWrapperPass>();
548-
AU.setPreservesAll();
548+
// Invalidates UniformityInfo
549+
AU.setPreservesCFG();
549550
}
550551

551552
bool runOnFunction(Function &F) override;

llvm/test/CodeGen/AMDGPU/llc-pipeline.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@
255255
; GCN-O1-NEXT: Uniformity Analysis
256256
; GCN-O1-NEXT: AMDGPU IR late optimizations
257257
; GCN-O1-NEXT: Post-Dominator Tree Construction
258+
; GCN-O1-NEXT: Uniformity Analysis
258259
; GCN-O1-NEXT: Unify divergent function exit nodes
259260
; GCN-O1-NEXT: Dominator Tree Construction
260261
; GCN-O1-NEXT: Cycle Info Analysis
@@ -559,6 +560,7 @@
559560
; GCN-O1-OPTS-NEXT: Uniformity Analysis
560561
; GCN-O1-OPTS-NEXT: AMDGPU IR late optimizations
561562
; GCN-O1-OPTS-NEXT: Post-Dominator Tree Construction
563+
; GCN-O1-OPTS-NEXT: Uniformity Analysis
562564
; GCN-O1-OPTS-NEXT: Unify divergent function exit nodes
563565
; GCN-O1-OPTS-NEXT: Dominator Tree Construction
564566
; GCN-O1-OPTS-NEXT: Cycle Info Analysis
@@ -875,6 +877,7 @@
875877
; GCN-O2-NEXT: Uniformity Analysis
876878
; GCN-O2-NEXT: AMDGPU IR late optimizations
877879
; GCN-O2-NEXT: Post-Dominator Tree Construction
880+
; GCN-O2-NEXT: Uniformity Analysis
878881
; GCN-O2-NEXT: Unify divergent function exit nodes
879882
; GCN-O2-NEXT: Dominator Tree Construction
880883
; GCN-O2-NEXT: Cycle Info Analysis
@@ -1206,6 +1209,7 @@
12061209
; GCN-O3-NEXT: Uniformity Analysis
12071210
; GCN-O3-NEXT: AMDGPU IR late optimizations
12081211
; GCN-O3-NEXT: Post-Dominator Tree Construction
1212+
; GCN-O3-NEXT: Uniformity Analysis
12091213
; GCN-O3-NEXT: Unify divergent function exit nodes
12101214
; GCN-O3-NEXT: Dominator Tree Construction
12111215
; GCN-O3-NEXT: Cycle Info Analysis

0 commit comments

Comments
 (0)