[clang] [CIR] Support vector of boolean in cir.minus op (PR #217089)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 10 21:11:24 PDT 2026
https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/217089
>From dad5ac61fb5c4a1393565f491ff69f70e92b42b7 Mon Sep 17 00:00:00 2001
From: Amr Hesham <amr96 at programmer.net>
Date: Tue, 18 Aug 2026 19:25:53 +0200
Subject: [PATCH] [CIR] Support vector of boolean in cir.minus op
---
clang/include/clang/CIR/Dialect/IR/CIROps.td | 2 +-
.../CIR/Dialect/IR/CIRTypeConstraints.td | 6 ++++++
clang/test/CIR/CodeGen/vector-bool.cpp | 19 +++++++++++++++++++
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 449af063cf9ac..4507f227b1032 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2055,7 +2055,7 @@ def CIR_DecOp
//===----------------------------------------------------------------------===//
def CIR_MinusOp
- : CIR_UnaryOpWithOverflowFlag<"minus", CIR_AnyIntOrVecOfIntType> {
+ : CIR_UnaryOpWithOverflowFlag<"minus", CIR_AnyIntOrVecOfIntOrBoolType> {
let summary = "Integer unary minus (negation)";
let description = [{
The `cir.minus` operation negates the operand. The operand and result
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
index afdd732a5867f..2f8029c355109 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
@@ -342,6 +342,12 @@ def CIR_AnyIntOrVecOfIntType
let cppFunctionName = "isIntOrVectorOfIntType";
}
+def CIR_AnyIntOrVecOfIntOrBoolType
+ : AnyTypeOf<[CIR_AnyIntType, CIR_VectorOfIntOrBoolType],
+ "integer or vector of bool or integer type"> {
+ let cppFunctionName = "isIntOrVecOfIntOrBoolType";
+}
+
def CIR_AnySIntOrVecOfSIntType
: AnyTypeOf<[CIR_AnySIntType, CIR_VectorOfSIntType],
"signed integer or vector of signed integer type"> {
diff --git a/clang/test/CIR/CodeGen/vector-bool.cpp b/clang/test/CIR/CodeGen/vector-bool.cpp
index 9c0ada81f7559..e5b818e655579 100644
--- a/clang/test/CIR/CodeGen/vector-bool.cpp
+++ b/clang/test/CIR/CodeGen/vector-bool.cpp
@@ -412,3 +412,22 @@ void vec_bool_dynamic_shuffling() {
// SHARED: %[[SHUF_INS_7:.*]] = insertelement <8 x i1> %[[SHUF_INS_6]], i1 %[[SHUF_ELT_7]], i64 7
// SHARED: %[[RESULT_I8:.*]] = bitcast <8 x i1> %[[SHUF_INS_7]] to i8
// SHARED: store i8 %[[RESULT_I8]], ptr %[[C_ADDR]], align 1
+
+void vec_bool_minus_op() {
+ v8b a;
+ v8b b = -a;
+}
+
+// CIR: %[[A_ADDR:.*]] = cir.alloca "a" {{.*}} : !cir.ptr<!cir.vector<8 x !cir.bool>>
+// CIR: %[[B_ADDR:.*]] = cir.alloca "b" {{.*}} init : !cir.ptr<!cir.vector<8 x !cir.bool>>
+// CIR: %[[TMP_A:.*]] = cir.load {{.*}} %[[A_ADDR]] : !cir.ptr<!cir.vector<8 x !cir.bool>>, !cir.vector<8 x !cir.bool>
+// CIR: %[[RESULT:.*]] = cir.minus %[[TMP_A]] : !cir.vector<8 x !cir.bool>
+// CIR: cir.store {{.*}} %[[RESULT]], %[[B_ADDR]] : !cir.vector<8 x !cir.bool>, !cir.ptr<!cir.vector<8 x !cir.bool>>
+
+// SHARED: %[[A_ADDR:.*]] = alloca i8, align 1
+// SHARED: %[[B_ADDR:.*]] = alloca i8, align 1
+// SHARED: %[[TMP_A:.*]] = load i8, ptr %[[A_ADDR]], align 1
+// SHARED: %[[TMP_A_VEC:.*]] = bitcast i8 %[[TMP_A]] to <8 x i1>
+// SHARED: %[[RESULT:.*]] = sub <8 x i1> zeroinitializer, %[[TMP_A_VEC]]
+// SHARED: %[[RESULT_I8:.*]] = bitcast <8 x i1> %[[RESULT]] to i8
+// SHARED: store i8 %[[RESULT_I8]], ptr %[[B_ADDR]], align 1
More information about the cfe-commits
mailing list