[llvm] 5d03bee - [DAG] canCreateUndefOrPoison - out of range vector insert/extract element indices only generate poison (#196720)

via llvm-commits llvm-commits at lists.llvm.org
Sat May 9 15:23:46 PDT 2026


Author: Simon Pilgrim
Date: 2026-05-09T22:23:41Z
New Revision: 5d03beef627a0d733c83c562d9a09e7201d9e001

URL: https://github.com/llvm/llvm-project/commit/5d03beef627a0d733c83c562d9a09e7201d9e001
DIFF: https://github.com/llvm/llvm-project/commit/5d03beef627a0d733c83c562d9a09e7201d9e001.diff

LOG: [DAG] canCreateUndefOrPoison - out of range vector insert/extract element indices only generate poison (#196720)

Matches ValueTracking / GISel implementations - although testing options are limited until DAG has actual uses of UndefPoisonKind::UndefOnly

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 0b7d8b7946f99..a221df567a10f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5993,10 +5993,13 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
   case ISD::INSERT_VECTOR_ELT:
   case ISD::EXTRACT_VECTOR_ELT: {
     // Ensure that the element index is in bounds.
-    EVT VecVT = Op.getOperand(0).getValueType();
-    SDValue Idx = Op.getOperand(Opcode == ISD::INSERT_VECTOR_ELT ? 2 : 1);
-    KnownBits KnownIdx = computeKnownBits(Idx, Depth + 1);
-    return KnownIdx.getMaxValue().uge(VecVT.getVectorMinNumElements());
+    if (includesPoison(Kind)) {
+      EVT VecVT = Op.getOperand(0).getValueType();
+      SDValue Idx = Op.getOperand(Opcode == ISD::INSERT_VECTOR_ELT ? 2 : 1);
+      KnownBits KnownIdx = computeKnownBits(Idx, Depth + 1);
+      return KnownIdx.getMaxValue().uge(VecVT.getVectorMinNumElements());
+    }
+    return false;
   }
 
   case ISD::VECTOR_SHUFFLE: {


        


More information about the llvm-commits mailing list