Skip to content

Commit 9a415f6

Browse files
authored
[GlobalISel] Fold ptrtoint(undef) and inttoptr(undef) to undef. (#119073)
This helps with shuffles a little, and one of the amd gpu tests is now equivalent to the SDAG version.
1 parent beea456 commit 9a415f6

File tree

4 files changed

+50
-68
lines changed

4 files changed

+50
-68
lines changed

llvm/include/llvm/Target/GlobalISel/Combine.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def unary_undef_to_zero: GICombineRule<
428428
// replaced with undef.
429429
def propagate_undef_any_op: GICombineRule<
430430
(defs root:$root),
431-
(match (wip_match_opcode G_ADD, G_FPTOSI, G_FPTOUI, G_SUB, G_XOR, G_TRUNC, G_BITCAST, G_ANYEXT):$root,
431+
(match (wip_match_opcode G_ADD, G_FPTOSI, G_FPTOUI, G_SUB, G_XOR, G_TRUNC, G_BITCAST, G_ANYEXT, G_PTRTOINT, G_INTTOPTR):$root,
432432
[{ return Helper.matchAnyExplicitUseIsUndef(*${root}); }]),
433433
(apply [{ Helper.replaceInstWithUndef(*${root}); }])>;
434434

llvm/test/CodeGen/AArch64/GlobalISel/combine-cast.mir

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,27 @@ body: |
217217
%large:_(<2 x s64>) = G_ANYEXT %bv(<2 x s32>)
218218
$q0 = COPY %large(<2 x s64>)
219219
$d0 = COPY %bv(<2 x s32>)
220+
...
221+
---
222+
name: test_undef_ptrtoint
223+
legalized: true
224+
body: |
225+
bb.1:
226+
; CHECK-LABEL: name: test_undef_ptrtoint
227+
; CHECK: [[DEF:%[0-9]+]]:_(<2 x s64>) = G_IMPLICIT_DEF
228+
; CHECK-NEXT: $q0 = COPY [[DEF]](<2 x s64>)
229+
%0:_(<2 x p0>) = G_IMPLICIT_DEF
230+
%1:_(<2 x s64>) = G_PTRTOINT %0(<2 x p0>)
231+
$q0 = COPY %1(<2 x s64>)
232+
...
233+
---
234+
name: test_undef_inttoptr
235+
legalized: true
236+
body: |
237+
bb.1:
238+
; CHECK-LABEL: name: test_undef_inttoptr
239+
; CHECK: [[DEF:%[0-9]+]]:_(<2 x p0>) = G_IMPLICIT_DEF
240+
; CHECK-NEXT: $q0 = COPY [[DEF]](<2 x p0>)
241+
%0:_(<2 x s64>) = G_IMPLICIT_DEF
242+
%1:_(<2 x p0>) = G_INTTOPTR %0(<2 x s64>)
243+
$q0 = COPY %1(<2 x p0>)

llvm/test/CodeGen/AArch64/neon-reverseshuffle.ll

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,10 @@ entry:
1313
}
1414

1515
define <2 x ptr> @v2p0(<2 x ptr> %a) {
16-
; CHECK-SD-LABEL: v2p0:
17-
; CHECK-SD: // %bb.0: // %entry
18-
; CHECK-SD-NEXT: ext v0.16b, v0.16b, v0.16b, #8
19-
; CHECK-SD-NEXT: ret
20-
;
21-
; CHECK-GI-LABEL: v2p0:
22-
; CHECK-GI: // %bb.0: // %entry
23-
; CHECK-GI-NEXT: adrp x8, .LCPI1_0
24-
; CHECK-GI-NEXT: // kill: def $q0 killed $q0 def $q0_q1
25-
; CHECK-GI-NEXT: ldr q2, [x8, :lo12:.LCPI1_0]
26-
; CHECK-GI-NEXT: tbl v0.16b, { v0.16b, v1.16b }, v2.16b
27-
; CHECK-GI-NEXT: ret
16+
; CHECK-LABEL: v2p0:
17+
; CHECK: // %bb.0: // %entry
18+
; CHECK-NEXT: ext v0.16b, v0.16b, v0.16b, #8
19+
; CHECK-NEXT: ret
2820
entry:
2921
%V128 = shufflevector <2 x ptr> %a, <2 x ptr> undef, <2 x i32> <i32 1, i32 0>
3022
ret <2 x ptr> %V128

llvm/test/CodeGen/AMDGPU/lds-global-non-entry-func.ll

Lines changed: 21 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -100,59 +100,29 @@ define void @func_use_lds_global() {
100100

101101
; ERR: warning: <unknown>:0:0: in function func_use_lds_global_constexpr_cast void (ptr addrspace(1)): local memory global used by non-kernel function
102102
define void @func_use_lds_global_constexpr_cast(ptr addrspace(1) %out) {
103-
; GFX8-SDAG-LABEL: func_use_lds_global_constexpr_cast:
104-
; GFX8-SDAG: ; %bb.0:
105-
; GFX8-SDAG-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
106-
; GFX8-SDAG-NEXT: s_mov_b64 s[4:5], 0xc8
107-
; GFX8-SDAG-NEXT: s_load_dwordx2 s[0:1], s[4:5], 0x0
108-
; GFX8-SDAG-NEXT: s_waitcnt lgkmcnt(0)
109-
; GFX8-SDAG-NEXT: s_trap 2
110-
; GFX8-SDAG-NEXT: s_setpc_b64 s[30:31]
111-
;
112-
; GFX8-GISEL-LABEL: func_use_lds_global_constexpr_cast:
113-
; GFX8-GISEL: ; %bb.0:
114-
; GFX8-GISEL-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
115-
; GFX8-GISEL-NEXT: s_mov_b64 s[4:5], 0xc8
116-
; GFX8-GISEL-NEXT: s_load_dwordx2 s[0:1], s[4:5], 0x0
117-
; GFX8-GISEL-NEXT: s_waitcnt lgkmcnt(0)
118-
; GFX8-GISEL-NEXT: s_trap 2
119-
; GFX8-GISEL-NEXT: flat_store_dword v[0:1], v0
120-
; GFX8-GISEL-NEXT: s_waitcnt vmcnt(0)
121-
; GFX8-GISEL-NEXT: s_setpc_b64 s[30:31]
122-
;
123-
; GFX9-SDAG-LABEL: func_use_lds_global_constexpr_cast:
124-
; GFX9-SDAG: ; %bb.0:
125-
; GFX9-SDAG-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
126-
; GFX9-SDAG-NEXT: s_trap 2
127-
; GFX9-SDAG-NEXT: s_setpc_b64 s[30:31]
103+
; GFX8-LABEL: func_use_lds_global_constexpr_cast:
104+
; GFX8: ; %bb.0:
105+
; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
106+
; GFX8-NEXT: s_mov_b64 s[4:5], 0xc8
107+
; GFX8-NEXT: s_load_dwordx2 s[0:1], s[4:5], 0x0
108+
; GFX8-NEXT: s_waitcnt lgkmcnt(0)
109+
; GFX8-NEXT: s_trap 2
110+
; GFX8-NEXT: s_setpc_b64 s[30:31]
128111
;
129-
; GFX9-GISEL-LABEL: func_use_lds_global_constexpr_cast:
130-
; GFX9-GISEL: ; %bb.0:
131-
; GFX9-GISEL-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
132-
; GFX9-GISEL-NEXT: s_trap 2
133-
; GFX9-GISEL-NEXT: global_store_dword v[0:1], v0, off
134-
; GFX9-GISEL-NEXT: s_waitcnt vmcnt(0)
135-
; GFX9-GISEL-NEXT: s_setpc_b64 s[30:31]
112+
; GFX9-LABEL: func_use_lds_global_constexpr_cast:
113+
; GFX9: ; %bb.0:
114+
; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
115+
; GFX9-NEXT: s_trap 2
116+
; GFX9-NEXT: s_setpc_b64 s[30:31]
136117
;
137-
; SDAG-LABEL: func_use_lds_global_constexpr_cast:
138-
; SDAG: ; %bb.0:
139-
; SDAG-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
140-
; SDAG-NEXT: s_cbranch_execnz .LBB1_2
141-
; SDAG-NEXT: ; %bb.1:
142-
; SDAG-NEXT: s_setpc_b64 s[30:31]
143-
; SDAG-NEXT: .LBB1_2:
144-
; SDAG-NEXT: s_endpgm
145-
;
146-
; GISEL-LABEL: func_use_lds_global_constexpr_cast:
147-
; GISEL: ; %bb.0:
148-
; GISEL-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
149-
; GISEL-NEXT: s_cbranch_execnz .LBB1_2
150-
; GISEL-NEXT: ; %bb.1:
151-
; GISEL-NEXT: global_store_dword v[0:1], v0, off
152-
; GISEL-NEXT: s_waitcnt vmcnt(0)
153-
; GISEL-NEXT: s_setpc_b64 s[30:31]
154-
; GISEL-NEXT: .LBB1_2:
155-
; GISEL-NEXT: s_endpgm
118+
; CHECK-LABEL: func_use_lds_global_constexpr_cast:
119+
; CHECK: ; %bb.0:
120+
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
121+
; CHECK-NEXT: s_cbranch_execnz .LBB1_2
122+
; CHECK-NEXT: ; %bb.1:
123+
; CHECK-NEXT: s_setpc_b64 s[30:31]
124+
; CHECK-NEXT: .LBB1_2:
125+
; CHECK-NEXT: s_endpgm
156126
store i32 ptrtoint (ptr addrspace(3) @lds to i32), ptr addrspace(1) %out, align 4
157127
ret void
158128
}
@@ -611,7 +581,3 @@ ret:
611581
ret i32 %phi
612582
}
613583

614-
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
615-
; CHECK: {{.*}}
616-
; GFX8: {{.*}}
617-
; GFX9: {{.*}}

0 commit comments

Comments
 (0)