Skip to content

Commit 7753dc3

Browse files
committed
Address review feedback
- Expand testing
1 parent 6a3216e commit 7753dc3

File tree

3 files changed

+268
-28
lines changed

3 files changed

+268
-28
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
709709
#undef HANDLEBINOP
710710

711711
mlir::Value emitCmp(const BinaryOperator *e) {
712+
const mlir::Location loc = cgf.getLoc(e->getExprLoc());
712713
mlir::Value result;
713714
QualType lhsTy = e->getLHS()->getType();
714715
QualType rhsTy = e->getRHS()->getType();
@@ -734,44 +735,39 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
734735
};
735736

736737
if (lhsTy->getAs<MemberPointerType>()) {
738+
assert(!cir::MissingFeatures::dataMemberType());
737739
assert(e->getOpcode() == BO_EQ || e->getOpcode() == BO_NE);
738740
mlir::Value lhs = cgf.emitScalarExpr(e->getLHS());
739741
mlir::Value rhs = cgf.emitScalarExpr(e->getRHS());
740742
cir::CmpOpKind kind = clangCmpToCIRCmp(e->getOpcode());
741-
result =
742-
builder.createCompare(cgf.getLoc(e->getExprLoc()), kind, lhs, rhs);
743+
result = builder.createCompare(loc, kind, lhs, rhs);
743744
} else if (!lhsTy->isAnyComplexType() && !rhsTy->isAnyComplexType()) {
744745
BinOpInfo boInfo = emitBinOps(e);
745746
mlir::Value lhs = boInfo.lhs;
746747
mlir::Value rhs = boInfo.rhs;
747748

748749
if (lhsTy->isVectorType()) {
749750
assert(!cir::MissingFeatures::vectorType());
750-
cgf.cgm.errorNYI(boInfo.loc, "vector comparisons");
751-
result = builder.getBool(false, cgf.getLoc(boInfo.loc));
751+
cgf.cgm.errorNYI(loc, "vector comparisons");
752+
result = builder.getBool(false, loc);
752753
} else if (boInfo.isFixedPointOp()) {
753754
assert(!cir::MissingFeatures::fixedPointType());
754-
cgf.cgm.errorNYI(boInfo.loc, "fixed point comparisons");
755-
result = builder.getBool(false, cgf.getLoc(boInfo.loc));
756-
} else if (lhsTy->hasSignedIntegerRepresentation()) {
757-
cir::CmpOpKind kind = clangCmpToCIRCmp(e->getOpcode());
758-
result = builder.createCompare(cgf.getLoc(boInfo.loc), kind, lhs, rhs);
755+
cgf.cgm.errorNYI(loc, "fixed point comparisons");
756+
result = builder.getBool(false, loc);
759757
} else {
760758
// Unsigned integers and pointers.
761759
if (cgf.cgm.getCodeGenOpts().StrictVTablePointers &&
762760
mlir::isa<cir::PointerType>(lhs.getType()) &&
763761
mlir::isa<cir::PointerType>(rhs.getType())) {
764-
cgf.cgm.errorNYI(boInfo.loc, "strict vtable pointer comparisons");
765-
result = builder.getBool(false, cgf.getLoc(boInfo.loc));
762+
cgf.cgm.errorNYI(loc, "strict vtable pointer comparisons");
766763
}
767764

768765
cir::CmpOpKind kind = clangCmpToCIRCmp(e->getOpcode());
769-
result = builder.createCompare(cgf.getLoc(boInfo.loc), kind, lhs, rhs);
766+
result = builder.createCompare(loc, kind, lhs, rhs);
770767
}
771768
} else {
772769
// Complex Comparison: can only be an equality comparison.
773770
assert(!cir::MissingFeatures::complexType());
774-
const mlir::Location loc = cgf.getLoc(e->getSourceRange());
775771
cgf.cgm.errorNYI(loc, "complex comparison");
776772
result = builder.getBool(false, loc);
777773
}

clang/test/CIR/CodeGen/cast.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -DCIR_ONLY %s -o %t.cir
1+
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
22
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
33
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
44
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
@@ -57,16 +57,16 @@ int cStyleCasts_0(unsigned x1, int x2, float x3, short x4, double x5) {
5757
// CIR: %{{[0-9]+}} = cir.cast(bool_to_int, %{{[0-9]+}} : !cir.bool), !s32i
5858
// LLVM: %{{[0-9]+}} = zext i1 %{{[0-9]+}} to i32
5959

60-
#ifdef CIR_ONLY
6160
bool b2 = x2; // int to bool
6261
// CIR: %{{[0-9]+}} = cir.cast(int_to_bool, %{{[0-9]+}} : !s32i), !cir.bool
63-
#endif
62+
// LLVM: %[[INTTOBOOL:[0-9]+]] = icmp ne i32 %{{[0-9]+}}, 0
63+
// LLVM: zext i1 %[[INTTOBOOL]] to i8
6464

65-
#ifdef CIR_ONLY
6665
void *p;
67-
bool b3 = p; // ptr to bool
66+
bool b3 = p; // ptr to bool
6867
// CIR: %{{[0-9]+}} = cir.cast(ptr_to_bool, %{{[0-9]+}} : !cir.ptr<!void>), !cir.bool
69-
#endif
68+
// LLVM: %[[PTRTOBOOL:[0-9]+]] = icmp ne ptr %{{[0-9]+}}, null
69+
// LLVM: zext i1 %[[PTRTOBOOL]] to i8
7070

7171
float f;
7272
bool b4 = f; // float to bool
@@ -77,7 +77,6 @@ int cStyleCasts_0(unsigned x1, int x2, float x3, short x4, double x5) {
7777
return 0;
7878
}
7979

80-
#ifdef CIR_ONLY
8180
bool cptr(void *d) {
8281
bool x = d;
8382
return x;
@@ -88,7 +87,15 @@ bool cptr(void *d) {
8887

8988
// CIR: %[[DVAL:[0-9]+]] = cir.load %[[DPTR]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void>
9089
// CIR: %{{[0-9]+}} = cir.cast(ptr_to_bool, %[[DVAL]] : !cir.ptr<!void>), !cir.bool
91-
#endif
90+
91+
// LLVM-LABEL: define i1 @cptr(ptr %0)
92+
// LLVM: %[[ARG_STORAGE:.*]] = alloca ptr, i64 1
93+
// LLVM: %[[RETVAL:.*]] = alloca i8, i64 1
94+
// LLVM: %[[X_STORAGE:.*]] = alloca i8, i64 1
95+
// LLVM: store ptr %0, ptr %[[ARG_STORAGE]]
96+
// LLVM: %[[LOADED_PTR:.*]] = load ptr, ptr %[[ARG_STORAGE]]
97+
// LLVM: %[[NULL_CHECK:.*]] = icmp ne ptr %[[LOADED_PTR]], null
98+
// LLVM: ret i1
9299

93100
void should_not_cast() {
94101
unsigned x1;

0 commit comments

Comments
 (0)