[llvm] r321767 - [DAGCombine] Handle out of range EXTRACT_VECTOR_ELT indices

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 3 14:42:33 PST 2018


Author: rksimon
Date: Wed Jan  3 14:42:33 2018
New Revision: 321767

URL: http://llvm.org/viewvc/llvm-project?rev=321767&view=rev
Log:
[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

Added:
    llvm/trunk/test/CodeGen/X86/extract-insert.ll
Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=321767&r1=321766&r2=321767&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Wed Jan  3 14:42:33 2018
@@ -14200,6 +14200,10 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR
   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 &&

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=321767&r1=321766&r2=321767&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Wed Jan  3 14:42:33 2018
@@ -4453,7 +4453,7 @@ SDValue SelectionDAG::getNode(unsigned O
       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

Added: llvm/trunk/test/CodeGen/X86/extract-insert.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/extract-insert.ll?rev=321767&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/extract-insert.ll (added)
+++ llvm/trunk/test/CodeGen/X86/extract-insert.ll Wed Jan  3 14:42:33 2018
@@ -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
+}
+




More information about the llvm-commits mailing list