llvm-project/llvm/test/CodeGen/AMDGPU/amdgpu-simplify-demanded-bits-readfirstlane.ll
Lakreite a44c15874d
[AMDGPU][CodeGen] Implement SimplifyDemandedBitsForTargetNode for readfirstlane. (#190009)
Propagate demanded bits through readfirstlane intrinsic in
AMDGPUISelLowering with SimplifyDemandedBitsForTargetNode
implementation.

This allows upstream zero/sign extensions to be eliminated when only a
subset of bits is used after the intrinsic.

Partially addresses #128390.
2026-04-03 14:30:47 +02:00

61 lines
2.3 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 < %s | FileCheck -check-prefix=GCN %s
define void @readfirstlane_demanded_i8_zext_store(i8 %src, ptr addrspace(1) %ptr) {
; GCN-LABEL: readfirstlane_demanded_i8_zext_store:
; GCN: ; %bb.0:
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; GCN-NEXT: v_readfirstlane_b32 s4, v0
; GCN-NEXT: v_mov_b32_e32 v0, s4
; GCN-NEXT: global_store_byte v[1:2], v0, off
; GCN-NEXT: s_waitcnt vmcnt(0)
; GCN-NEXT: s_setpc_b64 s[30:31]
%zext = zext i8 %src to i32
%readfirstlane = call i32 @llvm.amdgcn.readfirstlane.i32(i32 %zext)
%trunc = trunc i32 %readfirstlane to i8
store i8 %trunc, ptr addrspace(1) %ptr
ret void
}
define void @readfirstlane_demanded_i8_sext_store(i8 %src, ptr addrspace(1) %ptr) {
; GCN-LABEL: readfirstlane_demanded_i8_sext_store:
; GCN: ; %bb.0:
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; GCN-NEXT: v_readfirstlane_b32 s4, v0
; GCN-NEXT: v_mov_b32_e32 v0, s4
; GCN-NEXT: global_store_byte v[1:2], v0, off
; GCN-NEXT: s_waitcnt vmcnt(0)
; GCN-NEXT: s_setpc_b64 s[30:31]
%sext = sext i8 %src to i32
%readfirstlane = call i32 @llvm.amdgcn.readfirstlane.i32(i32 %sext)
%trunc = trunc i32 %readfirstlane to i8
store i8 %trunc, ptr addrspace(1) %ptr
ret void
}
define i16 @readfirstlane_demanded_i16_zext(i16 %src) {
; GCN-LABEL: readfirstlane_demanded_i16_zext:
; GCN: ; %bb.0:
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; GCN-NEXT: v_readfirstlane_b32 s4, v0
; GCN-NEXT: v_mov_b32_e32 v0, s4
; GCN-NEXT: s_setpc_b64 s[30:31]
%zext = zext i16 %src to i32
%readfirstlane = call i32 @llvm.amdgcn.readfirstlane.i32(i32 %zext)
%trunc = trunc i32 %readfirstlane to i16
ret i16 %trunc
}
define i16 @readfirstlane_demanded_i16_sext(i16 %src) {
; GCN-LABEL: readfirstlane_demanded_i16_sext:
; GCN: ; %bb.0:
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; GCN-NEXT: v_readfirstlane_b32 s4, v0
; GCN-NEXT: v_mov_b32_e32 v0, s4
; GCN-NEXT: s_setpc_b64 s[30:31]
%sext = sext i16 %src to i32
%readfirstlane = call i32 @llvm.amdgcn.readfirstlane.i32(i32 %sext)
%trunc = trunc i32 %readfirstlane to i16
ret i16 %trunc
}