Skip to content

Commit 95a497b

Browse files
authored
[CIR] Enable cir.bool binops (#1312)
Add !cir.bool to the list of types accepted by the binop rewriter. Although we don't generate boolean binops from logical operations on C++ boolean values, there will be cases where such operations are useful while generating conditions for other operations, such as the overflow checks needed for array new handling.
1 parent 82d18f5 commit 95a497b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,8 +2678,8 @@ mlir::LogicalResult CIRToLLVMBinOpLowering::matchAndRewrite(
26782678
"inconsistent operands' types not supported yet");
26792679

26802680
mlir::Type type = op.getRhs().getType();
2681-
assert((mlir::isa<cir::IntType, cir::CIRFPTypeInterface, cir::VectorType,
2682-
mlir::IntegerType>(type)) &&
2681+
assert((mlir::isa<cir::IntType, cir::BoolType, cir::CIRFPTypeInterface,
2682+
cir::VectorType, mlir::IntegerType>(type)) &&
26832683
"operand type not supported yet");
26842684

26852685
auto llvmTy = getTypeConverter()->convertType(op.getType());
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: cir-opt %s -cir-to-llvm -o %t.mlir
2+
// RUN: FileCheck --input-file=%t.mlir %s
3+
4+
module {
5+
cir.func @foo() {
6+
%0 = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["a", init] {alignment = 4 : i64}
7+
%1 = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["b", init] {alignment = 4 : i64}
8+
%2 = cir.load %0 : !cir.ptr<!cir.bool>, !cir.bool
9+
%3 = cir.load %1 : !cir.ptr<!cir.bool>, !cir.bool
10+
%4 = cir.binop(or, %2, %3) : !cir.bool
11+
// CHECK: = llvm.or {{.*}}, {{.*}} : i1
12+
%5 = cir.binop(xor, %2, %3) : !cir.bool
13+
// CHECK: = llvm.xor {{.*}}, {{.*}} : i1
14+
%6 = cir.binop(and, %2, %3) : !cir.bool
15+
// CHECK: = llvm.and {{.*}}, {{.*}} : i1
16+
cir.return
17+
}
18+
}

0 commit comments

Comments
 (0)