[clang] [CIR] Support vector of boolean in cir.minus op (PR #217089)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 18 10:32:00 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Amr Hesham (AmrDeveloper)
<details>
<summary>Changes</summary>
Support the Vector of bool type in the minus operation
---
Full diff: https://github.com/llvm/llvm-project/pull/217089.diff
3 Files Affected:
- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+1-1)
- (modified) clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td (+6)
- (modified) clang/test/CIR/CodeGen/vector-bool.cpp (+19)
``````````diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index fbb71206b2a89..3e72c6889566f 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2051,7 +2051,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 4e6f95902b81e..9033b60a0a459 100644
--- a/clang/test/CIR/CodeGen/vector-bool.cpp
+++ b/clang/test/CIR/CodeGen/vector-bool.cpp
@@ -233,3 +233,22 @@ void vec_bool_bitwise_operators() {
// SHARED: %[[XOR:.*]] = xor <8 x i1> %[[TMP_A_VEC]], %[[TMP_B_VEC]]
// SHARED: %[[XOR_I8:.*]] = bitcast <8 x i1> %[[XOR]] to i8
// SHARED: store i8 %[[XOR_I8]], ptr %[[XOR_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
``````````
</details>
https://github.com/llvm/llvm-project/pull/217089
More information about the cfe-commits
mailing list