[PATCH] [DAGCombiner] Fold (vextract v, (sext (trunc i))) -> (vextract v, i)
Michael Spencer
bigcheesegs at gmail.com
Thu Apr 24 15:43:45 PDT 2014
Hi grosbach, nadav,
EXTRACT_VECTOR_ELT has undefined behavior for element indices greater than
the input vector width.
http://reviews.llvm.org/D3494
Files:
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
test/CodeGen/X86/vec_splat.ll
Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -9691,6 +9691,16 @@
SDValue EltNo = N->getOperand(1);
bool ConstEltNo = isa<ConstantSDNode>(EltNo);
+ // (vextract v, (sext (trunc i))) -> (vextract v, i)
+ if (EltNo.getOpcode() == ISD::SIGN_EXTEND &&
+ EltNo.getOperand(0).getOpcode() == ISD::TRUNCATE) {
+ SDValue Trunc = EltNo.getOperand(0);
+ if (Trunc.getValueType().getSizeInBits() >=
+ Log2_64_Ceil(VT.getVectorNumElements()))
+ return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(N), N->getValueType(0),
+ InVec, Trunc.getOperand(0));
+ }
+
// Transform: (EXTRACT_VECTOR_ELT( VECTOR_SHUFFLE )) -> EXTRACT_VECTOR_ELT.
// We only perform this optimization before the op legalization phase because
// we may introduce new vector instructions which are not backed by TD
Index: test/CodeGen/X86/vec_splat.ll
===================================================================
--- test/CodeGen/X86/vec_splat.ll
+++ test/CodeGen/X86/vec_splat.ll
@@ -48,5 +48,6 @@
; AVX-LABEL: load_extract_splat
; AVX-NOT: rsp
+; AVX-NOT: mov
; AVX: vbroadcastss
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3494.8820.patch
Type: text/x-patch
Size: 1282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140424/1d6c392d/attachment.bin>
More information about the llvm-commits
mailing list