[llvm] [AMDGPU] Change control flow intrinsic lowering making the wave to re… (PR #86805)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 16 20:13:35 PDT 2024


================
@@ -15619,6 +15619,91 @@ void SITargetLowering::finalizeLowering(MachineFunction &MF) const {
     }
   }
 
+  // ISel inserts copy to regs for the successor PHIs
+  // at the BB end. We need to move the SI_WAVE_RECONVERGE right before the branch.
+  // Even we don't have to move SI_WAVE_RECONVERGE we need to take care of the
+  // S_CBRANCH_SCC0/1 as SI_WAVE_RECONVERGE overwrites SCC
+  for (auto &MBB : MF) {
+    for (auto &MI : MBB) {
+      if (MI.getOpcode() == AMDGPU::SI_WAVE_RECONVERGE) {
+        MachineBasicBlock::iterator I(MI);
+        MachineBasicBlock::iterator Next = std::next(I);
+        bool NeedToMove = false;
+        while (Next != MBB.end() && !Next->isBranch()) {
+          NeedToMove = true;
+          Next++;
+        }
+
+        // Lets take care of SCC users as SI_WAVE_RECONVERGE defines SCC
+        bool NeedPreserveSCC =
+            Next != MBB.end() && Next->readsRegister(AMDGPU::SCC);
----------------
ruiling wrote:

Agree, see my previous comment(https://github.com/llvm/llvm-project/pull/86805#discussion_r1546069752), the issue should be better fixed in SIAnnotateControlFlow.

https://github.com/llvm/llvm-project/pull/86805


More information about the llvm-commits mailing list