[clang] [CIR] Lower constant vectors with undef, poison and zero elements (PR #246018)

Henrich Lauko via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 25 08:01:50 PST 2026


https://github.com/xlauko updated https://github.com/llvm/llvm-project/pull/246018

>From ae843502954ab03ec2131c45633cf6d228abf34c Mon Sep 17 00:00:00 2001
From: Henrich Lauko <hlauko at nvidia.com>
Date: Wed, 25 Nov 2026 14:14:31 +0000
Subject: [PATCH] [CIR] Lower constant vectors with undef, poison and zero
 elements

The `cir::ConstVectorAttr` verifier only checks the element types, so
`#cir.undef`, `#cir.poison` and `#cir.zero` are valid elements, and
`VecShuffleOp::fold` created an undef element for a -1 index. The
lowering to the LLVM dialect handled int, float and bool elements and
hit an `llvm_unreachable` on anything else, so a
`__builtin_shufflevector` of two constant vectors with a -1 index
crashed `-fclangir -emit-llvm`.

A zero element is now a zero in the dense constant. An undef or poison
element also takes a zero there and is then replaced by an
`llvm.insertelement` of `llvm.mlir.undef` or `llvm.mlir.poison`.
`llvm.mlir.constant` cannot hold such an element itself: a dense
elements attribute holds only literals, and the translation to LLVM IR
accepts a per-element `LLVM::UndefAttr` or `LLVM::ZeroAttr` only in
struct and array constants and no `LLVM::PoisonAttr` at all. The
IRBuilder folds the insertions when the module is translated, in
function bodies and in global initializers, so the LLVM IR holds one
constant such as `<4 x i32> <i32 poison, i32 2, i32 3, i32 4>`. A vector
that is undef or poison in every element lowers to a single
`llvm.mlir.undef` or `llvm.mlir.poison` of the vector type. A vector of
literals lowers as before.

`VecShuffleOp::fold` now creates a poison element for a -1 index. Classic
codegen and the lowering of a shuffle that is not folded both give
poison there.

Assisted-by: Claude Code (Fable 5.2).
---
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp       |   2 +-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp |  42 +++-
 .../CodeGen/vector-shuffle-poison-index.cpp   |  53 +++++
 .../const-vector-undef-poison-zero.cir        | 187 ++++++++++++++++++
 .../CIR/Transforms/vector-shuffle-fold.cir    |   2 +-
 5 files changed, 278 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CIR/CodeGen/vector-shuffle-poison-index.cpp
 create mode 100644 clang/test/CIR/Lowering/const-vector-undef-poison-zero.cir

diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index e81db4631eeef4..ef204c0a97b186 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -4698,7 +4698,7 @@ OpFoldResult cir::VecShuffleOp::fold(FoldAdaptor adaptor) {
   uint64_t vec1Size = vec1Elts.size();
   for (const auto &idxAttr : indicesElts.getAsRange<cir::IntAttr>()) {
     if (idxAttr.getSInt() == -1) {
-      elements.push_back(cir::UndefAttr::get(vec1ElemTy));
+      elements.push_back(cir::PoisonAttr::get(vec1ElemTy));
       continue;
     }
 
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index e0dd52a9268739..dfefdd83f14ea6 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -1083,7 +1083,15 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstRecordAttr constRecord) {
 
 /// ConstVectorAttr visitor.
 mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstVectorAttr attr) {
-  const mlir::Type llvmTy = converter->convertType(attr.getType());
+  const auto llvmTy =
+      mlir::cast<mlir::VectorType>(converter->convertType(attr.getType()));
+  const mlir::Type llvmEltTy = llvmTy.getElementType();
+
+  // A vector that is undef or poison in every element is that one value.
+  if (llvm::all_of(attr.getElts(), llvm::IsaPred<cir::UndefAttr>))
+    return mlir::LLVM::UndefOp::create(rewriter, parentLoc, llvmTy);
+  if (llvm::all_of(attr.getElts(), llvm::IsaPred<cir::PoisonAttr>))
+    return mlir::LLVM::PoisonOp::create(rewriter, parentLoc, llvmTy);
 
   SmallVector<mlir::Attribute> mlirValues;
   for (const mlir::Attribute elementAttr : attr.getElts()) {
@@ -1096,17 +1104,39 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstVectorAttr attr) {
           converter->convertType(floatAttr.getType()), floatAttr.getValue());
     } else if (auto boolAttr = mlir::dyn_cast<cir::BoolAttr>(elementAttr)) {
       mlirAttr = rewriter.getBoolAttr(boolAttr.getValue());
+    } else if (mlir::isa<cir::ZeroAttr, cir::UndefAttr, cir::PoisonAttr>(
+                   elementAttr)) {
+      // An undef or poison element is inserted over this zero below.
+      mlirAttr = rewriter.getZeroAttr(llvmEltTy);
     } else {
-      llvm_unreachable("vector constant with an element that is neither an "
-                       "int, a float, or a bool");
+      llvm_unreachable("unexpected ConstVectorAttr element");
     }
     mlirValues.push_back(mlirAttr);
   }
 
-  return mlir::LLVM::ConstantOp::create(
+  mlir::Value result = mlir::LLVM::ConstantOp::create(
       rewriter, parentLoc, llvmTy,
-      mlir::DenseElementsAttr::get(mlir::cast<mlir::ShapedType>(llvmTy),
-                                   mlirValues));
+      mlir::DenseElementsAttr::get(llvmTy, mlirValues));
+
+  // A dense constant holds only literals, so an undef or poison element is
+  // inserted into it. The translation to LLVM IR folds the insertions back
+  // into one constant. The scalar visitors are not used here: they produce the
+  // in-memory type, which for a bool is not the type of a vector element.
+  for (const auto [lane, elementAttr] : llvm::enumerate(attr.getElts())) {
+    mlir::Value element;
+    if (mlir::isa<cir::UndefAttr>(elementAttr))
+      element = mlir::LLVM::UndefOp::create(rewriter, parentLoc, llvmEltTy);
+    else if (mlir::isa<cir::PoisonAttr>(elementAttr))
+      element = mlir::LLVM::PoisonOp::create(rewriter, parentLoc, llvmEltTy);
+    else
+      continue;
+    mlir::Value index = mlir::LLVM::ConstantOp::create(
+        rewriter, parentLoc, rewriter.getI64Type(), lane);
+    result = mlir::LLVM::InsertElementOp::create(rewriter, parentLoc, result,
+                                                 element, index);
+  }
+
+  return result;
 }
 
 // GlobalViewAttr / GlobalOffsetAttr visitors.
diff --git a/clang/test/CIR/CodeGen/vector-shuffle-poison-index.cpp b/clang/test/CIR/CodeGen/vector-shuffle-poison-index.cpp
new file mode 100644
index 00000000000000..ebe02db500c2c1
--- /dev/null
+++ b/clang/test/CIR/CodeGen/vector-shuffle-poison-index.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefixes=LLVM,LLVMCIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s -check-prefixes=LLVM,OGCG
+
+// A shuffle of two constant vectors folds to a constant vector. A -1 index
+// leaves a poison element in it, as in classic codegen.
+
+typedef int vi4 __attribute__((vector_size(16)));
+typedef float vf4 __attribute__((vector_size(16)));
+
+// The -1 index keeps the initializer from being a constant expression, so the
+// folded vector is stored by the dynamic initializer.
+vi4 g_shuffle =
+    __builtin_shufflevector(vi4{1, 2, 3, 4}, vi4{5, 6, 7, 8}, 4, -1, 6, -1);
+
+// CIR-LABEL: cir.func {{.*}} @__cxx_global_var_init
+// CIR: cir.const #cir.const_vector<[#cir.int<5> : !s32i, #cir.poison : !s32i, #cir.int<7> : !s32i, #cir.poison : !s32i]> : !cir.vector<4 x !s32i>
+
+// LLVM-LABEL: define internal void @__cxx_global_var_init()
+// LLVM: store <4 x i32> <i32 5, i32 poison, i32 7, i32 poison>, ptr @g_shuffle, align 16
+// LLVM-NEXT: ret void
+
+vi4 shuffle_int() {
+  return __builtin_shufflevector(vi4{1, 2, 3, 4}, vi4{5, 6, 7, 8}, -1, 1, 2, 3);
+}
+
+// CIR-LABEL: cir.func {{.*}} @_Z11shuffle_intv
+// CIR: cir.const #cir.const_vector<[#cir.poison : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.vector<4 x !s32i>
+
+// LLVM-LABEL: define dso_local noundef <4 x i32> @_Z11shuffle_intv()
+// FIXME: ClangIR stores the result to a return slot and reloads it.
+// LLVMCIR: store <4 x i32> <i32 poison, i32 2, i32 3, i32 4>, ptr %[[SLOT:.*]], align 16
+// LLVMCIR-NEXT: %[[RET:.*]] = load <4 x i32>, ptr %[[SLOT]], align 16
+// LLVMCIR-NEXT: ret <4 x i32> %[[RET]]
+// OGCG: ret <4 x i32> <i32 poison, i32 2, i32 3, i32 4>
+
+vf4 shuffle_float() {
+  return __builtin_shufflevector(vf4{1.0f, 2.0f, 3.0f, 4.0f},
+                                 vf4{5.0f, 6.0f, 7.0f, 8.0f}, 0, -1, 6, -1);
+}
+
+// CIR-LABEL: cir.func {{.*}} @_Z13shuffle_floatv
+// CIR: cir.const #cir.const_vector<[#cir.fp<1.000000e+00> : !cir.float, #cir.poison : !cir.float, #cir.fp<7.000000e+00> : !cir.float, #cir.poison : !cir.float]> : !cir.vector<4 x !cir.float>
+
+// LLVM-LABEL: define dso_local noundef <4 x float> @_Z13shuffle_floatv()
+// FIXME: ClangIR stores the result to a return slot and reloads it.
+// LLVMCIR: store <4 x float> <float 1.000000e+00, float poison, float 7.000000e+00, float poison>, ptr %[[SLOT:.*]], align 16
+// LLVMCIR-NEXT: %[[RET:.*]] = load <4 x float>, ptr %[[SLOT]], align 16
+// LLVMCIR-NEXT: ret <4 x float> %[[RET]]
+// OGCG: ret <4 x float> <float 1.000000e+00, float poison, float 7.000000e+00, float poison>
diff --git a/clang/test/CIR/Lowering/const-vector-undef-poison-zero.cir b/clang/test/CIR/Lowering/const-vector-undef-poison-zero.cir
new file mode 100644
index 00000000000000..b08a1650e5c407
--- /dev/null
+++ b/clang/test/CIR/Lowering/const-vector-undef-poison-zero.cir
@@ -0,0 +1,187 @@
+// RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR
+// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM
+
+// A constant vector may hold undef, poison and zero elements. A zero stays in
+// the dense constant. An undef or poison element is inserted into it, and the
+// translation to LLVM IR folds the insertion. A vector that is undef or poison
+// in every element is a single undef or poison value.
+
+!s32i = !cir.int<s, 32>
+
+module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
+  cir.global external @g_mixed = #cir.const_vector<[#cir.int<1> : !s32i, #cir.undef : !s32i, #cir.poison : !s32i, #cir.zero : !s32i]> : !cir.vector<4 x !s32i>
+  // MLIR: llvm.mlir.global external @g_mixed() {{.*}}: vector<4xi32> {
+  // MLIR:   %[[VEC:.*]] = llvm.mlir.constant(dense<[1, 0, 0, 0]> : vector<4xi32>) : vector<4xi32>
+  // MLIR:   %[[UNDEF:.*]] = llvm.mlir.undef : i32
+  // MLIR:   %[[ONE:.*]] = llvm.mlir.constant(1 : i64) : i64
+  // MLIR:   %[[INS:.*]] = llvm.insertelement %[[UNDEF]], %[[VEC]][%[[ONE]] : i64] : vector<4xi32>
+  // MLIR:   %[[POISON:.*]] = llvm.mlir.poison : i32
+  // MLIR:   %[[TWO:.*]] = llvm.mlir.constant(2 : i64) : i64
+  // MLIR:   %[[RES:.*]] = llvm.insertelement %[[POISON]], %[[INS]][%[[TWO]] : i64] : vector<4xi32>
+  // MLIR:   llvm.return %[[RES]] : vector<4xi32>
+
+  // LLVM: @g_mixed = global <4 x i32> <i32 1, i32 undef, i32 poison, i32 0>
+
+  cir.global external @g_poison = #cir.const_vector<[#cir.poison : !s32i, #cir.poison : !s32i]> : !cir.vector<2 x !s32i>
+  // MLIR: llvm.mlir.global external @g_poison() {{.*}}: vector<2xi32> {
+  // MLIR-NEXT:   %[[POISON:.*]] = llvm.mlir.poison : vector<2xi32>
+  // MLIR-NEXT:   llvm.return %[[POISON]] : vector<2xi32>
+
+  // LLVM: @g_poison = global <2 x i32> poison
+
+  cir.func @int_undef() -> !cir.vector<4 x !s32i> {
+    %0 = cir.const #cir.const_vector<[#cir.undef : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.vector<4 x !s32i>
+    cir.return %0 : !cir.vector<4 x !s32i>
+  }
+  // MLIR-LABEL: llvm.func @int_undef
+  // MLIR:   %[[VEC:.*]] = llvm.mlir.constant(dense<[0, 2, 3, 4]> : vector<4xi32>) : vector<4xi32>
+  // MLIR:   %[[UNDEF:.*]] = llvm.mlir.undef : i32
+  // MLIR:   %[[ZERO:.*]] = llvm.mlir.constant(0 : i64) : i64
+  // MLIR:   %[[RES:.*]] = llvm.insertelement %[[UNDEF]], %[[VEC]][%[[ZERO]] : i64] : vector<4xi32>
+  // MLIR:   llvm.return %[[RES]] : vector<4xi32>
+
+  // LLVM-LABEL: @int_undef
+  // LLVM:   ret <4 x i32> <i32 undef, i32 2, i32 3, i32 4>
+
+  cir.func @int_poison() -> !cir.vector<4 x !s32i> {
+    %0 = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.poison : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.vector<4 x !s32i>
+    cir.return %0 : !cir.vector<4 x !s32i>
+  }
+  // MLIR-LABEL: llvm.func @int_poison
+  // MLIR:   %[[VEC:.*]] = llvm.mlir.constant(dense<[1, 0, 3, 4]> : vector<4xi32>) : vector<4xi32>
+  // MLIR:   %[[POISON:.*]] = llvm.mlir.poison : i32
+  // MLIR:   %[[ONE:.*]] = llvm.mlir.constant(1 : i64) : i64
+  // MLIR:   %[[RES:.*]] = llvm.insertelement %[[POISON]], %[[VEC]][%[[ONE]] : i64] : vector<4xi32>
+  // MLIR:   llvm.return %[[RES]] : vector<4xi32>
+
+  // LLVM-LABEL: @int_poison
+  // LLVM:   ret <4 x i32> <i32 1, i32 poison, i32 3, i32 4>
+
+  cir.func @int_zero() -> !cir.vector<4 x !s32i> {
+    %0 = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.zero : !s32i, #cir.int<4> : !s32i]> : !cir.vector<4 x !s32i>
+    cir.return %0 : !cir.vector<4 x !s32i>
+  }
+  // MLIR-LABEL: llvm.func @int_zero
+  // MLIR-NEXT:   %[[VEC:.*]] = llvm.mlir.constant(dense<[1, 2, 0, 4]> : vector<4xi32>) : vector<4xi32>
+  // MLIR-NEXT:   llvm.return %[[VEC]] : vector<4xi32>
+
+  // LLVM-LABEL: @int_zero
+  // LLVM:   ret <4 x i32> <i32 1, i32 2, i32 0, i32 4>
+
+  cir.func @float_undef() -> !cir.vector<2 x !cir.float> {
+    %0 = cir.const #cir.const_vector<[#cir.fp<1.000000e+00> : !cir.float, #cir.undef : !cir.float]> : !cir.vector<2 x !cir.float>
+    cir.return %0 : !cir.vector<2 x !cir.float>
+  }
+  // MLIR-LABEL: llvm.func @float_undef
+  // MLIR:   %[[VEC:.*]] = llvm.mlir.constant(dense<[1.000000e+00, 0.000000e+00]> : vector<2xf32>) : vector<2xf32>
+  // MLIR:   %[[UNDEF:.*]] = llvm.mlir.undef : f32
+  // MLIR:   %[[ONE:.*]] = llvm.mlir.constant(1 : i64) : i64
+  // MLIR:   %[[RES:.*]] = llvm.insertelement %[[UNDEF]], %[[VEC]][%[[ONE]] : i64] : vector<2xf32>
+  // MLIR:   llvm.return %[[RES]] : vector<2xf32>
+
+  // LLVM-LABEL: @float_undef
+  // LLVM:   ret <2 x float> <float 1.000000e+00, float undef>
+
+  cir.func @float_poison() -> !cir.vector<2 x !cir.float> {
+    %0 = cir.const #cir.const_vector<[#cir.poison : !cir.float, #cir.fp<2.000000e+00> : !cir.float]> : !cir.vector<2 x !cir.float>
+    cir.return %0 : !cir.vector<2 x !cir.float>
+  }
+  // MLIR-LABEL: llvm.func @float_poison
+  // MLIR:   %[[VEC:.*]] = llvm.mlir.constant(dense<[0.000000e+00, 2.000000e+00]> : vector<2xf32>) : vector<2xf32>
+  // MLIR:   %[[POISON:.*]] = llvm.mlir.poison : f32
+  // MLIR:   %[[ZERO:.*]] = llvm.mlir.constant(0 : i64) : i64
+  // MLIR:   %[[RES:.*]] = llvm.insertelement %[[POISON]], %[[VEC]][%[[ZERO]] : i64] : vector<2xf32>
+  // MLIR:   llvm.return %[[RES]] : vector<2xf32>
+
+  // LLVM-LABEL: @float_poison
+  // LLVM:   ret <2 x float> <float poison, float 2.000000e+00>
+
+  cir.func @float_zero() -> !cir.vector<2 x !cir.float> {
+    %0 = cir.const #cir.const_vector<[#cir.fp<1.000000e+00> : !cir.float, #cir.zero : !cir.float]> : !cir.vector<2 x !cir.float>
+    cir.return %0 : !cir.vector<2 x !cir.float>
+  }
+  // MLIR-LABEL: llvm.func @float_zero
+  // MLIR-NEXT:   %[[VEC:.*]] = llvm.mlir.constant(dense<[1.000000e+00, 0.000000e+00]> : vector<2xf32>) : vector<2xf32>
+  // MLIR-NEXT:   llvm.return %[[VEC]] : vector<2xf32>
+
+  // LLVM-LABEL: @float_zero
+  // LLVM:   ret <2 x float> <float 1.000000e+00, float 0.000000e+00>
+
+  cir.func @bool_undef() -> !cir.vector<4 x !cir.bool> {
+    %0 = cir.const #cir.const_vector<[#cir.undef : !cir.bool, #cir.bool<true> : !cir.bool, #cir.bool<false> : !cir.bool, #cir.bool<true> : !cir.bool]> : !cir.vector<4 x !cir.bool>
+    cir.return %0 : !cir.vector<4 x !cir.bool>
+  }
+  // MLIR-LABEL: llvm.func @bool_undef
+  // MLIR:   %[[VEC:.*]] = llvm.mlir.constant(dense<[false, true, false, true]> : vector<4xi1>) : vector<4xi1>
+  // MLIR:   %[[UNDEF:.*]] = llvm.mlir.undef : i1
+  // MLIR:   %[[ZERO:.*]] = llvm.mlir.constant(0 : i64) : i64
+  // MLIR:   %[[RES:.*]] = llvm.insertelement %[[UNDEF]], %[[VEC]][%[[ZERO]] : i64] : vector<4xi1>
+  // MLIR:   llvm.return %[[RES]] : vector<4xi1>
+
+  // LLVM-LABEL: @bool_undef
+  // LLVM:   ret <4 x i1> <i1 undef, i1 true, i1 false, i1 true>
+
+  cir.func @bool_poison() -> !cir.vector<4 x !cir.bool> {
+    %0 = cir.const #cir.const_vector<[#cir.bool<true> : !cir.bool, #cir.bool<true> : !cir.bool, #cir.bool<false> : !cir.bool, #cir.poison : !cir.bool]> : !cir.vector<4 x !cir.bool>
+    cir.return %0 : !cir.vector<4 x !cir.bool>
+  }
+  // MLIR-LABEL: llvm.func @bool_poison
+  // MLIR:   %[[VEC:.*]] = llvm.mlir.constant(dense<[true, true, false, false]> : vector<4xi1>) : vector<4xi1>
+  // MLIR:   %[[POISON:.*]] = llvm.mlir.poison : i1
+  // MLIR:   %[[THREE:.*]] = llvm.mlir.constant(3 : i64) : i64
+  // MLIR:   %[[RES:.*]] = llvm.insertelement %[[POISON]], %[[VEC]][%[[THREE]] : i64] : vector<4xi1>
+  // MLIR:   llvm.return %[[RES]] : vector<4xi1>
+
+  // LLVM-LABEL: @bool_poison
+  // LLVM:   ret <4 x i1> <i1 true, i1 true, i1 false, i1 poison>
+
+  cir.func @bool_zero() -> !cir.vector<4 x !cir.bool> {
+    %0 = cir.const #cir.const_vector<[#cir.bool<true> : !cir.bool, #cir.zero : !cir.bool, #cir.bool<true> : !cir.bool, #cir.bool<true> : !cir.bool]> : !cir.vector<4 x !cir.bool>
+    cir.return %0 : !cir.vector<4 x !cir.bool>
+  }
+  // MLIR-LABEL: llvm.func @bool_zero
+  // MLIR-NEXT:   %[[VEC:.*]] = llvm.mlir.constant(dense<[true, false, true, true]> : vector<4xi1>) : vector<4xi1>
+  // MLIR-NEXT:   llvm.return %[[VEC]] : vector<4xi1>
+
+  // LLVM-LABEL: @bool_zero
+  // LLVM:   ret <4 x i1> <i1 true, i1 false, i1 true, i1 true>
+
+  cir.func @all_undef() -> !cir.vector<2 x !s32i> {
+    %0 = cir.const #cir.const_vector<[#cir.undef : !s32i, #cir.undef : !s32i]> : !cir.vector<2 x !s32i>
+    cir.return %0 : !cir.vector<2 x !s32i>
+  }
+  // MLIR-LABEL: llvm.func @all_undef
+  // MLIR-NEXT:   %[[VEC:.*]] = llvm.mlir.undef : vector<2xi32>
+  // MLIR-NEXT:   llvm.return %[[VEC]] : vector<2xi32>
+
+  // LLVM-LABEL: @all_undef
+  // LLVM:   ret <2 x i32> undef
+
+  cir.func @all_poison() -> !cir.vector<2 x !cir.float> {
+    %0 = cir.const #cir.const_vector<[#cir.poison : !cir.float, #cir.poison : !cir.float]> : !cir.vector<2 x !cir.float>
+    cir.return %0 : !cir.vector<2 x !cir.float>
+  }
+  // MLIR-LABEL: llvm.func @all_poison
+  // MLIR-NEXT:   %[[VEC:.*]] = llvm.mlir.poison : vector<2xf32>
+  // MLIR-NEXT:   llvm.return %[[VEC]] : vector<2xf32>
+
+  // LLVM-LABEL: @all_poison
+  // LLVM:   ret <2 x float> poison
+
+  cir.func @undef_and_poison() -> !cir.vector<2 x !s32i> {
+    %0 = cir.const #cir.const_vector<[#cir.undef : !s32i, #cir.poison : !s32i]> : !cir.vector<2 x !s32i>
+    cir.return %0 : !cir.vector<2 x !s32i>
+  }
+  // MLIR-LABEL: llvm.func @undef_and_poison
+  // MLIR:   %[[VEC:.*]] = llvm.mlir.constant(dense<0> : vector<2xi32>) : vector<2xi32>
+  // MLIR:   %[[UNDEF:.*]] = llvm.mlir.undef : i32
+  // MLIR:   %[[ZERO:.*]] = llvm.mlir.constant(0 : i64) : i64
+  // MLIR:   %[[INS:.*]] = llvm.insertelement %[[UNDEF]], %[[VEC]][%[[ZERO]] : i64] : vector<2xi32>
+  // MLIR:   %[[POISON:.*]] = llvm.mlir.poison : i32
+  // MLIR:   %[[ONE:.*]] = llvm.mlir.constant(1 : i64) : i64
+  // MLIR:   %[[RES:.*]] = llvm.insertelement %[[POISON]], %[[INS]][%[[ONE]] : i64] : vector<2xi32>
+  // MLIR:   llvm.return %[[RES]] : vector<2xi32>
+
+  // LLVM-LABEL: @undef_and_poison
+  // LLVM:   ret <2 x i32> <i32 undef, i32 poison>
+}
diff --git a/clang/test/CIR/Transforms/vector-shuffle-fold.cir b/clang/test/CIR/Transforms/vector-shuffle-fold.cir
index 7aaddc051a75bc..9b5ffff22d6cf9 100644
--- a/clang/test/CIR/Transforms/vector-shuffle-fold.cir
+++ b/clang/test/CIR/Transforms/vector-shuffle-fold.cir
@@ -53,7 +53,7 @@ module  {
   }
 
   // CHECK: cir.func{{.*}} @fold_shuffle_vector_op_test() -> !cir.vector<4 x !s32i> {
-  // CHECK: cir.const #cir.const_vector<[#cir.undef : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i,
+  // CHECK: cir.const #cir.const_vector<[#cir.poison : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i,
   // CHECK-SAME: #cir.int<4> : !s32i]> : !cir.vector<4 x !s32i>
   // CHECK-NEXT: cir.return %[[RES]] : !cir.vector<4 x !s32i>
 }



More information about the cfe-commits mailing list