From 8ad7d9a779d52d70c08e86048534a363db1ff951 Mon Sep 17 00:00:00 2001 From: Yi-Chi Lee Date: Thu, 2 Oct 2025 17:31:10 -0500 Subject: [PATCH 1/2] [SelectionDAG] add ISD::BITCAST handling for isGuaranteedNotToBeUndefOrPoison --- .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 95f53fe0bfdba..deab1a919b952 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -5636,6 +5636,30 @@ bool SelectionDAG::isGuaranteedNotToBeUndefOrPoison(SDValue Op, }); } + case ISD::BITCAST: { + SDValue Src = Op.getOperand(0); + EVT SrcVT = Src.getValueType(); + EVT TgtVT = Op.getValueType(); + + // Case 1: Scalar -> Vector, or Scalar -> Scalar + if (!SrcVT.isVector()) { + APInt DemandedSrcElts(1, 1); + return isGuaranteedNotToBeUndefOrPoison(Src, DemandedSrcElts, PoisonOnly, + Depth + 1); + } + + // Case 2: Vector -> Scalar + if (SrcVT.isVector() && !TgtVT.isVector()) + return isGuaranteedNotToBeUndefOrPoison(Src, PoisonOnly, Depth + 1); + + // Case 3: Vector -> Vector + unsigned NumSrcElts = SrcVT.getVectorNumElements(); + APInt ScaledDemandedElts = APIntOps::ScaleBitMask(DemandedElts, NumSrcElts); + + return isGuaranteedNotToBeUndefOrPoison(Src, ScaledDemandedElts, PoisonOnly, + Depth + 1); + } + // TODO: Search for noundef attributes from library functions. // TODO: Pointers dereferenced by ISD::LOAD/STORE ops are noundef. From 2b946f2a448d390e37a25e3239825ed390996d69 Mon Sep 17 00:00:00 2001 From: Yi-Chi Lee Date: Fri, 3 Oct 2025 11:09:37 -0500 Subject: [PATCH 2/2] fix for scalable vector --- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index deab1a919b952..41304083e0033 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -5648,8 +5648,9 @@ bool SelectionDAG::isGuaranteedNotToBeUndefOrPoison(SDValue Op, Depth + 1); } - // Case 2: Vector -> Scalar - if (SrcVT.isVector() && !TgtVT.isVector()) + // Case 2: Vector -> Scalar, or Scalable Vector -> Scalable Vector + if ((SrcVT.isVector() && !TgtVT.isVector()) || + (SrcVT.isScalableVT() && TgtVT.isScalableVT())) return isGuaranteedNotToBeUndefOrPoison(Src, PoisonOnly, Depth + 1); // Case 3: Vector -> Vector