|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
| 2 | + |
| 3 | +; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -mattr=-enable-flat-scratch < %s | FileCheck --check-prefixes=GFX90A,GFX90A-MUBUF %s |
| 4 | +; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -mattr=+enable-flat-scratch < %s | FileCheck --check-prefixes=GFX90A,GFX90A-FLATSCR %s |
| 5 | +; RUN: llc -mtriple=amdgcn -mcpu=gfx1030 -mattr=-enable-flat-scratch < %s | FileCheck --check-prefixes=GFX10,GFX10-MUBUF %s |
| 6 | +; RUN: llc -mtriple=amdgcn -mcpu=gfx1030 -mattr=+enable-flat-scratch < %s | FileCheck --check-prefixes=GFX10,GFX10-FLATSCR %s |
| 7 | +; RUN: llc -mtriple=amdgcn -mcpu=gfx942 < %s | FileCheck --check-prefixes=GFX942 %s |
| 8 | +; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 < %s | FileCheck --check-prefixes=GFX11 %s |
| 9 | +; RUN: llc -mtriple=amdgcn -mcpu=gfx1200 < %s | FileCheck --check-prefixes=GFX12 %s |
| 10 | + |
| 11 | +; This test checks memory addresses with constant offset components that should |
| 12 | +; not be folded into memory accesses with immediate offsets. |
| 13 | +; SeparateConstOffsetsFromGEP transforms the GEPs in a way that can lead to |
| 14 | +; out-of-bounds or negative intermediate results in the address computation, |
| 15 | +; which are problematic for flat and scratch instructions: |
| 16 | +; gep[inbounds](p, i + 3) -> gep(gep(p, i), 3) |
| 17 | + |
| 18 | + |
| 19 | +; FIXME the offset here should not be folded: if %p points to the beginning of |
| 20 | +; scratch or LDS and %i is -1, a folded offset crashes the program. |
| 21 | +define i32 @flat_offset_maybe_oob(ptr %p, i32 %i) { |
| 22 | +; GFX90A-LABEL: flat_offset_maybe_oob: |
| 23 | +; GFX90A: ; %bb.0: |
| 24 | +; GFX90A-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) |
| 25 | +; GFX90A-NEXT: v_ashrrev_i32_e32 v3, 31, v2 |
| 26 | +; GFX90A-NEXT: v_lshlrev_b64 v[2:3], 2, v[2:3] |
| 27 | +; GFX90A-NEXT: v_add_co_u32_e32 v0, vcc, v0, v2 |
| 28 | +; GFX90A-NEXT: v_addc_co_u32_e32 v1, vcc, v1, v3, vcc |
| 29 | +; GFX90A-NEXT: flat_load_dword v0, v[0:1] offset:12 |
| 30 | +; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0) |
| 31 | +; GFX90A-NEXT: s_setpc_b64 s[30:31] |
| 32 | +; |
| 33 | +; GFX10-LABEL: flat_offset_maybe_oob: |
| 34 | +; GFX10: ; %bb.0: |
| 35 | +; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) |
| 36 | +; GFX10-NEXT: v_ashrrev_i32_e32 v3, 31, v2 |
| 37 | +; GFX10-NEXT: v_lshlrev_b64 v[2:3], 2, v[2:3] |
| 38 | +; GFX10-NEXT: v_add_co_u32 v0, vcc_lo, v0, v2 |
| 39 | +; GFX10-NEXT: v_add_co_ci_u32_e32 v1, vcc_lo, v1, v3, vcc_lo |
| 40 | +; GFX10-NEXT: flat_load_dword v0, v[0:1] offset:12 |
| 41 | +; GFX10-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0) |
| 42 | +; GFX10-NEXT: s_setpc_b64 s[30:31] |
| 43 | +; |
| 44 | +; GFX942-LABEL: flat_offset_maybe_oob: |
| 45 | +; GFX942: ; %bb.0: |
| 46 | +; GFX942-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) |
| 47 | +; GFX942-NEXT: v_ashrrev_i32_e32 v3, 31, v2 |
| 48 | +; GFX942-NEXT: v_lshl_add_u64 v[0:1], v[2:3], 2, v[0:1] |
| 49 | +; GFX942-NEXT: flat_load_dword v0, v[0:1] offset:12 |
| 50 | +; GFX942-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0) |
| 51 | +; GFX942-NEXT: s_setpc_b64 s[30:31] |
| 52 | +; |
| 53 | +; GFX11-LABEL: flat_offset_maybe_oob: |
| 54 | +; GFX11: ; %bb.0: |
| 55 | +; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) |
| 56 | +; GFX11-NEXT: v_ashrrev_i32_e32 v3, 31, v2 |
| 57 | +; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1) |
| 58 | +; GFX11-NEXT: v_lshlrev_b64 v[2:3], 2, v[2:3] |
| 59 | +; GFX11-NEXT: v_add_co_u32 v0, vcc_lo, v0, v2 |
| 60 | +; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_2) |
| 61 | +; GFX11-NEXT: v_add_co_ci_u32_e32 v1, vcc_lo, v1, v3, vcc_lo |
| 62 | +; GFX11-NEXT: flat_load_b32 v0, v[0:1] offset:12 |
| 63 | +; GFX11-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0) |
| 64 | +; GFX11-NEXT: s_setpc_b64 s[30:31] |
| 65 | +; |
| 66 | +; GFX12-LABEL: flat_offset_maybe_oob: |
| 67 | +; GFX12: ; %bb.0: |
| 68 | +; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 |
| 69 | +; GFX12-NEXT: s_wait_expcnt 0x0 |
| 70 | +; GFX12-NEXT: s_wait_samplecnt 0x0 |
| 71 | +; GFX12-NEXT: s_wait_bvhcnt 0x0 |
| 72 | +; GFX12-NEXT: s_wait_kmcnt 0x0 |
| 73 | +; GFX12-NEXT: v_ashrrev_i32_e32 v3, 31, v2 |
| 74 | +; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1) |
| 75 | +; GFX12-NEXT: v_lshlrev_b64_e32 v[2:3], 2, v[2:3] |
| 76 | +; GFX12-NEXT: v_add_co_u32 v0, vcc_lo, v0, v2 |
| 77 | +; GFX12-NEXT: s_wait_alu 0xfffd |
| 78 | +; GFX12-NEXT: v_add_co_ci_u32_e32 v1, vcc_lo, v1, v3, vcc_lo |
| 79 | +; GFX12-NEXT: flat_load_b32 v0, v[0:1] offset:12 |
| 80 | +; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 |
| 81 | +; GFX12-NEXT: s_wait_alu 0xfffd |
| 82 | +; GFX12-NEXT: s_setpc_b64 s[30:31] |
| 83 | + %idx = add nsw i32 %i, 3 |
| 84 | + %arrayidx = getelementptr inbounds i32, ptr %p, i32 %idx |
| 85 | + %l = load i32, ptr %arrayidx |
| 86 | + ret i32 %l |
| 87 | +} |
| 88 | + |
| 89 | +; For MUBUF and for GFX12, folding the offset is okay. |
| 90 | +define i32 @private_offset_maybe_oob(ptr addrspace(5) %p, i32 %i) { |
| 91 | +; GFX90A-MUBUF-LABEL: private_offset_maybe_oob: |
| 92 | +; GFX90A-MUBUF: ; %bb.0: |
| 93 | +; GFX90A-MUBUF-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) |
| 94 | +; GFX90A-MUBUF-NEXT: v_lshl_add_u32 v0, v1, 2, v0 |
| 95 | +; GFX90A-MUBUF-NEXT: buffer_load_dword v0, v0, s[0:3], 0 offen offset:12 |
| 96 | +; GFX90A-MUBUF-NEXT: s_waitcnt vmcnt(0) |
| 97 | +; GFX90A-MUBUF-NEXT: s_setpc_b64 s[30:31] |
| 98 | +; |
| 99 | +; GFX90A-FLATSCR-LABEL: private_offset_maybe_oob: |
| 100 | +; GFX90A-FLATSCR: ; %bb.0: |
| 101 | +; GFX90A-FLATSCR-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) |
| 102 | +; GFX90A-FLATSCR-NEXT: v_lshlrev_b32_e32 v1, 2, v1 |
| 103 | +; GFX90A-FLATSCR-NEXT: v_add3_u32 v0, v0, v1, 12 |
| 104 | +; GFX90A-FLATSCR-NEXT: scratch_load_dword v0, v0, off |
| 105 | +; GFX90A-FLATSCR-NEXT: s_waitcnt vmcnt(0) |
| 106 | +; GFX90A-FLATSCR-NEXT: s_setpc_b64 s[30:31] |
| 107 | +; |
| 108 | +; GFX10-MUBUF-LABEL: private_offset_maybe_oob: |
| 109 | +; GFX10-MUBUF: ; %bb.0: |
| 110 | +; GFX10-MUBUF-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) |
| 111 | +; GFX10-MUBUF-NEXT: v_lshl_add_u32 v0, v1, 2, v0 |
| 112 | +; GFX10-MUBUF-NEXT: buffer_load_dword v0, v0, s[0:3], 0 offen offset:12 |
| 113 | +; GFX10-MUBUF-NEXT: s_waitcnt vmcnt(0) |
| 114 | +; GFX10-MUBUF-NEXT: s_setpc_b64 s[30:31] |
| 115 | +; |
| 116 | +; GFX10-FLATSCR-LABEL: private_offset_maybe_oob: |
| 117 | +; GFX10-FLATSCR: ; %bb.0: |
| 118 | +; GFX10-FLATSCR-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) |
| 119 | +; GFX10-FLATSCR-NEXT: v_lshlrev_b32_e32 v1, 2, v1 |
| 120 | +; GFX10-FLATSCR-NEXT: v_add3_u32 v0, v0, v1, 12 |
| 121 | +; GFX10-FLATSCR-NEXT: scratch_load_dword v0, v0, off |
| 122 | +; GFX10-FLATSCR-NEXT: s_waitcnt vmcnt(0) |
| 123 | +; GFX10-FLATSCR-NEXT: s_setpc_b64 s[30:31] |
| 124 | +; |
| 125 | +; GFX942-LABEL: private_offset_maybe_oob: |
| 126 | +; GFX942: ; %bb.0: |
| 127 | +; GFX942-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) |
| 128 | +; GFX942-NEXT: v_lshlrev_b32_e32 v1, 2, v1 |
| 129 | +; GFX942-NEXT: v_add3_u32 v0, v0, v1, 12 |
| 130 | +; GFX942-NEXT: scratch_load_dword v0, v0, off |
| 131 | +; GFX942-NEXT: s_waitcnt vmcnt(0) |
| 132 | +; GFX942-NEXT: s_setpc_b64 s[30:31] |
| 133 | +; |
| 134 | +; GFX11-LABEL: private_offset_maybe_oob: |
| 135 | +; GFX11: ; %bb.0: |
| 136 | +; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) |
| 137 | +; GFX11-NEXT: v_lshlrev_b32_e32 v1, 2, v1 |
| 138 | +; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1) |
| 139 | +; GFX11-NEXT: v_add3_u32 v0, v0, v1, 12 |
| 140 | +; GFX11-NEXT: scratch_load_b32 v0, v0, off |
| 141 | +; GFX11-NEXT: s_waitcnt vmcnt(0) |
| 142 | +; GFX11-NEXT: s_setpc_b64 s[30:31] |
| 143 | +; |
| 144 | +; GFX12-LABEL: private_offset_maybe_oob: |
| 145 | +; GFX12: ; %bb.0: |
| 146 | +; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 |
| 147 | +; GFX12-NEXT: s_wait_expcnt 0x0 |
| 148 | +; GFX12-NEXT: s_wait_samplecnt 0x0 |
| 149 | +; GFX12-NEXT: s_wait_bvhcnt 0x0 |
| 150 | +; GFX12-NEXT: s_wait_kmcnt 0x0 |
| 151 | +; GFX12-NEXT: v_lshl_add_u32 v0, v1, 2, v0 |
| 152 | +; GFX12-NEXT: scratch_load_b32 v0, v0, off offset:12 |
| 153 | +; GFX12-NEXT: s_wait_loadcnt 0x0 |
| 154 | +; GFX12-NEXT: s_setpc_b64 s[30:31] |
| 155 | + %idx = add nsw i32 %i, 3 |
| 156 | + %arrayidx = getelementptr inbounds i32, ptr addrspace(5) %p, i32 %idx |
| 157 | + %l = load i32, ptr addrspace(5) %arrayidx |
| 158 | + ret i32 %l |
| 159 | +} |
0 commit comments