diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-01-03 22:42:33 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-01-03 22:42:33 +0000 |
commit | ec0a2fb7037aab3eca8eacdfe85692d3c140a40f (patch) | |
tree | 7d0831d213cec6f601a80cc89a52000ffb3078ee | |
parent | 31abb45803d272b3fd211253f571047256ab2f19 (diff) | |
download | bcm5719-llvm-ec0a2fb7037aab3eca8eacdfe85692d3c140a40f.tar.gz bcm5719-llvm-ec0a2fb7037aab3eca8eacdfe85692d3c140a40f.zip |
[DAGCombine] Handle out of range EXTRACT_VECTOR_ELT indices
Handle this in DAGCombiner::visitEXTRACT_VECTOR_ELT the same as we already do in SelectionDAG::getNode and use APInt instead of getZExtValue.
This should also fix oss-fuzz #4910
llvm-svn: 321767
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 | ||||
-rw-r--r-- | llvm/test/CodeGen/X86/extract-insert.ll | 18 |
3 files changed, 23 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 81bff4d7eef..2b44e4fa93c 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -14200,6 +14200,10 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR_ELT(SDNode *N) { SDValue EltNo = N->getOperand(1); ConstantSDNode *ConstEltNo = dyn_cast<ConstantSDNode>(EltNo); + // extract_vector_elt of out-of-bounds element -> UNDEF + if (ConstEltNo && ConstEltNo->getAPIntValue().uge(VT.getVectorNumElements())) + return DAG.getUNDEF(NVT); + // extract_vector_elt (build_vector x, y), 1 -> y if (ConstEltNo && InVec.getOpcode() == ISD::BUILD_VECTOR && diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 4c8b63d2f23..7e99863b1ee 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -4453,7 +4453,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT, return getUNDEF(VT); // EXTRACT_VECTOR_ELT of out-of-bounds element is an UNDEF - if (N2C && N2C->getZExtValue() >= N1.getValueType().getVectorNumElements()) + if (N2C && N2C->getAPIntValue().uge(N1.getValueType().getVectorNumElements())) return getUNDEF(VT); // EXTRACT_VECTOR_ELT of CONCAT_VECTORS is often formed while lowering is diff --git a/llvm/test/CodeGen/X86/extract-insert.ll b/llvm/test/CodeGen/X86/extract-insert.ll new file mode 100644 index 00000000000..823390e86d1 --- /dev/null +++ b/llvm/test/CodeGen/X86/extract-insert.ll @@ -0,0 +1,18 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+sse2 | FileCheck %s --check-prefix=CHECK --check-prefix=X86 +; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse2 | FileCheck %s --check-prefix=CHECK --check-prefix=X64 + +define i32 @extractelt_undef_insertelt(i32 %x, i32 %y) { +; X86-LABEL: extractelt_undef_insertelt: +; X86: # %bb.0: +; X86-NEXT: retl +; +; X64-LABEL: extractelt_undef_insertelt: +; X64: # %bb.0: +; X64-NEXT: retq + %b = insertelement <4 x i32> zeroinitializer, i32 %x, i64 3 + %c = icmp uge i32 %y, %y + %d = extractelement <4 x i32> %b, i1 %c + ret i32 %d +} + |