[PATCH] D40165: DAG: Legalize truncstores to illegal int types
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 16 22:08:37 PST 2017
arsenm created this revision.
Herald added subscribers: nhaehnle, wdng.
Truncate to a legal int type, and produce a new
truncstore from a narrower type.
https://reviews.llvm.org/D40165
Files:
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
test/CodeGen/AMDGPU/store-weird-sizes.ll
Index: test/CodeGen/AMDGPU/store-weird-sizes.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AMDGPU/store-weird-sizes.ll
@@ -0,0 +1,56 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=hawaii -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,CIVI %s
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=fiji -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,CIVI %s
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9 %s
+
+; GCN-LABEL: {{^}}local_store_i56:
+; GCN-DAG: ds_write_b8 v0, v{{[0-9]+}} offset:6
+; GCN-DAG: ds_write_b16 v0, v{{[0-9]+}} offset:4
+; GCN-DAG: ds_write_b32 v0, v{{[0-9]+$}}
+define void @local_store_i56(i56 addrspace(3)* %ptr, i56 %arg) #0 {
+ store i56 %arg, i56 addrspace(3)* %ptr, align 8
+ ret void
+}
+
+; GCN-LABEL: {{^}}local_store_i55:
+; GCN-DAG: ds_write_b8 v0, v{{[0-9]+}} offset:6
+; GCN-DAG: ds_write_b16 v0, v{{[0-9]+}} offset:4
+; GCN-DAG: ds_write_b32 v0, v{{[0-9]+$}}
+define amdgpu_kernel void @local_store_i55(i55 addrspace(3)* %ptr, i55 %arg) #0 {
+ store i55 %arg, i55 addrspace(3)* %ptr, align 8
+ ret void
+}
+
+; GCN-LABEL: {{^}}local_store_i48:
+; GCN-DAG: ds_write_b16 v0, v{{[0-9]+}} offset:4
+; GCN-DAG: ds_write_b32 v0, v{{[0-9]+$}}
+define amdgpu_kernel void @local_store_i48(i48 addrspace(3)* %ptr, i48 %arg) #0 {
+ store i48 %arg, i48 addrspace(3)* %ptr, align 8
+ ret void
+}
+
+; GCN-LABEL: {{^}}local_store_i65:
+; GCN-DAG: ds_write_b8 v{{[0-9]+}}, v0 offset:8
+; GCN-DAG: ds_write_b64
+define amdgpu_kernel void @local_store_i65(i65 addrspace(3)* %ptr, i65 %arg) #0 {
+ store i65 %arg, i65 addrspace(3)* %ptr, align 8
+ ret void
+}
+
+; GCN-LABEL: {{^}}local_store_i13:
+; GCN: v_and_b32_e32 [[TRUNC:v[0-9]+]], 0x1fff, v1
+; GCN: ds_write_b16 v0, [[TRUNC]]
+define void @local_store_i13(i13 addrspace(3)* %ptr, i13 %arg) #0 {
+ store i13 %arg, i13 addrspace(3)* %ptr, align 8
+ ret void
+}
+
+; GCN-LABEL: {{^}}local_store_i17:
+; GCN: ds_write_b16 v0
+; CIVI: ds_write_b8 v0, v{{[0-9]+}} offset:2
+; GFX9: ds_write_b8_d16_hi v0, v{{[0-9]+}} offset:2
+define void @local_store_i17(i17 addrspace(3)* %ptr, i17 %arg) #0 {
+ store i17 %arg, i17 addrspace(3)* %ptr, align 8
+ ret void
+}
+
+attributes #0 = { nounwind }
Index: lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -624,13 +624,24 @@
assert(!StVT.isVector() &&
"Vector Stores are handled in LegalizeVectorOps");
+ SDValue Result;
+
// TRUNCSTORE:i16 i32 -> STORE i16
- assert(TLI.isTypeLegal(StVT) &&
- "Do not know how to expand this store!");
- Value = DAG.getNode(ISD::TRUNCATE, dl, StVT, Value);
- SDValue Result =
- DAG.getStore(Chain, dl, Value, Ptr, ST->getPointerInfo(),
- Alignment, MMOFlags, AAInfo);
+ if (TLI.isTypeLegal(StVT)) {
+ Value = DAG.getNode(ISD::TRUNCATE, dl, StVT, Value);
+ Result = DAG.getStore(Chain, dl, Value, Ptr, ST->getPointerInfo(),
+ Alignment, MMOFlags, AAInfo);
+ ReplaceNode(SDValue(Node, 0), Result);
+ } else {
+ // The in-memory type isn't legal. Truncate to the type it would promote
+ // to, and then do a truncstore.
+ Value = DAG.getNode(ISD::TRUNCATE, dl,
+ TLI.getTypeToTransformTo(*DAG.getContext(), StVT),
+ Value);
+ Result = DAG.getTruncStore(Chain, dl, Value, Ptr, ST->getPointerInfo(),
+ StVT, Alignment, MMOFlags, AAInfo);
+ }
+
ReplaceNode(SDValue(Node, 0), Result);
break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40165.123291.patch
Type: text/x-patch
Size: 3888 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171117/ec63365b/attachment.bin>
More information about the llvm-commits
mailing list