2018-08-31 13:49:54 +08:00
|
|
|
; RUN: llc -march=amdgcn -mtriple=amdgcn-- -mcpu=verde -mattr=-promote-alloca -verify-machineinstrs < %s | FileCheck -check-prefix=SI-ALLOCA -check-prefix=SI -check-prefix=FUNC %s
|
|
|
|
; RUN: llc -march=amdgcn -mtriple=amdgcn-- -mcpu=verde -mattr=+promote-alloca -verify-machineinstrs < %s | FileCheck -check-prefix=SI-PROMOTE -check-prefix=SI -check-prefix=FUNC %s
|
|
|
|
; RUN: llc -march=amdgcn -mtriple=amdgcn-- -mcpu=tonga -mattr=-promote-alloca -verify-machineinstrs < %s | FileCheck -check-prefix=SI-ALLOCA -check-prefix=SI -check-prefix=FUNC %s
|
|
|
|
; RUN: llc -march=amdgcn -mtriple=amdgcn-- -mcpu=tonga -mattr=+promote-alloca -verify-machineinstrs < %s | FileCheck -check-prefix=SI-PROMOTE -check-prefix=SI -check-prefix=FUNC %s
|
|
|
|
; RUN: llc -march=r600 -mtriple=r600-- -mcpu=redwood < %s | FileCheck --check-prefix=EG -check-prefix=FUNC %s
|
|
|
|
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-promote-alloca -sroa -instcombine < %s | FileCheck -check-prefix=OPT %s
|
2017-11-10 09:53:24 +08:00
|
|
|
target datalayout = "A5"
|
2016-07-19 02:34:53 +08:00
|
|
|
|
|
|
|
; OPT-LABEL: @vector_read(
|
|
|
|
; OPT: %0 = extractelement <4 x i32> <i32 0, i32 1, i32 2, i32 3>, i32 %index
|
|
|
|
; OPT: store i32 %0, i32 addrspace(1)* %out, align 4
|
2014-06-18 00:53:14 +08:00
|
|
|
|
2014-10-02 01:15:17 +08:00
|
|
|
; FUNC-LABEL: {{^}}vector_read:
|
2014-06-18 00:53:14 +08:00
|
|
|
; EG: MOV
|
|
|
|
; EG: MOV
|
|
|
|
; EG: MOV
|
|
|
|
; EG: MOV
|
|
|
|
; EG: MOVA_INT
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @vector_read(i32 addrspace(1)* %out, i32 %index) {
|
2014-06-18 00:53:14 +08:00
|
|
|
entry:
|
2017-11-10 09:53:24 +08:00
|
|
|
%tmp = alloca [4 x i32], addrspace(5)
|
|
|
|
%x = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 0
|
|
|
|
%y = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 1
|
|
|
|
%z = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 2
|
|
|
|
%w = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 3
|
|
|
|
store i32 0, i32 addrspace(5)* %x
|
|
|
|
store i32 1, i32 addrspace(5)* %y
|
|
|
|
store i32 2, i32 addrspace(5)* %z
|
|
|
|
store i32 3, i32 addrspace(5)* %w
|
|
|
|
%tmp1 = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 %index
|
|
|
|
%tmp2 = load i32, i32 addrspace(5)* %tmp1
|
2016-07-19 02:34:53 +08:00
|
|
|
store i32 %tmp2, i32 addrspace(1)* %out
|
2014-06-18 00:53:14 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-07-19 02:34:53 +08:00
|
|
|
; OPT-LABEL: @vector_write(
|
|
|
|
; OPT: %0 = insertelement <4 x i32> zeroinitializer, i32 1, i32 %w_index
|
|
|
|
; OPT: %1 = extractelement <4 x i32> %0, i32 %r_index
|
|
|
|
; OPT: store i32 %1, i32 addrspace(1)* %out, align 4
|
|
|
|
|
2014-10-02 01:15:17 +08:00
|
|
|
; FUNC-LABEL: {{^}}vector_write:
|
2014-06-18 00:53:14 +08:00
|
|
|
; EG: MOV
|
|
|
|
; EG: MOV
|
|
|
|
; EG: MOV
|
|
|
|
; EG: MOV
|
|
|
|
; EG: MOVA_INT
|
|
|
|
; EG: MOVA_INT
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @vector_write(i32 addrspace(1)* %out, i32 %w_index, i32 %r_index) {
|
2014-06-18 00:53:14 +08:00
|
|
|
entry:
|
2017-11-10 09:53:24 +08:00
|
|
|
%tmp = alloca [4 x i32], addrspace(5)
|
|
|
|
%x = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 0
|
|
|
|
%y = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 1
|
|
|
|
%z = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 2
|
|
|
|
%w = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 3
|
|
|
|
store i32 0, i32 addrspace(5)* %x
|
|
|
|
store i32 0, i32 addrspace(5)* %y
|
|
|
|
store i32 0, i32 addrspace(5)* %z
|
|
|
|
store i32 0, i32 addrspace(5)* %w
|
|
|
|
%tmp1 = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 %w_index
|
|
|
|
store i32 1, i32 addrspace(5)* %tmp1
|
|
|
|
%tmp2 = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 %r_index
|
|
|
|
%tmp3 = load i32, i32 addrspace(5)* %tmp2
|
2016-07-19 02:34:53 +08:00
|
|
|
store i32 %tmp3, i32 addrspace(1)* %out
|
2014-06-18 00:53:14 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; This test should be optimize to:
|
|
|
|
; store i32 0, i32 addrspace(1)* %out
|
2016-07-19 02:34:53 +08:00
|
|
|
|
|
|
|
; OPT-LABEL: @bitcast_gep(
|
|
|
|
; OPT-LABEL: store i32 0, i32 addrspace(1)* %out, align 4
|
|
|
|
|
2014-10-02 01:15:17 +08:00
|
|
|
; FUNC-LABEL: {{^}}bitcast_gep:
|
2014-07-13 10:46:17 +08:00
|
|
|
; EG: STORE_RAW
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @bitcast_gep(i32 addrspace(1)* %out, i32 %w_index, i32 %r_index) {
|
2014-06-18 00:53:14 +08:00
|
|
|
entry:
|
2017-11-10 09:53:24 +08:00
|
|
|
%tmp = alloca [4 x i32], addrspace(5)
|
|
|
|
%x = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 0
|
|
|
|
%y = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 1
|
|
|
|
%z = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 2
|
|
|
|
%w = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 3
|
|
|
|
store i32 0, i32 addrspace(5)* %x
|
|
|
|
store i32 0, i32 addrspace(5)* %y
|
|
|
|
store i32 0, i32 addrspace(5)* %z
|
|
|
|
store i32 0, i32 addrspace(5)* %w
|
|
|
|
%tmp1 = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 1
|
|
|
|
%tmp2 = bitcast i32 addrspace(5)* %tmp1 to [4 x i32] addrspace(5)*
|
|
|
|
%tmp3 = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp2, i32 0, i32 0
|
|
|
|
%tmp4 = load i32, i32 addrspace(5)* %tmp3
|
2016-07-19 02:34:53 +08:00
|
|
|
store i32 %tmp4, i32 addrspace(1)* %out
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; OPT-LABEL: @vector_read_bitcast_gep(
|
|
|
|
; OPT: %0 = extractelement <4 x i32> <i32 1065353216, i32 1, i32 2, i32 3>, i32 %index
|
|
|
|
; OPT: store i32 %0, i32 addrspace(1)* %out, align 4
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @vector_read_bitcast_gep(i32 addrspace(1)* %out, i32 %index) {
|
2016-07-19 02:34:53 +08:00
|
|
|
entry:
|
2017-11-10 09:53:24 +08:00
|
|
|
%tmp = alloca [4 x i32], addrspace(5)
|
|
|
|
%x = getelementptr inbounds [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 0
|
|
|
|
%y = getelementptr inbounds [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 1
|
|
|
|
%z = getelementptr inbounds [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 2
|
|
|
|
%w = getelementptr inbounds [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 3
|
|
|
|
%bc = bitcast i32 addrspace(5)* %x to float addrspace(5)*
|
|
|
|
store float 1.0, float addrspace(5)* %bc
|
|
|
|
store i32 1, i32 addrspace(5)* %y
|
|
|
|
store i32 2, i32 addrspace(5)* %z
|
|
|
|
store i32 3, i32 addrspace(5)* %w
|
|
|
|
%tmp1 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 %index
|
|
|
|
%tmp2 = load i32, i32 addrspace(5)* %tmp1
|
2016-07-19 02:34:53 +08:00
|
|
|
store i32 %tmp2, i32 addrspace(1)* %out
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; FIXME: Should be able to promote this. Instcombine should fold the
|
|
|
|
; cast in the hasOneUse case so it might not matter in practice
|
|
|
|
|
|
|
|
; OPT-LABEL: @vector_read_bitcast_alloca(
|
|
|
|
; OPT: alloca [4 x float]
|
|
|
|
; OPT: store float
|
|
|
|
; OPT: store float
|
|
|
|
; OPT: store float
|
|
|
|
; OPT: store float
|
|
|
|
; OPT: load float
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @vector_read_bitcast_alloca(float addrspace(1)* %out, i32 %index) {
|
2016-07-19 02:34:53 +08:00
|
|
|
entry:
|
2017-11-10 09:53:24 +08:00
|
|
|
%tmp = alloca [4 x i32], addrspace(5)
|
|
|
|
%tmp.bc = bitcast [4 x i32] addrspace(5)* %tmp to [4 x float] addrspace(5)*
|
|
|
|
%x = getelementptr inbounds [4 x float], [4 x float] addrspace(5)* %tmp.bc, i32 0, i32 0
|
|
|
|
%y = getelementptr inbounds [4 x float], [4 x float] addrspace(5)* %tmp.bc, i32 0, i32 1
|
|
|
|
%z = getelementptr inbounds [4 x float], [4 x float] addrspace(5)* %tmp.bc, i32 0, i32 2
|
|
|
|
%w = getelementptr inbounds [4 x float], [4 x float] addrspace(5)* %tmp.bc, i32 0, i32 3
|
|
|
|
store float 0.0, float addrspace(5)* %x
|
|
|
|
store float 1.0, float addrspace(5)* %y
|
|
|
|
store float 2.0, float addrspace(5)* %z
|
|
|
|
store float 4.0, float addrspace(5)* %w
|
|
|
|
%tmp1 = getelementptr inbounds [4 x float], [4 x float] addrspace(5)* %tmp.bc, i32 0, i32 %index
|
|
|
|
%tmp2 = load float, float addrspace(5)* %tmp1
|
2016-07-19 02:34:53 +08:00
|
|
|
store float %tmp2, float addrspace(1)* %out
|
2014-06-18 00:53:14 +08:00
|
|
|
ret void
|
|
|
|
}
|
2017-05-24 04:25:41 +08:00
|
|
|
|
|
|
|
; The pointer arguments in local address space should not affect promotion to vector.
|
|
|
|
|
|
|
|
; OPT-LABEL: @vector_read_with_local_arg(
|
|
|
|
; OPT: %0 = extractelement <4 x i32> <i32 0, i32 1, i32 2, i32 3>, i32 %index
|
|
|
|
; OPT: store i32 %0, i32 addrspace(1)* %out, align 4
|
|
|
|
define amdgpu_kernel void @vector_read_with_local_arg(i32 addrspace(3)* %stopper, i32 addrspace(1)* %out, i32 %index) {
|
|
|
|
entry:
|
2017-11-10 09:53:24 +08:00
|
|
|
%tmp = alloca [4 x i32], addrspace(5)
|
|
|
|
%x = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 0
|
|
|
|
%y = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 1
|
|
|
|
%z = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 2
|
|
|
|
%w = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 3
|
|
|
|
store i32 0, i32 addrspace(5)* %x
|
|
|
|
store i32 1, i32 addrspace(5)* %y
|
|
|
|
store i32 2, i32 addrspace(5)* %z
|
|
|
|
store i32 3, i32 addrspace(5)* %w
|
|
|
|
%tmp1 = getelementptr [4 x i32], [4 x i32] addrspace(5)* %tmp, i32 0, i32 %index
|
|
|
|
%tmp2 = load i32, i32 addrspace(5)* %tmp1
|
2017-05-24 04:25:41 +08:00
|
|
|
store i32 %tmp2, i32 addrspace(1)* %out
|
|
|
|
ret void
|
|
|
|
}
|