[PATCH] D131883: [DAG] Ensure more Legal BUILD_VECTOR elements types in shuffle->And combine
Dave Green via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 15 04:28:46 PDT 2022
dmgreen created this revision.
dmgreen added reviewers: RKSimon, efriedma, craig.topper, spatel.
Herald added subscribers: StephenFan, ecnelises, hiraditya.
Herald added a project: All.
dmgreen requested review of this revision.
Herald added a project: LLVM.
This is a followup to D131350 <https://reviews.llvm.org/D131350>, which caused another problem for i64 types being split into i32 on i32 targets. This patch tries to make sure that either Illegal types are OK, or that the element types of a buildvector are legal and bigger than or equal to the size of the original elements.
https://reviews.llvm.org/D131883
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/ARM/vector-store.ll
Index: llvm/test/CodeGen/ARM/vector-store.ll
===================================================================
--- llvm/test/CodeGen/ARM/vector-store.ll
+++ llvm/test/CodeGen/ARM/vector-store.ll
@@ -419,3 +419,20 @@
store <3 x i8> zeroinitializer, <3 x i8> *%p, align 4
ret void
}
+
+define void @v3i64shuffle(<3 x i64> *%p, <3 x i64> %a) {
+; CHECK-LABEL: v3i64shuffle:
+; CHECK: @ %bb.0:
+; CHECK-NEXT: vmov.i32 q8, #0x0
+; CHECK-NEXT: ldrd r12, r1, [sp, #8]
+; CHECK-NEXT: vmov d18, r2, r3
+; CHECK-NEXT: vorr d19, d16, d16
+; CHECK-NEXT: str r1, [r0, #20]
+; CHECK-NEXT: vst1.32 {d18, d19}, [r0]!
+; CHECK-NEXT: str.w r12, [r0]
+; CHECK-NEXT: bx lr
+ %b = shufflevector <3 x i64> %a, <3 x i64> zeroinitializer, <3 x i32> <i32 0, i32 3, i32 2>
+ store <3 x i64> %b, <3 x i64> *%p, align 4
+ ret void
+}
+
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -22846,25 +22846,31 @@
SDLoc DL(N);
EVT IntVT = VT.changeVectorElementTypeToInteger();
EVT IntSVT = VT.getVectorElementType().changeTypeToInteger();
- IntSVT = TLI.getTypeToTransformTo(*DAG.getContext(), IntSVT);
- SDValue ZeroElt = DAG.getConstant(0, DL, IntSVT);
- SDValue AllOnesElt = DAG.getAllOnesConstant(DL, IntSVT);
- SmallVector<SDValue, 16> AndMask(NumElts, DAG.getUNDEF(IntSVT));
- for (int I = 0; I != (int)NumElts; ++I)
- if (0 <= Mask[I])
- AndMask[I] = Mask[I] == I ? AllOnesElt : ZeroElt;
-
- // See if a clear mask is legal instead of going via
- // XformToShuffleWithZero which loses UNDEF mask elements.
- if (TLI.isVectorClearMaskLegal(ClearMask, IntVT))
- return DAG.getBitcast(
- VT, DAG.getVectorShuffle(IntVT, DL, DAG.getBitcast(IntVT, N0),
- DAG.getConstant(0, DL, IntVT), ClearMask));
-
- if (TLI.isOperationLegalOrCustom(ISD::AND, IntVT))
- return DAG.getBitcast(
- VT, DAG.getNode(ISD::AND, DL, IntVT, DAG.getBitcast(IntVT, N0),
- DAG.getBuildVector(IntVT, DL, AndMask)));
+ // Transform the type to a legal type so that the buildvector constant
+ // elements are not illegal. Make sure that the result is larger than the
+ // original type, incase the value is split into two (eg i64->i32).
+ if (!TLI.isTypeLegal(IntSVT) && LegalTypes)
+ IntSVT = TLI.getTypeToTransformTo(*DAG.getContext(), IntSVT);
+ if (IntSVT.getSizeInBits() >= IntVT.getScalarSizeInBits()) {
+ SDValue ZeroElt = DAG.getConstant(0, DL, IntSVT);
+ SDValue AllOnesElt = DAG.getAllOnesConstant(DL, IntSVT);
+ SmallVector<SDValue, 16> AndMask(NumElts, DAG.getUNDEF(IntSVT));
+ for (int I = 0; I != (int)NumElts; ++I)
+ if (0 <= Mask[I])
+ AndMask[I] = Mask[I] == I ? AllOnesElt : ZeroElt;
+
+ // See if a clear mask is legal instead of going via
+ // XformToShuffleWithZero which loses UNDEF mask elements.
+ if (TLI.isVectorClearMaskLegal(ClearMask, IntVT))
+ return DAG.getBitcast(
+ VT, DAG.getVectorShuffle(IntVT, DL, DAG.getBitcast(IntVT, N0),
+ DAG.getConstant(0, DL, IntVT), ClearMask));
+
+ if (TLI.isOperationLegalOrCustom(ISD::AND, IntVT))
+ return DAG.getBitcast(
+ VT, DAG.getNode(ISD::AND, DL, IntVT, DAG.getBitcast(IntVT, N0),
+ DAG.getBuildVector(IntVT, DL, AndMask)));
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131883.452627.patch
Type: text/x-patch
Size: 3677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220815/0feec8ef/attachment.bin>
More information about the llvm-commits
mailing list