[PATCH] D45339: [NVPTX] Fixed vectorized LDG for f16.
Artem Belevich via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 5 15:41:58 PDT 2018
tra created this revision.
tra added reviewers: jlebar, bixia.
Herald added subscribers: hiraditya, sanjoy, jholewinski.
v2f16 is a special case in NVPTX. v4f16 may be loaded as a pair of v2f16
and that was not previously handled correctly by tryLDGLDU()
https://reviews.llvm.org/D45339
Files:
llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
llvm/test/CodeGen/NVPTX/ldg-invariant.ll
Index: llvm/test/CodeGen/NVPTX/ldg-invariant.ll
===================================================================
--- llvm/test/CodeGen/NVPTX/ldg-invariant.ll
+++ llvm/test/CodeGen/NVPTX/ldg-invariant.ll
@@ -10,6 +10,50 @@
ret i32 %a
}
+; CHECK-LABEL: @ld_global_v2f16
+define half @ld_global_v2f16(<2 x half> addrspace(1)* %ptr) {
+; load of v2f16 is weird as we consider it to be a legal type and don't split it
+; further into individual elements with a side effect of loading and storing it
+; as a 32-bit scalar.
+; CHECK: ld.global.nc.b32
+ %a = load <2 x half>, <2 x half> addrspace(1)* %ptr, !invariant.load !0
+ %v1 = extractelement <2 x half> %a, i32 0
+ %v2 = extractelement <2 x half> %a, i32 1
+ %sum = fadd half %v1, %v2
+ ret half %sum
+}
+
+; CHECK-LABEL: @ld_global_v4f16
+define half @ld_global_v4f16(<4 x half> addrspace(1)* %ptr) {
+; All other variants of f16 vectors get normal vectorized loads.stores.
+; CHECK: ld.global.nc.v4.b16
+ %a = load <4 x half>, <4 x half> addrspace(1)* %ptr, !invariant.load !0
+ %v1 = extractelement <4 x half> %a, i32 0
+ %v2 = extractelement <4 x half> %a, i32 1
+ %v3 = extractelement <4 x half> %a, i32 2
+ %v4 = extractelement <4 x half> %a, i32 3
+ %sum1 = fadd half %v1, %v2
+ %sum2 = fadd half %v3, %v4
+ %sum = fadd half %sum1, %sum2
+ ret half %sum
+}
+
+; CHECK-LABEL: @ld_global_v8f16
+define half @ld_global_v8f16(<8 x half> addrspace(1)* %ptr) {
+; But v8f16 is again loaded as v4i32, because PTX has no v8 variants of loads/stores.
+; CHECK: ld.global.nc.v4.b32
+ %a = load <8 x half>, <8 x half> addrspace(1)* %ptr, !invariant.load !0
+ %v1 = extractelement <8 x half> %a, i32 0
+ %v2 = extractelement <8 x half> %a, i32 2
+ %v3 = extractelement <8 x half> %a, i32 4
+ %v8 = extractelement <8 x half> %a, i32 6
+ %sum1 = fadd half %v1, %v2
+ %sum2 = fadd half %v3, %v8
+ %sum = fadd half %sum1, %sum2
+ ret half %sum
+}
+
+
; CHECK-LABEL: @ld_global_v2i32
define i32 @ld_global_v2i32(<2 x i32> addrspace(1)* %ptr) {
; CHECK: ld.global.nc.v2.{{[a-z]}}32
Index: llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
+++ llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
@@ -1239,6 +1239,12 @@
if (EltVT.isVector()) {
NumElts = EltVT.getVectorNumElements();
EltVT = EltVT.getVectorElementType();
+ // vectors of f16 are loaded/stored as multiples of v2f16 elements.
+ if (EltVT == MVT::f16 && N->getValueType(0) == MVT::v2f16 &&
+ NumElts % 2 == 0) {
+ EltVT = MVT::v2f16;
+ NumElts /= 2;
+ }
}
// Build the "promoted" result VTList for the load. If we are really loading
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45339.141232.patch
Type: text/x-patch
Size: 2718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180405/415d2ae2/attachment.bin>
More information about the llvm-commits
mailing list