[llvm] [IVUsers] Make IV-use collection independent of SSA use-list order (PR #215261)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 06:25:14 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: LJ (elle-j)

<details>
<summary>Changes</summary>

`IVUsers::AddUsersIfInteresting` visits the users of an instruction in SSA use-list order. That order carries the IR's construction and mutation history, is invisible in printed IR, and should have no semantic meaning. However, it leaks into codegen in several ways:
* LSR's `SolveRecurse` keeps the first-enumerated solution when complete solutions tie on cost, and
* its search-space narrowing heuristics prune candidates in enumeration order, and
* the traversal can even change which IV uses are collected, not just their order: the walk skips users it has already visited, and one failure case abandons an instruction's remaining users, so membership depends on visit order.

As a result, semantically identical modules that differ only in in-memory use-list order can compile to different assembly.

This commit fixes this by collecting the (deduplicated) users into a vector and visiting them in reverse program order, sorted by basic-block position within the function and by `Instruction::comesBefore` within a block. Both keys are pure functions of the IR text, so the collected IV uses (membership and order) no longer depend on use-list order. Canonicalizing the traversal, rather than adding a tie-break in `SolveRecurse`, also fixes the membership dependence.

Reverse program order is chosen because it closely matches the use-list order of freshly parsed IR (uses are prepended on creation), so IR that round-trips through serialization mostly keeps its current behavior (in a comparison on the `Transforms/LoopStrengthReduce` test directory, forward program order changed roughly 25x more test outputs than reverse).

`BasicBlock::getNumber()` is deliberately not used as the block key because block numbers are assigned by insertion history, which is the same type of issue this patch fixes.

The new test (`llvm/test/Transforms/LoopStrengthReduce/use-list-order.ll`) compiles two identical functions that differ only in a `uselistorder` directive (without this patch they compile to different code).

AI tool usage: This patch implementation has been assisted by Claude Fable 5 in particular for exploring alternative approaches, keeping the change consistent with existing code structure and conventions, and analyzing the changes of the regenerated tests. I have reviewed all changes.

Fixes [#<!-- -->215260](https://github.com/llvm/llvm-project/issues/215260)

---

Patch is 179.76 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/215261.diff


17 Files Affected:

- (modified) llvm/include/llvm/Analysis/IVUsers.h (+7-1) 
- (modified) llvm/lib/Analysis/IVUsers.cpp (+34-6) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/divergence-divergent-i1-used-outside-loop.ll (+7-7) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/divergence-temporal-divergent-i1.ll (+2-3) 
- (modified) llvm/test/CodeGen/AMDGPU/agpr-copy-no-free-registers.ll (+182-208) 
- (modified) llvm/test/CodeGen/AMDGPU/asyncmark-gfx12plus.ll (+5-6) 
- (modified) llvm/test/CodeGen/AMDGPU/memcpy_const_compare.ll (+9-9) 
- (modified) llvm/test/CodeGen/AMDGPU/memintrinsic-unroll.ll (+235-235) 
- (modified) llvm/test/CodeGen/AMDGPU/memmove-var-size.ll (+48-48) 
- (modified) llvm/test/CodeGen/AMDGPU/noclobber-barrier.ll (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/promote-constOffset-to-imm.ll (+234-233) 
- (modified) llvm/test/CodeGen/AMDGPU/waitcnt-loop-ds-prefetch-flushed.ll (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/while-break.ll (+2-2) 
- (modified) llvm/test/CodeGen/NVPTX/load-with-non-coherent-cache.ll (+2-2) 
- (modified) llvm/test/CodeGen/PowerPC/more-dq-form-prepare.ll (+174-173) 
- (modified) llvm/test/Transforms/LoopStrengthReduce/X86/missing-phi-operand-update.ll (+13-13) 
- (added) llvm/test/Transforms/LoopStrengthReduce/use-list-order.ll (+120) 


``````````diff
diff --git a/llvm/include/llvm/Analysis/IVUsers.h b/llvm/include/llvm/Analysis/IVUsers.h
index 076d13e7e4257..df4fdca43caf5 100644
--- a/llvm/include/llvm/Analysis/IVUsers.h
+++ b/llvm/include/llvm/Analysis/IVUsers.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_ANALYSIS_IVUSERS_H
 #define LLVM_ANALYSIS_IVUSERS_H
 
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/Analysis/LoopAnalysisManager.h"
 #include "llvm/Analysis/LoopPass.h"
 #include "llvm/Analysis/ScalarEvolutionNormalization.h"
@@ -105,6 +106,10 @@ class IVUsers {
   // Ephemeral values used by @llvm.assume in this function.
   SmallPtrSet<const Value *, 32> EphValues;
 
+  /// The position of every basic block within its function, used to visit
+  /// the users of an instruction in a use-list-order-independent order.
+  DenseMap<const BasicBlock *, unsigned> BBPositions;
+
 public:
   LLVM_ABI IVUsers(Loop *L, AssumptionCache *AC, LoopInfo *LI,
                    DominatorTree *DT, ScalarEvolution *SE);
@@ -112,7 +117,8 @@ class IVUsers {
   IVUsers(IVUsers &&X)
       : L(std::move(X.L)), AC(std::move(X.AC)), DT(std::move(X.DT)),
         SE(std::move(X.SE)), Processed(std::move(X.Processed)),
-        IVUses(std::move(X.IVUses)), EphValues(std::move(X.EphValues)) {
+        IVUses(std::move(X.IVUses)), EphValues(std::move(X.EphValues)),
+        BBPositions(std::move(X.BBPositions)) {
     for (IVStrideUse &U : IVUses)
       U.Parent = this;
   }
diff --git a/llvm/lib/Analysis/IVUsers.cpp b/llvm/lib/Analysis/IVUsers.cpp
index fb7778e9ef153..ed9dddcd37ac8 100644
--- a/llvm/lib/Analysis/IVUsers.cpp
+++ b/llvm/lib/Analysis/IVUsers.cpp
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Analysis/IVUsers.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Analysis/AssumptionCache.h"
 #include "llvm/Analysis/CodeMetrics.h"
 #include "llvm/Analysis/LoopAnalysisManager.h"
@@ -170,12 +171,35 @@ bool IVUsers::AddUsersIfInteresting(Instruction *I) {
   if (!isInteresting(ISE, I, L, SE, LI))
     return false;
 
-  SmallPtrSet<Instruction *, 4> UniqueUsers;
-  for (Use &U : I->uses()) {
-    Instruction *User = cast<Instruction>(U.getUser());
-    if (!UniqueUsers.insert(User).second)
-      continue;
-
+  // Visit the users of I in reverse program order rather than in use-list
+  // order: use-list order depends on the IR's construction and mutation
+  // history, which printed IR does not preserve. The traversal order
+  // affects both which IV uses are collected (the Processed short-circuit
+  // and the non-invertible-normalization early return below are
+  // order-sensitive) and which solution LSR picks (both its cost-tie
+  // breaking and its search-space pruning follow enumeration order).
+  // Reverse program order is used because it closely matches the use-list
+  // order of freshly parsed IR, where uses are prepended on creation.
+  SmallVector<Instruction *, 8> Users;
+  {
+    SmallPtrSet<Instruction *, 4> UniqueUsers;
+    for (Use &U : I->uses()) {
+      Instruction *User = cast<Instruction>(U.getUser());
+      if (UniqueUsers.insert(User).second)
+        Users.push_back(User);
+    }
+  }
+  llvm::sort(Users, [this](Instruction *A, Instruction *B) {
+    assert(BBPositions.contains(A->getParent()) &&
+           BBPositions.contains(B->getParent()) &&
+           "IV user in a block not numbered at IVUsers construction");
+    if (A->getParent() != B->getParent())
+      return BBPositions.lookup(A->getParent()) >
+             BBPositions.lookup(B->getParent());
+    return B->comesBefore(A);
+  });
+
+  for (Instruction *User : Users) {
     // Do not infinitely recurse on PHI nodes.
     if (isa<PHINode>(User) && Processed.count(User))
       continue;
@@ -255,6 +279,10 @@ IVUsers::IVUsers(Loop *L, AssumptionCache *AC, LoopInfo *LI, DominatorTree *DT,
   EphValues.clear();
   CodeMetrics::collectEphemeralValues(L, AC, EphValues);
 
+  unsigned Position = 0;
+  for (const BasicBlock &BB : *L->getHeader()->getParent())
+    BBPositions[&BB] = Position++;
+
   // Find all uses of induction variables in this loop, and categorize
   // them by stride.  Start by finding all of the PHI nodes in the header for
   // this loop.  If they are induction variables, inspect their uses.
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/divergence-divergent-i1-used-outside-loop.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/divergence-divergent-i1-used-outside-loop.ll
index ac93b626bce90..14b06e0b5e99c 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/divergence-divergent-i1-used-outside-loop.ll
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/divergence-divergent-i1-used-outside-loop.ll
@@ -242,11 +242,11 @@ define void @divergent_i1_xor_used_outside_loop_larger_loop_body(i32 %num.elts,
 ; GFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
 ; GFX10-NEXT:    v_cmp_eq_u32_e32 vcc_lo, 0, v0
 ; GFX10-NEXT:    s_mov_b32 s6, exec_lo
-; GFX10-NEXT:    s_mov_b32 s4, 0
+; GFX10-NEXT:    s_mov_b32 s8, 0
 ; GFX10-NEXT:    s_and_saveexec_b32 s7, vcc_lo
 ; GFX10-NEXT:    s_cbranch_execz .LBB4_6
 ; GFX10-NEXT:  ; %bb.1: ; %loop.start.preheader
-; GFX10-NEXT:    s_mov_b32 s8, 0
+; GFX10-NEXT:    s_mov_b32 s4, -1
 ; GFX10-NEXT:    ; implicit-def: $sgpr10
 ; GFX10-NEXT:    ; implicit-def: $sgpr11
 ; GFX10-NEXT:    ; implicit-def: $sgpr9
@@ -264,8 +264,9 @@ define void @divergent_i1_xor_used_outside_loop_larger_loop_body(i32 %num.elts,
 ; GFX10-NEXT:    s_cbranch_execz .LBB4_5
 ; GFX10-NEXT:  .LBB4_3: ; %loop.start
 ; GFX10-NEXT:    ; =>This Inner Loop Header: Depth=1
-; GFX10-NEXT:    s_ashr_i32 s5, s4, 31
+; GFX10-NEXT:    s_add_i32 s4, s4, 1
 ; GFX10-NEXT:    s_andn2_b32 s10, s10, exec_lo
+; GFX10-NEXT:    s_ashr_i32 s5, s4, 31
 ; GFX10-NEXT:    s_lshl_b64 s[12:13], s[4:5], 2
 ; GFX10-NEXT:    s_andn2_b32 s5, s11, exec_lo
 ; GFX10-NEXT:    v_mov_b32_e32 v5, s12
@@ -287,9 +288,8 @@ define void @divergent_i1_xor_used_outside_loop_larger_loop_body(i32 %num.elts,
 ; GFX10-NEXT:    s_andn2_b32 s11, s11, exec_lo
 ; GFX10-NEXT:    s_and_b32 s12, exec_lo, 0
 ; GFX10-NEXT:    s_andn2_b32 s10, s10, exec_lo
-; GFX10-NEXT:    s_add_i32 s4, s4, 1
-; GFX10-NEXT:    s_and_b32 s13, exec_lo, vcc_lo
 ; GFX10-NEXT:    s_or_b32 s11, s11, s12
+; GFX10-NEXT:    s_and_b32 s13, exec_lo, vcc_lo
 ; GFX10-NEXT:    s_or_b32 s10, s10, s13
 ; GFX10-NEXT:    s_branch .LBB4_2
 ; GFX10-NEXT:  .LBB4_5: ; %loop.exit.guard
@@ -459,7 +459,7 @@ define amdgpu_ps void @divergent_i1_freeze_used_outside_loop(i32 %n, ptr addrspa
 ; GFX10-LABEL: divergent_i1_freeze_used_outside_loop:
 ; GFX10:       ; %bb.0: ; %entry
 ; GFX10-NEXT:    s_mov_b32 s1, exec_lo
-; GFX10-NEXT:    s_mov_b32 s0, 0
+; GFX10-NEXT:    s_mov_b32 s0, -1
 ; GFX10-NEXT:    s_mov_b32 s2, 0
 ; GFX10-NEXT:    ; implicit-def: $sgpr4
 ; GFX10-NEXT:    ; implicit-def: $sgpr3
@@ -468,7 +468,6 @@ define amdgpu_ps void @divergent_i1_freeze_used_outside_loop(i32 %n, ptr addrspa
 ; GFX10-NEXT:    ; in Loop: Header=BB6_2 Depth=1
 ; GFX10-NEXT:    s_or_b32 exec_lo, exec_lo, s5
 ; GFX10-NEXT:    v_cmp_lt_i32_e32 vcc_lo, s0, v0
-; GFX10-NEXT:    s_add_i32 s0, s0, 1
 ; GFX10-NEXT:    s_or_b32 s2, vcc_lo, s2
 ; GFX10-NEXT:    s_andn2_b32 s3, s3, exec_lo
 ; GFX10-NEXT:    s_and_b32 s5, exec_lo, s4
@@ -481,6 +480,7 @@ define amdgpu_ps void @divergent_i1_freeze_used_outside_loop(i32 %n, ptr addrspa
 ; GFX10-NEXT:    ; =>This Inner Loop Header: Depth=1
 ; GFX10-NEXT:    s_andn2_b32 s4, s4, exec_lo
 ; GFX10-NEXT:    s_and_b32 s5, exec_lo, s1
+; GFX10-NEXT:    s_add_i32 s0, s0, 1
 ; GFX10-NEXT:    s_or_b32 s4, s4, s5
 ; GFX10-NEXT:    s_and_saveexec_b32 s5, s1
 ; GFX10-NEXT:    s_cbranch_execz .LBB6_1
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/divergence-temporal-divergent-i1.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/divergence-temporal-divergent-i1.ll
index 8c344daa5c38e..48199e6deb629 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/divergence-temporal-divergent-i1.ll
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/divergence-temporal-divergent-i1.ll
@@ -101,7 +101,7 @@ define amdgpu_cs void @loop_with_1break(ptr addrspace(1) %x, i32 %x.size, ptr ad
 ; GFX10-LABEL: loop_with_1break:
 ; GFX10:       ; %bb.0: ; %entry
 ; GFX10-NEXT:    v_mov_b32_e32 v3, 0
-; GFX10-NEXT:    s_mov_b32 s4, 0
+; GFX10-NEXT:    s_mov_b32 s4, -1
 ; GFX10-NEXT:    s_mov_b32 s8, 0
 ; GFX10-NEXT:    ; implicit-def: $sgpr10
 ; GFX10-NEXT:    ; implicit-def: $sgpr9
@@ -115,7 +115,6 @@ define amdgpu_cs void @loop_with_1break(ptr addrspace(1) %x, i32 %x.size, ptr ad
 ; GFX10-NEXT:    v_add_co_u32 v4, vcc_lo, v0, v4
 ; GFX10-NEXT:    v_add_co_ci_u32_e32 v5, vcc_lo, v1, v5, vcc_lo
 ; GFX10-NEXT:    v_cmp_lt_u32_e32 vcc_lo, s4, v2
-; GFX10-NEXT:    s_add_i32 s4, s4, 1
 ; GFX10-NEXT:    global_load_dword v6, v[4:5], off
 ; GFX10-NEXT:    s_and_b32 s7, exec_lo, vcc_lo
 ; GFX10-NEXT:    s_or_b32 s10, s6, s7
@@ -136,6 +135,7 @@ define amdgpu_cs void @loop_with_1break(ptr addrspace(1) %x, i32 %x.size, ptr ad
 ; GFX10-NEXT:    s_cbranch_execz .LBB2_5
 ; GFX10-NEXT:  .LBB2_3: ; %A
 ; GFX10-NEXT:    ; =>This Inner Loop Header: Depth=1
+; GFX10-NEXT:    s_add_i32 s4, s4, 1
 ; GFX10-NEXT:    s_ashr_i32 s5, s4, 31
 ; GFX10-NEXT:    s_lshl_b64 s[6:7], s[4:5], 2
 ; GFX10-NEXT:    s_add_u32 s12, s0, s6
@@ -152,7 +152,6 @@ define amdgpu_cs void @loop_with_1break(ptr addrspace(1) %x, i32 %x.size, ptr ad
 ; GFX10-NEXT:    s_cbranch_scc1 .LBB2_1
 ; GFX10-NEXT:  ; %bb.4: ; in Loop: Header=BB2_3 Depth=1
 ; GFX10-NEXT:    s_mov_b32 s5, 1
-; GFX10-NEXT:    ; implicit-def: $sgpr4
 ; GFX10-NEXT:    s_branch .LBB2_2
 ; GFX10-NEXT:  .LBB2_5: ; %loop.exit.guard
 ; GFX10-NEXT:    s_or_b32 exec_lo, exec_lo, s8
diff --git a/llvm/test/CodeGen/AMDGPU/agpr-copy-no-free-registers.ll b/llvm/test/CodeGen/AMDGPU/agpr-copy-no-free-registers.ll
index 41c3e0a07f5f5..16f7c02ba7880 100644
--- a/llvm/test/CodeGen/AMDGPU/agpr-copy-no-free-registers.ll
+++ b/llvm/test/CodeGen/AMDGPU/agpr-copy-no-free-registers.ll
@@ -511,120 +511,111 @@ define amdgpu_kernel void @introduced_copy_to_sgpr(i64 %arg, i32 %arg1, i32 %arg
 ; GFX908-LABEL: introduced_copy_to_sgpr:
 ; GFX908:       ; %bb.0: ; %bb
 ; GFX908-NEXT:    global_load_ushort v0, v[0:1], off glc
-; GFX908-NEXT:    s_load_dwordx4 s[0:3], s[8:9], 0x0
-; GFX908-NEXT:    s_load_dwordx2 s[4:5], s[8:9], 0x10
-; GFX908-NEXT:    s_load_dword s7, s[8:9], 0x18
-; GFX908-NEXT:    s_mov_b32 s6, 0
-; GFX908-NEXT:    s_mov_b32 s9, s6
+; GFX908-NEXT:    s_load_dwordx4 s[4:7], s[8:9], 0x0
+; GFX908-NEXT:    s_load_dwordx2 s[2:3], s[8:9], 0x10
+; GFX908-NEXT:    s_load_dword s0, s[8:9], 0x18
+; GFX908-NEXT:    s_mov_b32 s10, 0
+; GFX908-NEXT:    v_mov_b32_e32 v14, 0
 ; GFX908-NEXT:    s_waitcnt lgkmcnt(0)
-; GFX908-NEXT:    v_cvt_f32_u32_e32 v1, s3
-; GFX908-NEXT:    s_sub_i32 s8, 0, s3
-; GFX908-NEXT:    v_cvt_f32_f16_e32 v12, s7
-; GFX908-NEXT:    s_mov_b64 s[16:17], 0
+; GFX908-NEXT:    v_cvt_f32_u32_e32 v1, s7
+; GFX908-NEXT:    s_sub_i32 s1, 0, s7
+; GFX908-NEXT:    v_cvt_f32_f16_e32 v13, s0
 ; GFX908-NEXT:    v_rcp_f32_e32 v1, v1
-; GFX908-NEXT:    v_mov_b32_e32 v14, 0
 ; GFX908-NEXT:    v_mul_f32_e32 v1, 0x4f7ffffe, v1
 ; GFX908-NEXT:    v_cvt_u32_f32_e32 v1, v1
-; GFX908-NEXT:    v_readfirstlane_b32 s10, v1
-; GFX908-NEXT:    s_mul_i32 s8, s8, s10
-; GFX908-NEXT:    s_mul_hi_u32 s8, s10, s8
-; GFX908-NEXT:    s_add_i32 s10, s10, s8
-; GFX908-NEXT:    s_mul_hi_u32 s8, s2, s10
-; GFX908-NEXT:    s_mul_i32 s10, s8, s3
-; GFX908-NEXT:    s_sub_i32 s2, s2, s10
-; GFX908-NEXT:    s_add_i32 s11, s8, 1
-; GFX908-NEXT:    s_sub_i32 s10, s2, s3
+; GFX908-NEXT:    v_readfirstlane_b32 s8, v1
+; GFX908-NEXT:    s_mul_i32 s1, s1, s8
+; GFX908-NEXT:    s_mul_hi_u32 s1, s8, s1
+; GFX908-NEXT:    s_add_i32 s8, s8, s1
+; GFX908-NEXT:    s_mul_hi_u32 s1, s6, s8
+; GFX908-NEXT:    s_mul_i32 s8, s1, s7
+; GFX908-NEXT:    s_sub_i32 s6, s6, s8
+; GFX908-NEXT:    s_add_i32 s9, s1, 1
+; GFX908-NEXT:    s_sub_i32 s8, s6, s7
 ; GFX908-NEXT:    s_waitcnt vmcnt(0)
-; GFX908-NEXT:    v_readfirstlane_b32 s12, v0
-; GFX908-NEXT:    s_and_b32 s30, s12, 0xffff
-; GFX908-NEXT:    s_cmp_ge_u32 s2, s3
-; GFX908-NEXT:    s_cselect_b32 s8, s11, s8
-; GFX908-NEXT:    s_cselect_b32 s2, s10, s2
-; GFX908-NEXT:    s_add_i32 s10, s8, 1
-; GFX908-NEXT:    s_cmp_ge_u32 s2, s3
-; GFX908-NEXT:    s_cselect_b32 s8, s10, s8
-; GFX908-NEXT:    s_lshr_b32 s7, s7, 16
-; GFX908-NEXT:    v_cvt_f32_f16_e32 v13, s7
-; GFX908-NEXT:    s_mul_i32 s12, s1, s30
-; GFX908-NEXT:    s_mul_hi_u32 s13, s0, s30
-; GFX908-NEXT:    s_mul_i32 s14, s0, s30
-; GFX908-NEXT:    s_add_i32 s15, s13, s12
-; GFX908-NEXT:    s_lshl_b64 s[2:3], s[0:1], 5
-; GFX908-NEXT:    s_lshl_b64 s[10:11], s[4:5], 5
-; GFX908-NEXT:    s_lshl_b64 s[12:13], s[8:9], 5
-; GFX908-NEXT:    s_lshl_b64 s[14:15], s[14:15], 5
+; GFX908-NEXT:    v_readfirstlane_b32 s11, v0
+; GFX908-NEXT:    s_and_b32 s20, s11, 0xffff
+; GFX908-NEXT:    s_cmp_ge_u32 s6, s7
+; GFX908-NEXT:    s_cselect_b32 s1, s9, s1
+; GFX908-NEXT:    s_cselect_b32 s6, s8, s6
+; GFX908-NEXT:    s_add_i32 s8, s1, 1
+; GFX908-NEXT:    s_cmp_ge_u32 s6, s7
+; GFX908-NEXT:    s_cselect_b32 s21, s8, s1
+; GFX908-NEXT:    s_lshr_b32 s1, s0, 16
+; GFX908-NEXT:    v_cvt_f32_f16_e32 v12, s1
 ; GFX908-NEXT:    s_and_b64 s[0:1], exec, s[0:1]
+; GFX908-NEXT:    s_mov_b64 s[6:7], 0
 ; GFX908-NEXT:    s_branch .LBB3_2
-; GFX908-NEXT:  .LBB3_1: ; %Flow20
+; GFX908-NEXT:  .LBB3_1: ; %Flow10
 ; GFX908-NEXT:    ; in Loop: Header=BB3_2 Depth=1
-; GFX908-NEXT:    s_and_b64 s[18:19], s[18:19], exec
-; GFX908-NEXT:    s_cselect_b32 s7, 1, 0
-; GFX908-NEXT:    s_cmp_lg_u32 s7, 1
+; GFX908-NEXT:    s_and_b64 s[8:9], s[8:9], exec
+; GFX908-NEXT:    s_cselect_b32 s8, 1, 0
+; GFX908-NEXT:    s_cmp_lg_u32 s8, 1
 ; GFX908-NEXT:    s_cbranch_scc0 .LBB3_13
 ; GFX908-NEXT:  .LBB3_2: ; %bb9
 ; GFX908-NEXT:    ; =>This Loop Header: Depth=1
 ; GFX908-NEXT:    ; Child Loop BB3_5 Depth 2
-; GFX908-NEXT:    s_mov_b64 s[20:21], -1
+; GFX908-NEXT:    s_mov_b64 s[12:13], -1
 ; GFX908-NEXT:    s_mov_b64 vcc, s[0:1]
 ; GFX908-NEXT:    s_cbranch_vccz .LBB3_11
 ; GFX908-NEXT:  ; %bb.3: ; %bb14
 ; GFX908-NEXT:    ; in Loop: Header=BB3_2 Depth=1
-; GFX908-NEXT:    s_load_dwordx2 s[18:19], s[16:17], 0x0
-; GFX908-NEXT:    s_cmp_lt_i32 s5, 0
-; GFX908-NEXT:    s_cselect_b64 s[20:21], -1, 0
-; GFX908-NEXT:    s_cmp_gt_i32 s5, -1
-; GFX908-NEXT:    s_cselect_b64 s[22:23], -1, 0
-; GFX908-NEXT:    s_waitcnt lgkmcnt(0)
-; GFX908-NEXT:    s_add_u32 s7, s18, 1
-; GFX908-NEXT:    s_addc_u32 s9, s19, 0
-; GFX908-NEXT:    s_mul_i32 s9, s2, s9
-; GFX908-NEXT:    s_mul_hi_u32 s24, s2, s7
-; GFX908-NEXT:    s_add_i32 s9, s24, s9
-; GFX908-NEXT:    s_mul_i32 s24, s3, s7
-; GFX908-NEXT:    s_mul_i32 s31, s2, s7
-; GFX908-NEXT:    s_mov_b32 s7, s6
-; GFX908-NEXT:    s_add_i32 s9, s9, s24
-; GFX908-NEXT:    v_mov_b32_e32 v0, s6
-; GFX908-NEXT:    v_mov_b32_e32 v1, s7
-; GFX908-NEXT:    s_mov_b64 s[24:25], s[10:11]
-; GFX908-NEXT:    v_mov_b32_e32 v2, s6
-; GFX908-NEXT:    v_mov_b32_e32 v3, s7
-; GFX908-NEXT:    v_mov_b32_e32 v4, s6
-; GFX908-NEXT:    v_mov_b32_e32 v5, s7
-; GFX908-NEXT:    v_mov_b32_e32 v6, s6
-; GFX908-NEXT:    v_mov_b32_e32 v7, s7
+; GFX908-NEXT:    s_load_dwordx2 s[14:15], s[6:7], 0x0
+; GFX908-NEXT:    s_cmp_lt_i32 s3, 0
+; GFX908-NEXT:    s_cselect_b64 s[8:9], -1, 0
+; GFX908-NEXT:    s_cmp_gt_i32 s3, -1
+; GFX908-NEXT:    s_mov_b32 s11, s10
+; GFX908-NEXT:    s_cselect_b64 s[12:13], -1, 0
+; GFX908-NEXT:    v_mov_b32_e32 v0, s10
+; GFX908-NEXT:    v_mov_b32_e32 v1, s11
+; GFX908-NEXT:    v_mov_b32_e32 v2, s10
+; GFX908-NEXT:    v_mov_b32_e32 v3, s11
+; GFX908-NEXT:    v_mov_b32_e32 v4, s10
+; GFX908-NEXT:    v_mov_b32_e32 v5, s11
+; GFX908-NEXT:    v_mov_b32_e32 v6, s10
+; GFX908-NEXT:    v_mov_b32_e32 v7, s11
 ; GFX908-NEXT:    s_branch .LBB3_5
-; GFX908-NEXT:  .LBB3_4: ; %Flow18
+; GFX908-NEXT:  .LBB3_4: ; %Flow8
 ; GFX908-NEXT:    ; in Loop: Header=BB3_5 Depth=2
-; GFX908-NEXT:    s_and_b64 s[28:29], s[28:29], exec
-; GFX908-NEXT:    s_cselect_b32 s7, 1, 0
-; GFX908-NEXT:    s_cmp_lg_u32 s7, 1
+; GFX908-NEXT:    s_and_b64 s[18:19], s[18:19], exec
+; GFX908-NEXT:    s_cselect_b32 s11, 1, 0
+; GFX908-NEXT:    s_cmp_lg_u32 s11, 1
 ; GFX908-NEXT:    s_cbranch_scc0 .LBB3_10
 ; GFX908-NEXT:  .LBB3_5: ; %bb16
 ; GFX908-NEXT:    ; Parent Loop BB3_2 Depth=1
 ; GFX908-NEXT:    ; => This Inner Loop Header: Depth=2
-; GFX908-NEXT:    s_add_u32 s26, s24, s31
-; GFX908-NEXT:    s_addc_u32 s27, s25, s9
-; GFX908-NEXT:    global_load_dword v16, v14, s[26:27] offset:16 glc
+; GFX908-NEXT:    s_waitcnt lgkmcnt(0)
+; GFX908-NEXT:    s_add_u32 s11, s14, 1
+; GFX908-NEXT:    s_addc_u32 s16, s15, 0
+; GFX908-NEXT:    s_mul_i32 s17, s11, s5
+; GFX908-NEXT:    s_mul_hi_u32 s18, s11, s4
+; GFX908-NEXT:    s_add_i32 s17, s18, s17
+; GFX908-NEXT:    s_mul_i32 s16, s16, s4
+; GFX908-NEXT:    s_add_i32 s17, s17, s16
+; GFX908-NEXT:    s_mul_i32 s11, s11, s4
+; GFX908-NEXT:    s_add_u32 s16, s11, s2
+; GFX908-NEXT:    s_addc_u32 s17, s17, s3
+; GFX908-NEXT:    s_lshl_b64 s[16:17], s[16:17], 5
+; GFX908-NEXT:    global_load_dword v16, v14, s[16:17] offset:16 glc
 ; GFX908-NEXT:    s_waitcnt vmcnt(0)
-; GFX908-NEXT:    global_load_dword v15, v14, s[26:27] offset:20 glc
+; GFX908-NEXT:    global_load_dword v15, v14, s[16:17] offset:20 glc
 ; GFX908-NEXT:    s_waitcnt vmcnt(0)
-; GFX908-NEXT:    global_load_dword v8, v14, s[26:27] offset:24 glc
+; GFX908-NEXT:    global_load_dword v8, v14, s[16:17] offset:24 glc
 ; GFX908-NEXT:    s_waitcnt vmcnt(0)
-; GFX908-NEXT:    global_load_dword v8, v14, s[26:27] offset:28 glc
+; GFX908-NEXT:    global_load_dword v8, v14, s[16:17] offset:28 glc
 ; GFX908-NEXT:    s_waitcnt vmcnt(0)
 ; GFX908-NEXT:    ds_read_b64 v[8:9], v14
 ; GFX908-NEXT:    ds_read_b64 v[10:11], v0
-; GFX908-NEXT:    ; kill: killed $sgpr26 killed $sgpr27
-; GFX908-NEXT:    s_and_b64 s[26:27], s[22:23], exec
-; GFX908-NEXT:    s_cselect_b32 s7, 1, 0
-; GFX908-NEXT:    s_cmp_lg_u32 s7, 1
+; GFX908-NEXT:    ; kill: killed $sgpr16_sgpr17
+; GFX908-NEXT:    s_and_b64 s[16:17], s[12:13], exec
+; GFX908-NEXT:    s_cselect_b32 s11, 1, 0
+; GFX908-NEXT:    s_cmp_lg_u32 s11, 1
 ; GFX908-NEXT:    s_waitcnt lgkmcnt(0)
 ; GFX908-NEXT:    s_cbranch_scc1 .LBB3_7
 ; GFX908-NEXT:  ; %bb.6: ; %bb51
 ; GFX908-NEXT:    ; in Loop: Header=BB3_5 Depth=2
-; GFX908-NEXT:    v_add_f32_e32 v17, v12, v8
-; GFX908-NEXT:    v_add_f32_e32 v18, v13, v9
+; GFX908-NEXT:    v_add_f32_e32 v17, v13, v8
+; GFX908-NEXT:    v_add_f32_e32 v18, v12, v9
 ; GFX908-NEXT:    v_add_f32_e32 v19, 0, v8
 ; GFX908-NEXT:    v_add_f32_e32 v20, 0, v9
 ; GFX908-NEXT:    v_fma_mix_f32 v10, v16, 1.0, v10 op_sel_hi:[1,1,0]
@@ -639,154 +630,141 @@ define amdgpu_kernel void @introduced_copy_to_sgpr(i64 %arg, i32 %arg1, i32 %arg
 ; GFX908-NEXT:    v_add_f32_e32 v4, v4, v10
 ; GFX908-NEXT:    v_add_f32_e32 v7, v7, v9
 ; GFX908-NEXT:    v_add_f32_e32 v6, v6, v8
-; GFX908-NEXT:    s_mov_b64 s[28:29], -1
+; GFX908-NEXT:    s_mov_b64 s[18:19], -1
 ; GFX908-NEXT:    s_branch .LBB3_8
 ; GFX908-NEXT:  .LBB3_7: ; in Loop: Header=BB3_5 Depth=2
-; GFX908-NEXT:    s_mov_b64 s[28:29], s[20:21]
+; GFX908-NEXT:    s_mov_b64 s[18:19], s[8:9]
 ; GFX908-NEXT:  .LBB3_8: ; %Flow
 ; GFX908-NEXT:    ; in Loop: Header=BB3_5 Depth=2
-; GFX908-NEXT:    s_and_b64 s[28:29], s[28:29], exec
-; GFX908-NEXT:    s_cselect_b32 s7, 1, 0
-; GFX908-NEXT:    s_mov_b64 s[26:27], -1
-; GFX908-NEXT:    s_cmp_lg_u32 s7, 1
-; GFX908-NEXT:    s_mov_b64 s[28:29], -1
+; GFX908-NEXT:    s_and_b64 s[18:19], s[18:19], exec
+; GFX908-NEXT:    s_cselect_b32 s11, 1, 0
+; GFX908-NEXT:    s_mov_b64 s[16:17], -1
+; GFX908-NEXT:    s_cmp_lg_u32 s11, 1
+; GFX908-NEXT:    s_mov_b64 s[18:19], -1
 ; GFX908-NEXT:    s_cbranch_scc1 .LBB3_4
 ; GFX908-NEXT:  ; %bb.9: ; %bb58
 ; GFX908-NEXT:    ; in Loop: Header=BB3_5 Depth=2
-; GFX908-NEXT:    s_add_u32 s18, s18, s30
-; GFX908-NEXT:    s_addc_u32 s19, s19, 0
-; GFX908-NEXT:    s_add_u32 s24, s24, s14
-; GFX908-NEXT:    s_addc_u32 s25, s25, s15
-; GFX908-NEXT:    s_cmp_gt_i32 s19, -1
-; GFX908-NEXT:    s_mov_b64 s[26:27], 0
-; GFX908-NEXT:    s_cselect_b64 s[28:29], -1, 0
+; GFX908-NEXT:    s_add_u32 s14, s14, s20
+; GFX908-NEXT:    s_addc_u32 s15, s15, 0
+; GFX908-NEXT:    s_cmp_gt_i32 s15, -1
+; GFX908-NEXT:    s_mov_b64 s[16:17], 0
+; GFX908-NEXT:    s_cselect_b64 s[18:19], -1, 0
 ; GFX908-NEXT:    s_branch .LBB3_4
 ; GFX908-NEXT:  .LBB3_10: ; %loop.exit.guard
 ; GFX908-NEXT:    ; in Loop: Header=BB3_2 Depth=1
-; GFX908-NEXT:    s_xor_b64 s[20:21], s[26:27], -1
-; GFX908-NEXT:  .LBB3_11: ; %Flow19
+;...
[truncated]

``````````

</details>


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


More information about the llvm-commits mailing list