| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6 | |
| ; RUN: llc -global-isel=0 -mtriple=amdgpu12.00-amd-amdhsa < %s | FileCheck -check-prefix=GFX12 %s | |
| ; RUN: llc -global-isel -mtriple=amdgpu12.00-amd-amdhsa < %s | FileCheck -check-prefix=GFX12-GISEL %s | |
| ; Loop-carried divergent i1 values in a loop with a uniform trip count. The | |
| ; only latch ends in a uniform branch, so EXEC is the same on every iteration | |
| ; and no lane-mask merges are needed across the back-edge. Only the join of the | |
| ; inner divergent if needs merging. | |
| define amdgpu_kernel void @uniform_loop_live_side(ptr addrspace(1) %buf) { | |
| ; GFX12-LABEL: uniform_loop_live_side: | |
| ; GFX12: ; %bb.0: ; %entry | |
| ; GFX12-NEXT: s_load_b64 s[0:1], s[4:5], 0x0 | |
| ; GFX12-NEXT: v_and_b32_e32 v0, 0x3ff, v0 | |
| ; GFX12-NEXT: v_mov_b32_e32 v2, 0 | |
| ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1) | |
| ; GFX12-NEXT: v_lshlrev_b32_e32 v0, 2, v0 | |
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | |
| ; GFX12-NEXT: s_load_b32 s2, s[0:1], 0x0 | |
| ; GFX12-NEXT: v_add_co_u32 v0, s3, s0, v0 | |
| ; GFX12-NEXT: v_add_co_ci_u32_e64 v1, null, s1, 0, s3 | |
| ; GFX12-NEXT: s_mov_b32 s3, 0 | |
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | |
| ; GFX12-NEXT: s_and_b32 s2, s2, 15 | |
| ; GFX12-NEXT: s_cbranch_scc0 .LBB0_7 | |
| ; GFX12-NEXT: ; %bb.1: ; %loop.preheader | |
| ; GFX12-NEXT: global_load_b32 v3, v[0:1], off | |
| ; GFX12-NEXT: v_mov_b32_e32 v2, 0 | |
| ; GFX12-NEXT: s_mov_b32 s5, -1 | |
| ; GFX12-NEXT: s_mov_b32 s4, 0 | |
| ; GFX12-NEXT: s_branch .LBB0_4 | |
| ; GFX12-NEXT: .LBB0_2: ; %Flow | |
| ; GFX12-NEXT: ; in Loop: Header=BB0_4 Depth=1 | |
| ; GFX12-NEXT: s_or_b32 exec_lo, exec_lo, s9 | |
| ; GFX12-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | |
| ; GFX12-NEXT: s_and_not1_b32 s5, s5, exec_lo | |
| ; GFX12-NEXT: s_and_b32 s7, s7, exec_lo | |
| ; GFX12-NEXT: s_and_not1_b32 s3, s3, exec_lo | |
| ; GFX12-NEXT: s_and_b32 s8, s8, exec_lo | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_or_b32 s5, s5, s7 | |
| ; GFX12-NEXT: s_or_b32 s3, s3, s8 | |
| ; GFX12-NEXT: .LBB0_3: ; %latch | |
| ; GFX12-NEXT: ; in Loop: Header=BB0_4 Depth=1 | |
| ; GFX12-NEXT: s_or_b32 exec_lo, exec_lo, s6 | |
| ; GFX12-NEXT: s_add_co_i32 s4, s4, 1 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_cmp_lt_u32 s4, s2 | |
| ; GFX12-NEXT: s_cbranch_scc0 .LBB0_7 | |
| ; GFX12-NEXT: .LBB0_4: ; %loop | |
| ; GFX12-NEXT: ; =>This Inner Loop Header: Depth=1 | |
| ; GFX12-NEXT: s_and_saveexec_b32 s6, s5 | |
| ; GFX12-NEXT: s_cbranch_execz .LBB0_3 | |
| ; GFX12-NEXT: ; %bb.5: ; %if.live | |
| ; GFX12-NEXT: ; in Loop: Header=BB0_4 Depth=1 | |
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | |
| ; GFX12-NEXT: v_add_nc_u32_e32 v4, s4, v3 | |
| ; GFX12-NEXT: s_mov_b32 s7, 0 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_mov_b32 s8, s3 | |
| ; GFX12-NEXT: s_mov_b32 s9, exec_lo | |
| ; GFX12-NEXT: v_ashrrev_i32_e32 v5, 31, v4 | |
| ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1) | |
| ; GFX12-NEXT: v_lshlrev_b64_e32 v[4:5], 2, v[4:5] | |
| ; GFX12-NEXT: v_add_co_u32 v4, vcc_lo, s0, v4 | |
| ; GFX12-NEXT: s_wait_alu depctr_va_vcc(0) | |
| ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1) | |
| ; GFX12-NEXT: v_add_co_ci_u32_e64 v5, null, s1, v5, vcc_lo | |
| ; GFX12-NEXT: global_load_b32 v4, v[4:5], off | |
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | |
| ; GFX12-NEXT: v_and_b32_e32 v5, 1, v4 | |
| ; GFX12-NEXT: v_cmpx_eq_u32_e32 1, v5 | |
| ; GFX12-NEXT: s_cbranch_execz .LBB0_2 | |
| ; GFX12-NEXT: ; %bb.6: ; %then.hit | |
| ; GFX12-NEXT: ; in Loop: Header=BB0_4 Depth=1 | |
| ; GFX12-NEXT: v_add_nc_u32_e32 v2, v2, v4 | |
| ; GFX12-NEXT: s_mov_b32 s7, exec_lo | |
| ; GFX12-NEXT: s_or_b32 s8, s3, exec_lo | |
| ; GFX12-NEXT: s_branch .LBB0_2 | |
| ; GFX12-NEXT: .LBB0_7: ; %exit | |
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: v_cndmask_b32_e64 v3, 0, 1, s3 | |
| ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | |
| ; GFX12-NEXT: v_add_nc_u32_e32 v2, v2, v3 | |
| ; GFX12-NEXT: global_store_b32 v[0:1], v2, off | |
| ; GFX12-NEXT: s_endpgm | |
| ; | |
| ; GFX12-GISEL-LABEL: uniform_loop_live_side: | |
| ; GFX12-GISEL: ; %bb.0: ; %entry | |
| ; GFX12-GISEL-NEXT: s_load_b64 s[0:1], s[4:5], 0x0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s3, 0 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1) | |
| ; GFX12-GISEL-NEXT: v_dual_mov_b32 v1, s3 :: v_dual_and_b32 v0, 0x3ff, v0 | |
| ; GFX12-GISEL-NEXT: v_lshlrev_b32_e32 v0, 2, v0 | |
| ; GFX12-GISEL-NEXT: s_wait_kmcnt 0x0 | |
| ; GFX12-GISEL-NEXT: s_load_b32 s2, s[0:1], 0x0 | |
| ; GFX12-GISEL-NEXT: s_wait_kmcnt 0x0 | |
| ; GFX12-GISEL-NEXT: s_and_b32 s2, s2, 15 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_cmp_eq_u32 s2, 0 | |
| ; GFX12-GISEL-NEXT: s_cbranch_scc1 .LBB0_7 | |
| ; GFX12-GISEL-NEXT: ; %bb.1: ; %loop.preheader | |
| ; GFX12-GISEL-NEXT: global_load_b32 v2, v0, s[0:1] | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s4, 0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s5, exec_lo | |
| ; GFX12-GISEL-NEXT: v_mov_b32_e32 v1, s4 | |
| ; GFX12-GISEL-NEXT: s_branch .LBB0_4 | |
| ; GFX12-GISEL-NEXT: .LBB0_2: ; %Flow | |
| ; GFX12-GISEL-NEXT: ; in Loop: Header=BB0_4 Depth=1 | |
| ; GFX12-GISEL-NEXT: s_or_b32 exec_lo, exec_lo, s8 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 s5, s5, exec_lo | |
| ; GFX12-GISEL-NEXT: s_and_b32 s8, exec_lo, s9 | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 s3, s3, exec_lo | |
| ; GFX12-GISEL-NEXT: s_and_b32 s7, exec_lo, s7 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_or_b32 s5, s5, s8 | |
| ; GFX12-GISEL-NEXT: s_or_b32 s3, s3, s7 | |
| ; GFX12-GISEL-NEXT: .LBB0_3: ; %latch | |
| ; GFX12-GISEL-NEXT: ; in Loop: Header=BB0_4 Depth=1 | |
| ; GFX12-GISEL-NEXT: s_or_b32 exec_lo, exec_lo, s6 | |
| ; GFX12-GISEL-NEXT: s_add_co_i32 s4, s4, 1 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_cmp_lt_u32 s4, s2 | |
| ; GFX12-GISEL-NEXT: s_cbranch_scc0 .LBB0_7 | |
| ; GFX12-GISEL-NEXT: .LBB0_4: ; %loop | |
| ; GFX12-GISEL-NEXT: ; =>This Inner Loop Header: Depth=1 | |
| ; GFX12-GISEL-NEXT: s_and_saveexec_b32 s6, s5 | |
| ; GFX12-GISEL-NEXT: s_cbranch_execz .LBB0_3 | |
| ; GFX12-GISEL-NEXT: ; %bb.5: ; %if.live | |
| ; GFX12-GISEL-NEXT: ; in Loop: Header=BB0_4 Depth=1 | |
| ; GFX12-GISEL-NEXT: s_wait_loadcnt 0x0 | |
| ; GFX12-GISEL-NEXT: v_dual_mov_b32 v6, s1 :: v_dual_add_nc_u32 v3, s4, v2 | |
| ; GFX12-GISEL-NEXT: v_mov_b32_e32 v5, s0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s9, 0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s7, s3 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1) | |
| ; GFX12-GISEL-NEXT: v_ashrrev_i32_e32 v4, 31, v3 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s8, exec_lo | |
| ; GFX12-GISEL-NEXT: v_lshlrev_b64_e32 v[3:4], 2, v[3:4] | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2) | |
| ; GFX12-GISEL-NEXT: v_add_co_u32 v3, vcc_lo, v5, v3 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_va_vcc(0) | |
| ; GFX12-GISEL-NEXT: v_add_co_ci_u32_e64 v4, null, v6, v4, vcc_lo | |
| ; GFX12-GISEL-NEXT: global_load_b32 v3, v[3:4], off | |
| ; GFX12-GISEL-NEXT: s_wait_loadcnt 0x0 | |
| ; GFX12-GISEL-NEXT: v_and_b32_e32 v4, 1, v3 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(VALU_DEP_1) | |
| ; GFX12-GISEL-NEXT: v_cmpx_ne_u32_e32 0, v4 | |
| ; GFX12-GISEL-NEXT: s_cbranch_execz .LBB0_2 | |
| ; GFX12-GISEL-NEXT: ; %bb.6: ; %then.hit | |
| ; GFX12-GISEL-NEXT: ; in Loop: Header=BB0_4 Depth=1 | |
| ; GFX12-GISEL-NEXT: v_add_nc_u32_e32 v1, v1, v3 | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 s7, s3, exec_lo | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 s9, 0, exec_lo | |
| ; GFX12-GISEL-NEXT: s_or_b32 s7, s7, exec_lo | |
| ; GFX12-GISEL-NEXT: s_or_b32 s9, s9, exec_lo | |
| ; GFX12-GISEL-NEXT: s_branch .LBB0_2 | |
| ; GFX12-GISEL-NEXT: .LBB0_7: ; %exit | |
| ; GFX12-GISEL-NEXT: s_wait_loadcnt 0x0 | |
| ; GFX12-GISEL-NEXT: v_cndmask_b32_e64 v2, 0, 1, s3 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(VALU_DEP_1) | |
| ; GFX12-GISEL-NEXT: v_add_nc_u32_e32 v1, v1, v2 | |
| ; GFX12-GISEL-NEXT: global_store_b32 v0, v1, s[0:1] | |
| ; GFX12-GISEL-NEXT: s_endpgm | |
| entry: | |
| %tid = call i32 @llvm.amdgcn.workitem.id.x() | |
| %nraw = load i32, ptr addrspace(1) %buf, align 4 | |
| %n = and i32 %nraw, 15 | |
| %base.ptr = getelementptr i32, ptr addrspace(1) %buf, i32 %tid | |
| %base = load i32, ptr addrspace(1) %base.ptr, align 4 | |
| %go = icmp ne i32 %n, 0 | |
| br i1 %go, label %loop, label %exit | |
| loop: | |
| %i = phi i32 [ 0, %entry ], [ %i.next, %latch ] | |
| %acc = phi i32 [ 0, %entry ], [ %acc.next, %latch ] | |
| %live = phi i1 [ true, %entry ], [ %live.next, %latch ] | |
| %side = phi i1 [ false, %entry ], [ %side.next, %latch ] | |
| br i1 %live, label %if.live, label %latch | |
| if.live: | |
| %idx = add i32 %base, %i | |
| %element.ptr = getelementptr i32, ptr addrspace(1) %buf, i32 %idx | |
| %x = load i32, ptr addrspace(1) %element.ptr, align 4 | |
| %odd = trunc i32 %x to i1 | |
| br i1 %odd, label %then.hit, label %else.kill | |
| then.hit: | |
| %acc.hit = add i32 %acc, %x | |
| br label %latch | |
| else.kill: | |
| br label %latch | |
| latch: | |
| %acc.next = phi i32 [ %acc, %loop ], [ %acc.hit, %then.hit ], [ %acc, %else.kill ] | |
| %live.next = phi i1 [ %live, %loop ], [ true, %then.hit ], [ false, %else.kill ] | |
| %side.next = phi i1 [ %side, %loop ], [ true, %then.hit ], [ %side, %else.kill ] | |
| %i.next = add i32 %i, 1 | |
| %cont = icmp ult i32 %i.next, %n | |
| br i1 %cont, label %loop, label %exit | |
| exit: | |
| %acc.end = phi i32 [ 0, %entry ], [ %acc.next, %latch ] | |
| %side.end = phi i1 [ false, %entry ], [ %side.next, %latch ] | |
| %side.z = zext i1 %side.end to i32 | |
| %outv = add i32 %acc.end, %side.z | |
| store i32 %outv, ptr addrspace(1) %base.ptr, align 4 | |
| ret void | |
| } | |
| ; Lanes leave the loop at different iterations through a divergent break, so | |
| ; the loop-carried i1 that is live out of the loop must keep its merges. | |
| define amdgpu_kernel void @divergent_break_live_out(ptr addrspace(1) %buf, i32 %n) { | |
| ; GFX12-LABEL: divergent_break_live_out: | |
| ; GFX12: ; %bb.0: ; %entry | |
| ; GFX12-NEXT: s_load_b96 s[0:2], s[4:5], 0x0 | |
| ; GFX12-NEXT: v_and_b32_e32 v0, 0x3ff, v0 | |
| ; GFX12-NEXT: s_mov_b32 s6, 0 | |
| ; GFX12-NEXT: s_mov_b32 s3, 0 | |
| ; GFX12-NEXT: ; implicit-def: $sgpr4 | |
| ; GFX12-NEXT: ; implicit-def: $sgpr5 | |
| ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1) | |
| ; GFX12-NEXT: v_lshlrev_b32_e32 v0, 2, v0 | |
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | |
| ; GFX12-NEXT: v_add_co_u32 v0, s0, s0, v0 | |
| ; GFX12-NEXT: s_wait_alu depctr_va_sdst(0) | |
| ; GFX12-NEXT: v_add_co_ci_u32_e64 v1, null, s1, 0, s0 | |
| ; GFX12-NEXT: s_mov_b32 s0, 0 | |
| ; GFX12-NEXT: s_branch .LBB1_2 | |
| ; GFX12-NEXT: .LBB1_1: ; %Flow | |
| ; GFX12-NEXT: ; in Loop: Header=BB1_2 Depth=1 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_or_b32 exec_lo, exec_lo, s1 | |
| ; GFX12-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | |
| ; GFX12-NEXT: s_and_b32 s1, exec_lo, s7 | |
| ; GFX12-NEXT: s_and_not1_b32 s4, s4, exec_lo | |
| ; GFX12-NEXT: s_and_b32 s6, s5, exec_lo | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_or_b32 s3, s1, s3 | |
| ; GFX12-NEXT: s_or_b32 s4, s4, s6 | |
| ; GFX12-NEXT: s_mov_b32 s6, s5 | |
| ; GFX12-NEXT: s_and_not1_b32 exec_lo, exec_lo, s3 | |
| ; GFX12-NEXT: s_cbranch_execz .LBB1_4 | |
| ; GFX12-NEXT: .LBB1_2: ; %loop | |
| ; GFX12-NEXT: ; =>This Inner Loop Header: Depth=1 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_ashr_i32 s1, s0, 31 | |
| ; GFX12-NEXT: s_mov_b32 s7, -1 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_lshl_b64 s[8:9], s[0:1], 2 | |
| ; GFX12-NEXT: s_and_not1_b32 s1, s5, exec_lo | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: v_add_co_u32 v2, vcc_lo, v0, s8 | |
| ; GFX12-NEXT: s_wait_alu depctr_va_vcc(0) | |
| ; GFX12-NEXT: v_add_co_ci_u32_e64 v3, null, s9, v1, vcc_lo | |
| ; GFX12-NEXT: s_and_b32 s5, s6, exec_lo | |
| ; GFX12-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | |
| ; GFX12-NEXT: s_or_b32 s5, s1, s5 | |
| ; GFX12-NEXT: global_load_b32 v2, v[2:3], off | |
| ; GFX12-NEXT: s_mov_b32 s1, exec_lo | |
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | |
| ; GFX12-NEXT: v_cmpx_ne_u32_e32 0, v2 | |
| ; GFX12-NEXT: s_cbranch_execz .LBB1_1 | |
| ; GFX12-NEXT: ; %bb.3: ; %latch | |
| ; GFX12-NEXT: ; in Loop: Header=BB1_2 Depth=1 | |
| ; GFX12-NEXT: v_and_b32_e32 v2, 1, v2 | |
| ; GFX12-NEXT: s_add_co_i32 s0, s0, 1 | |
| ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | |
| ; GFX12-NEXT: v_cmp_eq_u32_e32 vcc_lo, 1, v2 | |
| ; GFX12-NEXT: s_xor_b32 s6, s6, vcc_lo | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_cmp_ge_u32 s0, s2 | |
| ; GFX12-NEXT: s_cselect_b32 s7, -1, 0 | |
| ; GFX12-NEXT: s_and_not1_b32 s5, s5, exec_lo | |
| ; GFX12-NEXT: s_and_b32 s6, s6, exec_lo | |
| ; GFX12-NEXT: s_or_not1_b32 s7, s7, exec_lo | |
| ; GFX12-NEXT: s_or_b32 s5, s5, s6 | |
| ; GFX12-NEXT: s_branch .LBB1_1 | |
| ; GFX12-NEXT: .LBB1_4: ; %exit | |
| ; GFX12-NEXT: s_or_b32 exec_lo, exec_lo, s3 | |
| ; GFX12-NEXT: v_cndmask_b32_e64 v2, 0, 1, s4 | |
| ; GFX12-NEXT: global_store_b32 v[0:1], v2, off | |
| ; GFX12-NEXT: s_endpgm | |
| ; | |
| ; GFX12-GISEL-LABEL: divergent_break_live_out: | |
| ; GFX12-GISEL: ; %bb.0: ; %entry | |
| ; GFX12-GISEL-NEXT: s_load_b96 s[0:2], s[4:5], 0x0 | |
| ; GFX12-GISEL-NEXT: v_and_b32_e32 v0, 0x3ff, v0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s6, 0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s3, 0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s4, 0 | |
| ; GFX12-GISEL-NEXT: ; implicit-def: $sgpr7 | |
| ; GFX12-GISEL-NEXT: s_wait_kmcnt 0x0 | |
| ; GFX12-GISEL-NEXT: v_dual_mov_b32 v1, s0 :: v_dual_lshlrev_b32 v0, 2, v0 | |
| ; GFX12-GISEL-NEXT: v_mov_b32_e32 v2, s1 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2) | |
| ; GFX12-GISEL-NEXT: v_add_co_u32 v1, vcc_lo, v1, v0 | |
| ; GFX12-GISEL-NEXT: v_add_co_ci_u32_e64 v2, null, 0, v2, vcc_lo | |
| ; GFX12-GISEL-NEXT: s_branch .LBB1_2 | |
| ; GFX12-GISEL-NEXT: .LBB1_1: ; %Flow | |
| ; GFX12-GISEL-NEXT: ; in Loop: Header=BB1_2 Depth=1 | |
| ; GFX12-GISEL-NEXT: s_or_b32 exec_lo, exec_lo, s5 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | |
| ; GFX12-GISEL-NEXT: s_and_b32 s5, exec_lo, s8 | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 s7, s7, exec_lo | |
| ; GFX12-GISEL-NEXT: s_and_b32 s8, exec_lo, s6 | |
| ; GFX12-GISEL-NEXT: s_or_b32 s3, s5, s3 | |
| ; GFX12-GISEL-NEXT: s_or_b32 s7, s7, s8 | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 exec_lo, exec_lo, s3 | |
| ; GFX12-GISEL-NEXT: s_cbranch_execz .LBB1_4 | |
| ; GFX12-GISEL-NEXT: .LBB1_2: ; %loop | |
| ; GFX12-GISEL-NEXT: ; =>This Inner Loop Header: Depth=1 | |
| ; GFX12-GISEL-NEXT: s_ashr_i32 s5, s4, 31 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s8, exec_lo | |
| ; GFX12-GISEL-NEXT: s_lshl_b64 s[10:11], s[4:5], 2 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s5, exec_lo | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: v_dual_mov_b32 v3, s10 :: v_dual_mov_b32 v4, s11 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2) | |
| ; GFX12-GISEL-NEXT: v_add_co_u32 v3, vcc_lo, v1, v3 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_va_vcc(0) | |
| ; GFX12-GISEL-NEXT: v_add_co_ci_u32_e64 v4, null, v2, v4, vcc_lo | |
| ; GFX12-GISEL-NEXT: global_load_b32 v3, v[3:4], off | |
| ; GFX12-GISEL-NEXT: s_wait_loadcnt 0x0 | |
| ; GFX12-GISEL-NEXT: v_cmpx_ne_u32_e32 0, v3 | |
| ; GFX12-GISEL-NEXT: s_cbranch_execz .LBB1_1 | |
| ; GFX12-GISEL-NEXT: ; %bb.3: ; %latch | |
| ; GFX12-GISEL-NEXT: ; in Loop: Header=BB1_2 Depth=1 | |
| ; GFX12-GISEL-NEXT: v_and_b32_e32 v3, 1, v3 | |
| ; GFX12-GISEL-NEXT: s_add_co_i32 s4, s4, 1 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(VALU_DEP_1) | |
| ; GFX12-GISEL-NEXT: v_cmp_ne_u32_e32 vcc_lo, 0, v3 | |
| ; GFX12-GISEL-NEXT: s_xor_b32 s9, s6, vcc_lo | |
| ; GFX12-GISEL-NEXT: s_cmp_ge_u32 s4, s2 | |
| ; GFX12-GISEL-NEXT: s_cselect_b32 s10, exec_lo, 0 | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 s6, s6, exec_lo | |
| ; GFX12-GISEL-NEXT: s_and_b32 s9, exec_lo, s9 | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 s8, s8, exec_lo | |
| ; GFX12-GISEL-NEXT: s_or_b32 s6, s6, s9 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_or_b32 s8, s8, s10 | |
| ; GFX12-GISEL-NEXT: s_branch .LBB1_1 | |
| ; GFX12-GISEL-NEXT: .LBB1_4: ; %exit | |
| ; GFX12-GISEL-NEXT: s_or_b32 exec_lo, exec_lo, s3 | |
| ; GFX12-GISEL-NEXT: v_cndmask_b32_e64 v1, 0, 1, s7 | |
| ; GFX12-GISEL-NEXT: global_store_b32 v0, v1, s[0:1] | |
| ; GFX12-GISEL-NEXT: s_endpgm | |
| entry: | |
| %tid = call i32 @llvm.amdgcn.workitem.id.x() | |
| %base.ptr = getelementptr i32, ptr addrspace(1) %buf, i32 %tid | |
| br label %loop | |
| loop: | |
| %i = phi i32 [ 0, %entry ], [ %i.next, %latch ] | |
| %flag = phi i1 [ false, %entry ], [ %flag.next, %latch ] | |
| %element.ptr = getelementptr i32, ptr addrspace(1) %base.ptr, i32 %i | |
| %x = load i32, ptr addrspace(1) %element.ptr, align 4 | |
| %stop = icmp eq i32 %x, 0 | |
| br i1 %stop, label %exit, label %latch | |
| latch: | |
| %odd = trunc i32 %x to i1 | |
| %flag.next = xor i1 %flag, %odd | |
| %i.next = add i32 %i, 1 | |
| %cont = icmp ult i32 %i.next, %n | |
| br i1 %cont, label %loop, label %exit | |
| exit: | |
| %flag.end = phi i1 [ %flag, %loop ], [ %flag.next, %latch ] | |
| %flag.z = zext i1 %flag.end to i32 | |
| store i32 %flag.z, ptr addrspace(1) %base.ptr, align 4 | |
| ret void | |
| } | |
| ; The loop condition itself is divergent, so lanes exit at different | |
| ; iterations and the merges across the back-edge must be kept. | |
| define amdgpu_kernel void @divergent_loop_cond(ptr addrspace(1) %buf) { | |
| ; GFX12-LABEL: divergent_loop_cond: | |
| ; GFX12: ; %bb.0: ; %entry | |
| ; GFX12-NEXT: s_load_b64 s[0:1], s[4:5], 0x0 | |
| ; GFX12-NEXT: v_and_b32_e32 v0, 0x3ff, v0 | |
| ; GFX12-NEXT: s_mov_b32 s5, 0 | |
| ; GFX12-NEXT: s_mov_b32 s4, 0 | |
| ; GFX12-NEXT: ; implicit-def: $sgpr6 | |
| ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | |
| ; GFX12-NEXT: v_lshlrev_b32_e32 v0, 2, v0 | |
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | |
| ; GFX12-NEXT: global_load_b32 v2, v0, s[0:1] | |
| ; GFX12-NEXT: v_add_co_u32 v0, s2, s0, v0 | |
| ; GFX12-NEXT: v_add_co_ci_u32_e64 v1, null, s1, 0, s2 | |
| ; GFX12-NEXT: s_mov_b32 s2, 0 | |
| ; GFX12-NEXT: s_branch .LBB2_2 | |
| ; GFX12-NEXT: .LBB2_1: ; %latch | |
| ; GFX12-NEXT: ; in Loop: Header=BB2_2 Depth=1 | |
| ; GFX12-NEXT: s_add_co_i32 s2, s2, 1 | |
| ; GFX12-NEXT: s_and_not1_b32 s3, s6, exec_lo | |
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: v_cmp_ge_u32_e32 vcc_lo, s2, v2 | |
| ; GFX12-NEXT: s_and_b32 s6, s5, exec_lo | |
| ; GFX12-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1) | |
| ; GFX12-NEXT: s_or_b32 s6, s3, s6 | |
| ; GFX12-NEXT: s_or_b32 s4, vcc_lo, s4 | |
| ; GFX12-NEXT: s_and_not1_b32 exec_lo, exec_lo, s4 | |
| ; GFX12-NEXT: s_cbranch_execz .LBB2_4 | |
| ; GFX12-NEXT: .LBB2_2: ; %loop | |
| ; GFX12-NEXT: ; =>This Inner Loop Header: Depth=1 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_ashr_i32 s3, s2, 31 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_lshl_b64 s[8:9], s[2:3], 2 | |
| ; GFX12-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | |
| ; GFX12-NEXT: s_add_nc_u64 s[8:9], s[0:1], s[8:9] | |
| ; GFX12-NEXT: s_load_b32 s3, s[8:9], 0x0 | |
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | |
| ; GFX12-NEXT: s_bitcmp0_b32 s3, 0 | |
| ; GFX12-NEXT: s_cbranch_scc1 .LBB2_1 | |
| ; GFX12-NEXT: ; %bb.3: ; %then.hit | |
| ; GFX12-NEXT: ; in Loop: Header=BB2_2 Depth=1 | |
| ; GFX12-NEXT: s_mov_b32 s5, -1 | |
| ; GFX12-NEXT: s_branch .LBB2_1 | |
| ; GFX12-NEXT: .LBB2_4: ; %exit | |
| ; GFX12-NEXT: s_or_b32 exec_lo, exec_lo, s4 | |
| ; GFX12-NEXT: v_cndmask_b32_e64 v2, 0, 1, s6 | |
| ; GFX12-NEXT: global_store_b32 v[0:1], v2, off | |
| ; GFX12-NEXT: s_endpgm | |
| ; | |
| ; GFX12-GISEL-LABEL: divergent_loop_cond: | |
| ; GFX12-GISEL: ; %bb.0: ; %entry | |
| ; GFX12-GISEL-NEXT: s_load_b64 s[0:1], s[4:5], 0x0 | |
| ; GFX12-GISEL-NEXT: v_and_b32_e32 v0, 0x3ff, v0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s4, 0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s2, 0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s6, 0 | |
| ; GFX12-GISEL-NEXT: ; implicit-def: $sgpr5 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(VALU_DEP_1) | |
| ; GFX12-GISEL-NEXT: v_lshlrev_b32_e32 v0, 2, v0 | |
| ; GFX12-GISEL-NEXT: s_wait_kmcnt 0x0 | |
| ; GFX12-GISEL-NEXT: global_load_b32 v1, v0, s[0:1] | |
| ; GFX12-GISEL-NEXT: s_branch .LBB2_2 | |
| ; GFX12-GISEL-NEXT: .LBB2_1: ; %latch | |
| ; GFX12-GISEL-NEXT: ; in Loop: Header=BB2_2 Depth=1 | |
| ; GFX12-GISEL-NEXT: s_and_b32 s3, s6, 1 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_cmp_lg_u32 s3, 0 | |
| ; GFX12-GISEL-NEXT: s_cselect_b32 s3, exec_lo, 0 | |
| ; GFX12-GISEL-NEXT: s_add_co_i32 s2, s2, 1 | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 s5, s5, exec_lo | |
| ; GFX12-GISEL-NEXT: s_wait_loadcnt 0x0 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: v_cmp_ge_u32_e32 vcc_lo, s2, v1 | |
| ; GFX12-GISEL-NEXT: s_or_b32 s5, s5, s3 | |
| ; GFX12-GISEL-NEXT: s_or_b32 s4, vcc_lo, s4 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 exec_lo, exec_lo, s4 | |
| ; GFX12-GISEL-NEXT: s_cbranch_execz .LBB2_4 | |
| ; GFX12-GISEL-NEXT: .LBB2_2: ; %loop | |
| ; GFX12-GISEL-NEXT: ; =>This Inner Loop Header: Depth=1 | |
| ; GFX12-GISEL-NEXT: s_ashr_i32 s3, s2, 31 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_lshl_b64 s[8:9], s[2:3], 2 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | |
| ; GFX12-GISEL-NEXT: s_add_co_u32 s8, s0, s8 | |
| ; GFX12-GISEL-NEXT: s_add_co_ci_u32 s9, s1, s9 | |
| ; GFX12-GISEL-NEXT: s_load_b32 s3, s[8:9], 0x0 | |
| ; GFX12-GISEL-NEXT: s_wait_kmcnt 0x0 | |
| ; GFX12-GISEL-NEXT: s_xor_b32 s3, s3, 1 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_and_b32 s3, s3, 1 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_cmp_lg_u32 s3, 0 | |
| ; GFX12-GISEL-NEXT: s_cbranch_scc1 .LBB2_1 | |
| ; GFX12-GISEL-NEXT: ; %bb.3: ; %then.hit | |
| ; GFX12-GISEL-NEXT: ; in Loop: Header=BB2_2 Depth=1 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s6, 1 | |
| ; GFX12-GISEL-NEXT: s_branch .LBB2_1 | |
| ; GFX12-GISEL-NEXT: .LBB2_4: ; %exit | |
| ; GFX12-GISEL-NEXT: s_or_b32 exec_lo, exec_lo, s4 | |
| ; GFX12-GISEL-NEXT: v_cndmask_b32_e64 v1, 0, 1, s5 | |
| ; GFX12-GISEL-NEXT: global_store_b32 v0, v1, s[0:1] | |
| ; GFX12-GISEL-NEXT: s_endpgm | |
| entry: | |
| %tid = call i32 @llvm.amdgcn.workitem.id.x() | |
| %base.ptr = getelementptr i32, ptr addrspace(1) %buf, i32 %tid | |
| %n = load i32, ptr addrspace(1) %base.ptr, align 4 | |
| br label %loop | |
| loop: | |
| %i = phi i32 [ 0, %entry ], [ %i.next, %latch ] | |
| %side = phi i1 [ false, %entry ], [ %side.next, %latch ] | |
| %element.ptr = getelementptr i32, ptr addrspace(1) %buf, i32 %i | |
| %x = load i32, ptr addrspace(1) %element.ptr, align 4 | |
| %odd = trunc i32 %x to i1 | |
| br i1 %odd, label %then.hit, label %latch | |
| then.hit: | |
| br label %latch | |
| latch: | |
| %side.next = phi i1 [ %side, %loop ], [ true, %then.hit ] | |
| %i.next = add i32 %i, 1 | |
| %cont = icmp ult i32 %i.next, %n | |
| br i1 %cont, label %loop, label %exit | |
| exit: | |
| %side.z = zext i1 %side.next to i32 | |
| store i32 %side.z, ptr addrspace(1) %base.ptr, align 4 | |
| ret void | |
| } | |
| ; The inner loop has a uniform trip count and needs no back-edge merges, but | |
| ; the outer loop exits divergently, so the outer loop-carried i1 keeps them. | |
| define amdgpu_kernel void @nested_inner_uniform(ptr addrspace(1) %buf, i32 %m) { | |
| ; GFX12-LABEL: nested_inner_uniform: | |
| ; GFX12: ; %bb.0: ; %entry | |
| ; GFX12-NEXT: s_load_b96 s[0:2], s[4:5], 0x0 | |
| ; GFX12-NEXT: v_and_b32_e32 v0, 0x3ff, v0 | |
| ; GFX12-NEXT: s_mov_b32 s3, 0 | |
| ; GFX12-NEXT: ; implicit-def: $sgpr4 | |
| ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | |
| ; GFX12-NEXT: v_lshlrev_b32_e32 v0, 2, v0 | |
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | |
| ; GFX12-NEXT: global_load_b32 v2, v0, s[0:1] | |
| ; GFX12-NEXT: v_add_co_u32 v0, s0, s0, v0 | |
| ; GFX12-NEXT: s_wait_alu depctr_va_sdst(0) | |
| ; GFX12-NEXT: v_add_co_ci_u32_e64 v1, null, s1, 0, s0 | |
| ; GFX12-NEXT: s_mov_b32 s0, 0 | |
| ; GFX12-NEXT: s_mov_b32 s1, 0 | |
| ; GFX12-NEXT: s_branch .LBB3_2 | |
| ; GFX12-NEXT: .LBB3_1: ; %outer.latch | |
| ; GFX12-NEXT: ; in Loop: Header=BB3_2 Depth=1 | |
| ; GFX12-NEXT: s_add_co_i32 s1, s1, 1 | |
| ; GFX12-NEXT: s_and_not1_b32 s4, s4, exec_lo | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: v_cmp_ge_u32_e32 vcc_lo, s1, v2 | |
| ; GFX12-NEXT: s_and_b32 s5, s3, exec_lo | |
| ; GFX12-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | |
| ; GFX12-NEXT: s_or_b32 s4, s4, s5 | |
| ; GFX12-NEXT: s_or_b32 s0, vcc_lo, s0 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_and_not1_b32 exec_lo, exec_lo, s0 | |
| ; GFX12-NEXT: s_cbranch_execz .LBB3_6 | |
| ; GFX12-NEXT: .LBB3_2: ; %outer | |
| ; GFX12-NEXT: ; =>This Loop Header: Depth=1 | |
| ; GFX12-NEXT: ; Child Loop BB3_4 Depth 2 | |
| ; GFX12-NEXT: s_mov_b32 s5, s3 | |
| ; GFX12-NEXT: s_mov_b32 s6, 0 | |
| ; GFX12-NEXT: s_branch .LBB3_4 | |
| ; GFX12-NEXT: .LBB3_3: ; %inner.latch | |
| ; GFX12-NEXT: ; in Loop: Header=BB3_4 Depth=2 | |
| ; GFX12-NEXT: s_or_b32 exec_lo, exec_lo, s7 | |
| ; GFX12-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | |
| ; GFX12-NEXT: s_and_not1_b32 s3, s3, exec_lo | |
| ; GFX12-NEXT: s_and_b32 s7, s5, exec_lo | |
| ; GFX12-NEXT: s_add_co_i32 s6, s6, 1 | |
| ; GFX12-NEXT: s_or_b32 s3, s3, s7 | |
| ; GFX12-NEXT: s_cmp_lt_u32 s6, s2 | |
| ; GFX12-NEXT: s_cbranch_scc0 .LBB3_1 | |
| ; GFX12-NEXT: .LBB3_4: ; %inner | |
| ; GFX12-NEXT: ; Parent Loop BB3_2 Depth=1 | |
| ; GFX12-NEXT: ; => This Inner Loop Header: Depth=2 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_add_co_i32 s8, s1, s6 | |
| ; GFX12-NEXT: s_mov_b32 s7, exec_lo | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_ashr_i32 s9, s8, 31 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: s_lshl_b64 s[8:9], s[8:9], 2 | |
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-NEXT: v_add_co_u32 v3, vcc_lo, v0, s8 | |
| ; GFX12-NEXT: s_wait_alu depctr_va_vcc(0) | |
| ; GFX12-NEXT: v_add_co_ci_u32_e64 v4, null, s9, v1, vcc_lo | |
| ; GFX12-NEXT: global_load_b32 v3, v[3:4], off | |
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | |
| ; GFX12-NEXT: v_and_b32_e32 v3, 1, v3 | |
| ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | |
| ; GFX12-NEXT: v_cmpx_eq_u32_e32 1, v3 | |
| ; GFX12-NEXT: s_cbranch_execz .LBB3_3 | |
| ; GFX12-NEXT: ; %bb.5: ; %then.hit | |
| ; GFX12-NEXT: ; in Loop: Header=BB3_4 Depth=2 | |
| ; GFX12-NEXT: s_or_b32 s5, s5, exec_lo | |
| ; GFX12-NEXT: s_branch .LBB3_3 | |
| ; GFX12-NEXT: .LBB3_6: ; %exit | |
| ; GFX12-NEXT: s_or_b32 exec_lo, exec_lo, s0 | |
| ; GFX12-NEXT: v_cndmask_b32_e64 v2, 0, 1, s4 | |
| ; GFX12-NEXT: global_store_b32 v[0:1], v2, off | |
| ; GFX12-NEXT: s_endpgm | |
| ; | |
| ; GFX12-GISEL-LABEL: nested_inner_uniform: | |
| ; GFX12-GISEL: ; %bb.0: ; %entry | |
| ; GFX12-GISEL-NEXT: s_load_b96 s[0:2], s[4:5], 0x0 | |
| ; GFX12-GISEL-NEXT: v_and_b32_e32 v0, 0x3ff, v0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s3, 0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s5, 0 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s4, 0 | |
| ; GFX12-GISEL-NEXT: ; implicit-def: $sgpr6 | |
| ; GFX12-GISEL-NEXT: s_wait_kmcnt 0x0 | |
| ; GFX12-GISEL-NEXT: v_dual_mov_b32 v3, s1 :: v_dual_lshlrev_b32 v0, 2, v0 | |
| ; GFX12-GISEL-NEXT: v_mov_b32_e32 v2, s0 | |
| ; GFX12-GISEL-NEXT: global_load_b32 v1, v0, s[0:1] | |
| ; GFX12-GISEL-NEXT: v_add_co_u32 v2, vcc_lo, v2, v0 | |
| ; GFX12-GISEL-NEXT: v_add_co_ci_u32_e64 v3, null, 0, v3, vcc_lo | |
| ; GFX12-GISEL-NEXT: s_branch .LBB3_2 | |
| ; GFX12-GISEL-NEXT: .LBB3_1: ; %outer.latch | |
| ; GFX12-GISEL-NEXT: ; in Loop: Header=BB3_2 Depth=1 | |
| ; GFX12-GISEL-NEXT: s_add_co_i32 s4, s4, 1 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: v_cmp_ge_u32_e32 vcc_lo, s4, v1 | |
| ; GFX12-GISEL-NEXT: s_or_b32 s3, vcc_lo, s3 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 exec_lo, exec_lo, s3 | |
| ; GFX12-GISEL-NEXT: s_cbranch_execz .LBB3_6 | |
| ; GFX12-GISEL-NEXT: .LBB3_2: ; %outer | |
| ; GFX12-GISEL-NEXT: ; =>This Loop Header: Depth=1 | |
| ; GFX12-GISEL-NEXT: ; Child Loop BB3_4 Depth 2 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s7, 0 | |
| ; GFX12-GISEL-NEXT: s_branch .LBB3_4 | |
| ; GFX12-GISEL-NEXT: .LBB3_3: ; %inner.latch | |
| ; GFX12-GISEL-NEXT: ; in Loop: Header=BB3_4 Depth=2 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_or_b32 exec_lo, exec_lo, s8 | |
| ; GFX12-GISEL-NEXT: s_add_co_i32 s7, s7, 1 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | |
| ; GFX12-GISEL-NEXT: s_cmp_lt_u32 s7, s2 | |
| ; GFX12-GISEL-NEXT: s_cselect_b32 s8, 1, 0 | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 s6, s6, exec_lo | |
| ; GFX12-GISEL-NEXT: s_and_b32 s9, exec_lo, s5 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_or_b32 s6, s6, s9 | |
| ; GFX12-GISEL-NEXT: s_cmp_lg_u32 s8, 0 | |
| ; GFX12-GISEL-NEXT: s_cbranch_scc0 .LBB3_1 | |
| ; GFX12-GISEL-NEXT: .LBB3_4: ; %inner | |
| ; GFX12-GISEL-NEXT: ; Parent Loop BB3_2 Depth=1 | |
| ; GFX12-GISEL-NEXT: ; => This Inner Loop Header: Depth=2 | |
| ; GFX12-GISEL-NEXT: s_add_co_i32 s8, s4, s7 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_ashr_i32 s9, s8, 31 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_lshl_b64 s[8:9], s[8:9], 2 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: v_dual_mov_b32 v4, s8 :: v_dual_mov_b32 v5, s9 | |
| ; GFX12-GISEL-NEXT: s_mov_b32 s8, exec_lo | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2) | |
| ; GFX12-GISEL-NEXT: v_add_co_u32 v4, vcc_lo, v2, v4 | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_va_vcc(0) | |
| ; GFX12-GISEL-NEXT: v_add_co_ci_u32_e64 v5, null, v3, v5, vcc_lo | |
| ; GFX12-GISEL-NEXT: global_load_b32 v4, v[4:5], off | |
| ; GFX12-GISEL-NEXT: s_wait_loadcnt 0x0 | |
| ; GFX12-GISEL-NEXT: v_and_b32_e32 v4, 1, v4 | |
| ; GFX12-GISEL-NEXT: s_delay_alu instid0(VALU_DEP_1) | |
| ; GFX12-GISEL-NEXT: v_cmpx_ne_u32_e32 0, v4 | |
| ; GFX12-GISEL-NEXT: s_cbranch_execz .LBB3_3 | |
| ; GFX12-GISEL-NEXT: ; %bb.5: ; %then.hit | |
| ; GFX12-GISEL-NEXT: ; in Loop: Header=BB3_4 Depth=2 | |
| ; GFX12-GISEL-NEXT: s_and_not1_b32 s5, s5, exec_lo | |
| ; GFX12-GISEL-NEXT: s_wait_alu depctr_sa_sdst(0) | |
| ; GFX12-GISEL-NEXT: s_or_b32 s5, s5, exec_lo | |
| ; GFX12-GISEL-NEXT: s_branch .LBB3_3 | |
| ; GFX12-GISEL-NEXT: .LBB3_6: ; %exit | |
| ; GFX12-GISEL-NEXT: s_or_b32 exec_lo, exec_lo, s3 | |
| ; GFX12-GISEL-NEXT: v_cndmask_b32_e64 v1, 0, 1, s6 | |
| ; GFX12-GISEL-NEXT: global_store_b32 v0, v1, s[0:1] | |
| ; GFX12-GISEL-NEXT: s_endpgm | |
| entry: | |
| %tid = call i32 @llvm.amdgcn.workitem.id.x() | |
| %base.ptr = getelementptr i32, ptr addrspace(1) %buf, i32 %tid | |
| %n = load i32, ptr addrspace(1) %base.ptr, align 4 | |
| br label %outer | |
| outer: | |
| %j = phi i32 [ 0, %entry ], [ %j.next, %outer.latch ] | |
| %any = phi i1 [ false, %entry ], [ %any.next, %outer.latch ] | |
| br label %inner | |
| inner: | |
| %i = phi i32 [ 0, %outer ], [ %i.next, %inner.latch ] | |
| %side = phi i1 [ %any, %outer ], [ %side.next, %inner.latch ] | |
| %idx = add i32 %i, %j | |
| %element.ptr = getelementptr i32, ptr addrspace(1) %base.ptr, i32 %idx | |
| %x = load i32, ptr addrspace(1) %element.ptr, align 4 | |
| %odd = trunc i32 %x to i1 | |
| br i1 %odd, label %then.hit, label %inner.latch | |
| then.hit: | |
| br label %inner.latch | |
| inner.latch: | |
| %side.next = phi i1 [ %side, %inner ], [ true, %then.hit ] | |
| %i.next = add i32 %i, 1 | |
| %inner.cont = icmp ult i32 %i.next, %m | |
| br i1 %inner.cont, label %inner, label %outer.latch | |
| outer.latch: | |
| %any.next = phi i1 [ %side.next, %inner.latch ] | |
| %j.next = add i32 %j, 1 | |
| %outer.cont = icmp ult i32 %j.next, %n | |
| br i1 %outer.cont, label %outer, label %exit | |
| exit: | |
| %any.z = zext i1 %any.next to i32 | |
| store i32 %any.z, ptr addrspace(1) %base.ptr, align 4 | |
| ret void | |
| } |