[llvm-branch-commits] [llvm] [DAG] isGuaranteedNotToBeUndefOrPoison - add ISD::CONCAT_VECTORS handling (PR #200932)
Krzysztof Drewniak via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jun 4 12:54:33 PDT 2026
https://github.com/krzysz00 updated https://github.com/llvm/llvm-project/pull/200932
>From f8612664467d4250eb67c3e25ab8a3aef0c92ea5 Mon Sep 17 00:00:00 2001
From: Krzysztof Drewniak <Krzysztof.Drewniak at amd.com>
Date: Fri, 29 May 2026 22:08:20 +0000
Subject: [PATCH 1/2] [SelectionDAG] Track demanded concat elements in noundef
checks
Teach isGuaranteedNotToBeUndefOrPoison to distribute fixed-length
demanded element masks across CONCAT_VECTORS operands. This is part of
the series of fixes needed to resolve a SelectionDAG hang by making it
possible to prove certain values don't need to be frozen.
AI note: an LLM generated the code and the test, I've read them
Co-Authored-By: OpenAI Codex <codex at openai.com>
---
.../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 23 +++++++++++++++++++
llvm/test/CodeGen/X86/freeze-vector.ll | 16 ++++---------
2 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 75d550801315b..057b3df5a4627 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5665,6 +5665,29 @@ bool SelectionDAG::isGuaranteedNotToBeUndefOrPoison(SDValue Op,
}
return true;
+ case ISD::CONCAT_VECTORS: {
+ EVT VT = Op.getValueType();
+ if (!VT.isFixedLengthVector())
+ return all_of(Op->ops(), [&](SDValue V) {
+ return isGuaranteedNotToBeUndefOrPoison(V, Kind, Depth + 1);
+ });
+
+ assert(DemandedElts.getBitWidth() == VT.getVectorNumElements() &&
+ "Unexpected demanded element mask width");
+
+ EVT SubVT = Op.getOperand(0).getValueType();
+ unsigned NumSubElts = SubVT.getVectorNumElements();
+ for (unsigned i = 0, e = Op.getNumOperands(); i != e; ++i) {
+ APInt DemandedSubElts =
+ DemandedElts.extractBits(NumSubElts, i * NumSubElts);
+ if (!!DemandedSubElts &&
+ !isGuaranteedNotToBeUndefOrPoison(Op.getOperand(i), DemandedSubElts,
+ Kind, Depth + 1))
+ return false;
+ }
+ return true;
+ }
+
case ISD::EXTRACT_SUBVECTOR: {
SDValue Src = Op.getOperand(0);
if (Src.getValueType().isScalableVector())
diff --git a/llvm/test/CodeGen/X86/freeze-vector.ll b/llvm/test/CodeGen/X86/freeze-vector.ll
index 76295cc6c737c..b7bce108860cd 100644
--- a/llvm/test/CodeGen/X86/freeze-vector.ll
+++ b/llvm/test/CodeGen/X86/freeze-vector.ll
@@ -767,18 +767,10 @@ define void @freeze_buildvector_not_simple_type(ptr %dst) nounwind {
}
define <4 x i32> @freeze_lshr_extract_concat_high_demanded(<4 x i32> %a, <4 x i32> %b) {
-; X86-LABEL: freeze_lshr_extract_concat_high_demanded:
-; X86: # %bb.0:
-; X86-NEXT: vpsrld $1, %xmm1, %xmm0
-; X86-NEXT: retl
-;
-; X64-LABEL: freeze_lshr_extract_concat_high_demanded:
-; X64: # %bb.0:
-; X64-NEXT: vinserti128 $1, %xmm1, %ymm0, %ymm0
-; X64-NEXT: vpsrld $1, %ymm0, %ymm0
-; X64-NEXT: vextracti128 $1, %ymm0, %xmm0
-; X64-NEXT: vzeroupper
-; X64-NEXT: retq
+; CHECK-LABEL: freeze_lshr_extract_concat_high_demanded:
+; CHECK: # %bb.0:
+; CHECK-NEXT: vpsrld $1, %xmm1, %xmm0
+; CHECK-NEXT: ret{{[l|q]}}
%poisonable = add nsw <4 x i32> %a, <i32 2147483647, i32 2147483647, i32 2147483647, i32 2147483647>
%wide = shufflevector <4 x i32> %poisonable, <4 x i32> %b, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
%shifted = lshr <8 x i32> %wide, <i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1>
>From 1a3285e6fc2afbb79502c0cad64ac4b6f45917d6 Mon Sep 17 00:00:00 2001
From: Krzysztof Drewniak <Krzysztof.Drewniak at amd.com>
Date: Wed, 3 Jun 2026 18:22:37 +0000
Subject: [PATCH 2/2] Review comments
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 057b3df5a4627..87fa8414279b5 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5668,20 +5668,15 @@ bool SelectionDAG::isGuaranteedNotToBeUndefOrPoison(SDValue Op,
case ISD::CONCAT_VECTORS: {
EVT VT = Op.getValueType();
if (!VT.isFixedLengthVector())
- return all_of(Op->ops(), [&](SDValue V) {
- return isGuaranteedNotToBeUndefOrPoison(V, Kind, Depth + 1);
- });
-
- assert(DemandedElts.getBitWidth() == VT.getVectorNumElements() &&
- "Unexpected demanded element mask width");
+ break;
EVT SubVT = Op.getOperand(0).getValueType();
unsigned NumSubElts = SubVT.getVectorNumElements();
- for (unsigned i = 0, e = Op.getNumOperands(); i != e; ++i) {
+ for (unsigned I = 0, E = Op.getNumOperands(); I != E; ++I) {
APInt DemandedSubElts =
- DemandedElts.extractBits(NumSubElts, i * NumSubElts);
+ DemandedElts.extractBits(NumSubElts, I * NumSubElts);
if (!!DemandedSubElts &&
- !isGuaranteedNotToBeUndefOrPoison(Op.getOperand(i), DemandedSubElts,
+ !isGuaranteedNotToBeUndefOrPoison(Op.getOperand(I), DemandedSubElts,
Kind, Depth + 1))
return false;
}
More information about the llvm-branch-commits
mailing list