summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Pilgrim <llvm-dev@redking.me.uk>2019-02-27 11:17:25 +0000
committerSimon Pilgrim <llvm-dev@redking.me.uk>2019-02-27 11:17:25 +0000
commit71bb6850cf318323270efbafa3d019d4d74450aa (patch)
tree6a33115979c2a4c7363f48b9232c1814c08f285d
parent5b27402bee4f95c045b9f5cad562ab4b12264d0b (diff)
downloadbcm5719-llvm-71bb6850cf318323270efbafa3d019d4d74450aa.tar.gz
bcm5719-llvm-71bb6850cf318323270efbafa3d019d4d74450aa.zip
[X86][AVX] Only combine loads to broadcasts for legal types
Thanks to @echristo for spotting this. llvm-svn: 354961
-rw-r--r--llvm/lib/Target/X86/X86ISelLowering.cpp20
-rw-r--r--llvm/test/CodeGen/X86/avx-vbroadcast.ll26
-rw-r--r--llvm/test/CodeGen/X86/avx2-vbroadcast.ll42
3 files changed, 79 insertions, 9 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index cb272335e2b..e5b2f05473e 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -7448,15 +7448,17 @@ static SDValue EltsFromConsecutiveLoads(EVT VT, ArrayRef<SDValue> Elts,
if (RepeatSize > ScalarSize)
RepeatVT = EVT::getVectorVT(*DAG.getContext(), RepeatVT,
RepeatSize / ScalarSize);
- if (SDValue RepeatLoad = EltsFromConsecutiveLoads(
- RepeatVT, RepeatedLoads, DL, DAG, Subtarget, isAfterLegalize)) {
- EVT BroadcastVT =
- EVT::getVectorVT(*DAG.getContext(), RepeatVT.getScalarType(),
- VT.getSizeInBits() / ScalarSize);
- unsigned Opcode = RepeatSize > ScalarSize ? X86ISD::SUBV_BROADCAST
- : X86ISD::VBROADCAST;
- SDValue Broadcast = DAG.getNode(Opcode, DL, BroadcastVT, RepeatLoad);
- return DAG.getBitcast(VT, Broadcast);
+ EVT BroadcastVT =
+ EVT::getVectorVT(*DAG.getContext(), RepeatVT.getScalarType(),
+ VT.getSizeInBits() / ScalarSize);
+ if (TLI.isTypeLegal(BroadcastVT)) {
+ if (SDValue RepeatLoad = EltsFromConsecutiveLoads(
+ RepeatVT, RepeatedLoads, DL, DAG, Subtarget, isAfterLegalize)) {
+ unsigned Opcode = RepeatSize > ScalarSize ? X86ISD::SUBV_BROADCAST
+ : X86ISD::VBROADCAST;
+ SDValue Broadcast = DAG.getNode(Opcode, DL, BroadcastVT, RepeatLoad);
+ return DAG.getBitcast(VT, Broadcast);
+ }
}
}
}
diff --git a/llvm/test/CodeGen/X86/avx-vbroadcast.ll b/llvm/test/CodeGen/X86/avx-vbroadcast.ll
index 84537cb15df..3426d6504c0 100644
--- a/llvm/test/CodeGen/X86/avx-vbroadcast.ll
+++ b/llvm/test/CodeGen/X86/avx-vbroadcast.ll
@@ -856,6 +856,32 @@ define <4 x double> @broadcast_shuffle1032(double* %p) {
ret <4 x double> %4
}
+define void @broadcast_v16i32(i32* %a, <16 x i32>* %b) {
+; X32-LABEL: broadcast_v16i32:
+; X32: ## %bb.0:
+; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; X32-NEXT: vbroadcastss (%ecx), %ymm0
+; X32-NEXT: vmovups %ymm0, 32(%eax)
+; X32-NEXT: vmovups %ymm0, (%eax)
+; X32-NEXT: vzeroupper
+; X32-NEXT: retl
+;
+; X64-LABEL: broadcast_v16i32:
+; X64: ## %bb.0:
+; X64-NEXT: vbroadcastss (%rdi), %ymm0
+; X64-NEXT: vmovups %ymm0, 32(%rsi)
+; X64-NEXT: vmovups %ymm0, (%rsi)
+; X64-NEXT: vzeroupper
+; X64-NEXT: retq
+ %1 = load i32, i32* %a, align 4
+ %2 = insertelement <8 x i32> undef, i32 %1, i32 0
+ %3 = shufflevector <8 x i32> %2, <8 x i32> undef, <8 x i32> zeroinitializer
+ %4 = shufflevector <8 x i32> undef, <8 x i32> %3, <16 x i32> <i32 0, i32 8, i32 1, i32 9, i32 2, i32 10, i32 3, i32 11, i32 4, i32 12, i32 5, i32 13, i32 6, i32 14, i32 7, i32 15>
+ store <16 x i32> %4, <16 x i32>* %b, align 4
+ ret void
+}
+
;
; When VBROADCAST replaces an existing load, ensure it still respects lifetime dependencies.
;
diff --git a/llvm/test/CodeGen/X86/avx2-vbroadcast.ll b/llvm/test/CodeGen/X86/avx2-vbroadcast.ll
index e10dbdaeb4f..e7dd881960b 100644
--- a/llvm/test/CodeGen/X86/avx2-vbroadcast.ll
+++ b/llvm/test/CodeGen/X86/avx2-vbroadcast.ll
@@ -1037,6 +1037,48 @@ define <4 x double> @splat_concat4(double %d) {
ret <4 x double> %5
}
+define void @broadcast_v16i32(i32* %a, <16 x i32>* %b) {
+; X32-AVX2-LABEL: broadcast_v16i32:
+; X32-AVX2: ## %bb.0:
+; X32-AVX2-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X32-AVX2-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; X32-AVX2-NEXT: vbroadcastss (%ecx), %ymm0
+; X32-AVX2-NEXT: vmovups %ymm0, 32(%eax)
+; X32-AVX2-NEXT: vmovups %ymm0, (%eax)
+; X32-AVX2-NEXT: vzeroupper
+; X32-AVX2-NEXT: retl
+;
+; X64-AVX2-LABEL: broadcast_v16i32:
+; X64-AVX2: ## %bb.0:
+; X64-AVX2-NEXT: vbroadcastss (%rdi), %ymm0
+; X64-AVX2-NEXT: vmovups %ymm0, 32(%rsi)
+; X64-AVX2-NEXT: vmovups %ymm0, (%rsi)
+; X64-AVX2-NEXT: vzeroupper
+; X64-AVX2-NEXT: retq
+;
+; X32-AVX512VL-LABEL: broadcast_v16i32:
+; X32-AVX512VL: ## %bb.0:
+; X32-AVX512VL-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X32-AVX512VL-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; X32-AVX512VL-NEXT: vbroadcastss (%ecx), %zmm0
+; X32-AVX512VL-NEXT: vmovups %zmm0, (%eax)
+; X32-AVX512VL-NEXT: vzeroupper
+; X32-AVX512VL-NEXT: retl
+;
+; X64-AVX512VL-LABEL: broadcast_v16i32:
+; X64-AVX512VL: ## %bb.0:
+; X64-AVX512VL-NEXT: vbroadcastss (%rdi), %zmm0
+; X64-AVX512VL-NEXT: vmovups %zmm0, (%rsi)
+; X64-AVX512VL-NEXT: vzeroupper
+; X64-AVX512VL-NEXT: retq
+ %1 = load i32, i32* %a, align 4
+ %2 = insertelement <8 x i32> undef, i32 %1, i32 0
+ %3 = shufflevector <8 x i32> %2, <8 x i32> undef, <8 x i32> zeroinitializer
+ %4 = shufflevector <8 x i32> undef, <8 x i32> %3, <16 x i32> <i32 0, i32 8, i32 1, i32 9, i32 2, i32 10, i32 3, i32 11, i32 4, i32 12, i32 5, i32 13, i32 6, i32 14, i32 7, i32 15>
+ store <16 x i32> %4, <16 x i32>* %b, align 4
+ ret void
+}
+
; Test cases for <rdar://problem/16074331>.
; Instruction selection for broacast instruction fails if
; the load cannot be folded into the broadcast.
OpenPOWER on IntegriCloud