[llvm] [SelectionDAG] Return poison instead of undef for out-of-bounds EXTRACT_VECTOR_ELT (PR #192844)

Xinlong Chen via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 19 04:32:21 PDT 2026


https://github.com/Xinlong-Chen created https://github.com/llvm/llvm-project/pull/192844

Out-of-bounds EXTRACT_VECTOR_ELT on fixed-length vectors is undefined behavior. 

Return poison instead of undef to be consistent with LangRef semantics.

Prep work to help with https://github.com/llvm/llvm-project/pull/190307

>From 3214be2461647d125ad8d10ebc589b15587cd974 Mon Sep 17 00:00:00 2001
From: xinlongchen <xinlongchen at tencent.com>
Date: Sun, 19 Apr 2026 19:14:59 +0800
Subject: [PATCH] [SelectionDAG] Return poison instead of undef for
 out-of-bounds EXTRACT_VECTOR_ELT

---
 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 86245e4044925..6c8d7742a80e4 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -8379,12 +8379,12 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     if (N1.isUndef() || N2.isUndef())
       return getUNDEF(VT);
 
-    // EXTRACT_VECTOR_ELT of out-of-bounds element is an UNDEF for fixed length
+    // EXTRACT_VECTOR_ELT of out-of-bounds element is an POISON for fixed length
     // vectors. For scalable vectors we will provide appropriate support for
     // dealing with arbitrary indices.
     if (N2C && N1.getValueType().isFixedLengthVector() &&
         N2C->getAPIntValue().uge(N1.getValueType().getVectorNumElements()))
-      return getUNDEF(VT);
+      return getPOISON(VT);
 
     // EXTRACT_VECTOR_ELT of CONCAT_VECTORS is often formed while lowering is
     // expanding copies of large vectors from registers. This only works for



More information about the llvm-commits mailing list