Skip to content

Commit

Permalink
[CIR] Force cir.cmp to always return bool
Browse files Browse the repository at this point in the history
It was always the intention for `cir.cmp` operations to return bool result. Due
to missing constraints, a bug in codegen has slipped in which created `cir.cmp`
operations with result type that matches the original AST expression type. In
C, as opposed to C++, boolean expression types are "int". This resulted with
extra operations being codegened around boolean expressions and their usage.

This commit both enforces `cir.cmp` in the op definition and fixes the
mentioned bug.
  • Loading branch information
orbiri committed Nov 15, 2024
1 parent 3aed38c commit 48f4934
Show file tree
Hide file tree
Showing 18 changed files with 531 additions and 588 deletions.
3 changes: 1 addition & 2 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1268,8 +1268,7 @@ def CmpOp : CIR_Op<"cmp", [Pure, SameTypeOperands]> {
```
}];

// TODO: get more accurate than CIR_AnyType
let results = (outs CIR_AnyType:$result);
let results = (outs CIR_BoolType:$result);
let arguments = (ins Arg<CmpOpKind, "cmp kind">:$kind,
CIR_AnyType:$lhs, CIR_AnyType:$rhs);

Expand Down
13 changes: 5 additions & 8 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,12 +947,11 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
// Other kinds of vectors. Element-wise comparison returning
// a vector.
cir::CmpOpKind Kind = ClangCmpToCIRCmp(E->getOpcode());
return Builder.create<cir::VecCmpOp>(CGF.getLoc(BOInfo.Loc),
CGF.getCIRType(BOInfo.FullType),
Kind, BOInfo.LHS, BOInfo.RHS);
Result = Builder.create<cir::VecCmpOp>(
CGF.getLoc(BOInfo.Loc), CGF.getCIRType(BOInfo.FullType), Kind,
BOInfo.LHS, BOInfo.RHS);
}
}
if (BOInfo.isFixedPointOp()) {
} else if (BOInfo.isFixedPointOp()) {
assert(0 && "not implemented");
} else {
// FIXME(cir): handle another if above for CIR equivalent on
Expand All @@ -966,9 +965,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
}

cir::CmpOpKind Kind = ClangCmpToCIRCmp(E->getOpcode());
return Builder.create<cir::CmpOp>(CGF.getLoc(BOInfo.Loc),
CGF.getCIRType(BOInfo.FullType), Kind,
BOInfo.LHS, BOInfo.RHS);
Result = Builder.createCompare(CGF.getLoc(BOInfo.Loc), Kind, LHS, RHS);
}
} else { // Complex Comparison: can only be an equality comparison.
assert(0 && "not implemented");
Expand Down
289 changes: 145 additions & 144 deletions clang/test/CIR/CodeGen/bf16-ops.c

Large diffs are not rendered by default.

144 changes: 72 additions & 72 deletions clang/test/CIR/CodeGen/float16-ops.c

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions clang/test/CIR/CodeGen/fp16-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,145 +228,145 @@ void foo(void) {
// CHECK-LLVM-NEXT: %{{.+}} = fsub half %{{.+}}, %[[#A]]

test = (h2 < h0);
// CHECK: %[[#A:]] = cir.cmp(lt, %{{.+}}, %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#A:]] = cir.cmp(lt, %{{.+}}, %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#A]] : !s32i), !u32i

// CHECK-LLVM: %{{.+}} = fcmp olt half %{{.+}}, %{{.+}}

test = (h2 < (__fp16)42.0);
// CHECK: %[[#A:]] = cir.const #cir.fp<4.200000e+01> : !cir.double
// CHECK-NEXT: %[[#B:]] = cir.cast(floating, %[[#A]] : !cir.double), !cir.f16
// CHECK-NEXT: %[[#C:]] = cir.cmp(lt, %{{.+}}, %[[#B]]) : !cir.f16, !s32i
// CHECK-NEXT: %[[#C:]] = cir.cmp(lt, %{{.+}}, %[[#B]]) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#C]] : !s32i), !u32i

// CHECK-LLVM: %{{.+}} = fcmp olt half %{{.+}}, 0xH5140

test = (h2 < f0);
// CHECK: %[[#A:]] = cir.cast(floating, %{{.+}} : !cir.f16), !cir.float
// CHECK: %[[#B:]] = cir.cmp(lt, %[[#A]], %{{.+}}) : !cir.float, !s32i
// CHECK: %[[#B:]] = cir.cmp(lt, %[[#A]], %{{.+}}) : !cir.float, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#A:]] = fpext half %{{.+}} to float
// CHECK-LLVM: %{{.+}} = fcmp olt float %[[#A]], %{{.+}}

test = (f2 < h0);
// CHECK: %[[#A:]] = cir.cast(floating, %{{.+}} : !cir.f16), !cir.float
// CHECK-NEXT: %[[#B:]] = cir.cmp(lt, %{{.+}}, %[[#A]]) : !cir.float, !s32i
// CHECK-NEXT: %[[#B:]] = cir.cmp(lt, %{{.+}}, %[[#A]]) : !cir.float, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#A:]] = fpext half %{{.=}} to float
// CHECK-LLVM-NEXT: %{{.+}} = fcmp olt float %{{.+}}, %[[#A]]

test = (i0 < h0);
// CHECK: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.f16
// CHECK: %[[#B:]] = cir.cmp(lt, %[[#A]], %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#B:]] = cir.cmp(lt, %[[#A]], %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#A:]] = sitofp i32 %{{.+}} to half
// CHECK-LLVM: %{{.+}} = fcmp olt half %[[#A]], %{{.+}}

test = (h0 < i0);
// CHECK: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.f16
// CHECK-NEXT: %[[#B:]] = cir.cmp(lt, %{{.+}}, %[[#A]]) : !cir.f16, !s32i
// CHECK-NEXT: %[[#B:]] = cir.cmp(lt, %{{.+}}, %[[#A]]) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#A:]] = sitofp i32 %{{.+}} to half
// CHECK-LLVM-NEXT: %{{.+}} = fcmp olt half %{{.+}}, %[[#A]]

test = (h0 > h2);
// CHECK: %[[#A:]] = cir.cmp(gt, %{{.+}}, %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#A:]] = cir.cmp(gt, %{{.+}}, %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#A]] : !s32i), !u32i

// CHECK-LLVM: %{{.+}} = fcmp ogt half %{{.+}}, %{{.+}}

test = ((__fp16)42.0 > h2);
// CHECK: %[[#A:]] = cir.const #cir.fp<4.200000e+01> : !cir.double
// CHECK-NEXT: %[[#B:]] = cir.cast(floating, %[[#A]] : !cir.double), !cir.f16
// CHECK: %[[#C:]] = cir.cmp(gt, %[[#B]], %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#C:]] = cir.cmp(gt, %[[#B]], %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#C]] : !s32i), !u32i

// CHECK-LLVM: %{{.+}} = fcmp ogt half 0xH5140, %{{.+}}

test = (h0 > f2);
// CHECK: %[[#A:]] = cir.cast(floating, %{{.+}} : !cir.f16), !cir.float
// CHECK: %[[#B:]] = cir.cmp(gt, %[[#A]], %{{.+}}) : !cir.float, !s32i
// CHECK: %[[#B:]] = cir.cmp(gt, %[[#A]], %{{.+}}) : !cir.float, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#LHS:]] = fpext half %{{.=}} to float
// CHECK-LLVM: %{{.+}} = fcmp ogt float %[[#LHS]], %{{.+}}

test = (f0 > h2);
// CHECK: %[[#A:]] = cir.cast(floating, %{{.+}} : !cir.f16), !cir.float
// CHECK-NEXT: %[[#B:]] = cir.cmp(gt, %{{.+}}, %[[#A]]) : !cir.float, !s32i
// CHECK-NEXT: %[[#B:]] = cir.cmp(gt, %{{.+}}, %[[#A]]) : !cir.float, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#RHS:]] = fpext half %{{.+}} to float
// CHECK-LLVM-NEXT: %{{.+}} = fcmp ogt float %{{.+}}, %[[#RHS]]

test = (i0 > h0);
// CHECK: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.f16
// CHECK: %[[#B:]] = cir.cmp(gt, %[[#A]], %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#B:]] = cir.cmp(gt, %[[#A]], %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#LHS:]] = sitofp i32 %{{.+}} to half
// CHECK-LLVM: %{{.+}} = fcmp ogt half %[[#LHS]], %{{.+}}

test = (h0 > i0);
// CHECK: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.f16
// CHECK-NEXT: %[[#B:]] = cir.cmp(gt, %{{.+}}, %[[#A]]) : !cir.f16, !s32i
// CHECK-NEXT: %[[#B:]] = cir.cmp(gt, %{{.+}}, %[[#A]]) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#RHS:]] = sitofp i32 %{{.+}} to half
// CHECK-LLVM-NEXT: %{{.+}} = fcmp ogt half %{{.+}}, %[[#RHS]]

test = (h2 <= h0);
// CHECK: %[[#A:]] = cir.cmp(le, %{{.+}}, %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#A:]] = cir.cmp(le, %{{.+}}, %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#A]] : !s32i), !u32i

// CHECK-LLVM: %{{.+}} = fcmp ole half %{{.+}}, %{{.+}}

test = (h2 <= (__fp16)42.0);
// CHECK: %[[#A:]] = cir.const #cir.fp<4.200000e+01> : !cir.double
// CHECK-NEXT: %[[#B:]] = cir.cast(floating, %[[#A]] : !cir.double), !cir.f16
// CHECK-NEXT: %[[#C:]] = cir.cmp(le, %{{.+}}, %[[#B]]) : !cir.f16, !s32i
// CHECK-NEXT: %[[#C:]] = cir.cmp(le, %{{.+}}, %[[#B]]) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#C]] : !s32i), !u32i

// CHECK-LLVM: %{{.+}} = fcmp ole half %{{.+}}, 0xH5140

test = (h2 <= f0);
// CHECK: %[[#A:]] = cir.cast(floating, %{{.+}} : !cir.f16), !cir.float
// CHECK: %[[#B:]] = cir.cmp(le, %[[#A]], %{{.+}}) : !cir.float, !s32i
// CHECK: %[[#B:]] = cir.cmp(le, %[[#A]], %{{.+}}) : !cir.float, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#LHS:]] = fpext half %{{.+}} to float
// CHECK-LLVM: %{{.+}} = fcmp ole float %[[#LHS]], %{{.+}}

test = (f2 <= h0);
// CHECK: %[[#A:]] = cir.cast(floating, %{{.+}} : !cir.f16), !cir.float
// CHECK-NEXT: %[[#B:]] = cir.cmp(le, %{{.+}}, %[[#A]]) : !cir.float, !s32i
// CHECK-NEXT: %[[#B:]] = cir.cmp(le, %{{.+}}, %[[#A]]) : !cir.float, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#RHS:]] = fpext half %{{.+}} to float
// CHECK-LLVM-NEXT: %{{.+}} = fcmp ole float %{{.+}}, %[[#RHS]]

test = (i0 <= h0);
// CHECK: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.f16
// CHECK: %[[#B:]] = cir.cmp(le, %[[#A]], %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#B:]] = cir.cmp(le, %[[#A]], %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#LHS:]] = sitofp i32 %{{.+}} to half
// CHECK-LLVM: %{{.+}} = fcmp ole half %[[#LHS]], %{{.+}}

test = (h0 <= i0);
// CHECK: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.f16
// CHECK-NEXT: %[[#B:]] = cir.cmp(le, %{{.+}}, %[[#A]]) : !cir.f16, !s32i
// CHECK-NEXT: %[[#B:]] = cir.cmp(le, %{{.+}}, %[[#A]]) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#RHS:]] = sitofp i32 %{{.+}} to half
// CHECK-LLVM-NEXT: %{{.+}} = fcmp ole half %{{.+}}, %[[#RHS]]

test = (h0 >= h2);
// CHECK: %[[#A:]] = cir.cmp(ge, %{{.+}}, %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#A:]] = cir.cmp(ge, %{{.+}}, %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#A]] : !s32i), !u32i

// CHECK-LLVM: %{{.+}} = fcmp oge half %{{.+}}, %{{.+}}
Expand All @@ -375,130 +375,130 @@ void foo(void) {
// CHECK: %[[#A:]] = cir.const #cir.fp<2.000000e+00> : !cir.double
// CHECK-NEXT: %[[#B:]] = cir.unary(minus, %[[#A]]) : !cir.double, !cir.double
// CHECK-NEXT: %[[#C:]] = cir.cast(floating, %[[#B]] : !cir.double), !cir.f16
// CHECK-NEXT: %[[#D:]] = cir.cmp(ge, %{{.+}}, %[[#C]]) : !cir.f16, !s32i
// CHECK-NEXT: %[[#D:]] = cir.cmp(ge, %{{.+}}, %[[#C]]) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#D]] : !s32i), !u32i

// CHECK-LLVM: %{{.+}} = fcmp oge half %{{.+}}, 0xHC000

test = (h0 >= f2);
// CHECK: %[[#A:]] = cir.cast(floating, %{{.+}} : !cir.f16), !cir.float
// CHECK: %[[#B:]] = cir.cmp(ge, %[[#A]], %{{.+}}) : !cir.float, !s32i
// CHECK: %[[#B:]] = cir.cmp(ge, %[[#A]], %{{.+}}) : !cir.float, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#LHS:]] = fpext half %{{.+}} to float
// CHECK-LLVM: %{{.+}} = fcmp oge float %[[#LHS]], %{{.+}}

test = (f0 >= h2);
// CHECK: %[[#A:]] = cir.cast(floating, %{{.+}} : !cir.f16), !cir.float
// CHECK-NEXT: %[[#B:]] = cir.cmp(ge, %{{.+}}, %[[#A]]) : !cir.float, !s32i
// CHECK-NEXT: %[[#B:]] = cir.cmp(ge, %{{.+}}, %[[#A]]) : !cir.float, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#RHS:]] = fpext half %{{.+}} to float
// CHECK-LLVM-NEXT: %{{.+}} = fcmp oge float %{{.+}}, %[[#RHS]]

test = (i0 >= h0);
// CHECK: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.f16
// CHECK: %[[#B:]] = cir.cmp(ge, %[[#A]], %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#B:]] = cir.cmp(ge, %[[#A]], %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#LHS:]] = sitofp i32 %{{.+}} to half
// CHECK-LLVM: %{{.+}} = fcmp oge half %[[#LHS]], %{{.+}}

test = (h0 >= i0);
// CHECK: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.f16
// CHECK-NEXT: %[[#B:]] = cir.cmp(ge, %{{.+}}, %[[#A]]) : !cir.f16, !s32i
// CHECK-NEXT: %[[#B:]] = cir.cmp(ge, %{{.+}}, %[[#A]]) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#RHS:]] = sitofp i32 %{{.+}} to half
// CHECK-LLVM-NEXT: %{{.+}} = fcmp oge half %{{.+}}, %[[#RHS]]

test = (h1 == h2);
// CHECK: %[[#A:]] = cir.cmp(eq, %{{.+}}, %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#A:]] = cir.cmp(eq, %{{.+}}, %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#A]] : !s32i), !u32i

// CHECK-LLVM: %{{.+}} = fcmp oeq half %{{.+}}, %{{.+}}

test = (h1 == (__fp16)1.0);
// CHECK: %[[#A:]] = cir.const #cir.fp<1.000000e+00> : !cir.double
// CHECK-NEXT: %[[#B:]] = cir.cast(floating, %[[#A]] : !cir.double), !cir.f16
// CHECK-NEXT: %[[#C:]] = cir.cmp(eq, %{{.+}}, %[[#B]]) : !cir.f16, !s32i
// CHECK-NEXT: %[[#C:]] = cir.cmp(eq, %{{.+}}, %[[#B]]) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#C]] : !s32i), !u32i

// CHECK-LLVM: %{{.+}} = fcmp oeq half %{{.+}}, 0xH3C00

test = (h1 == f1);
// CHECK: %[[#A:]] = cir.cast(floating, %{{.+}} : !cir.f16), !cir.float
// CHECK: %[[#B:]] = cir.cmp(eq, %[[#A]], %{{.+}}) : !cir.float, !s32i
// CHECK: %[[#B:]] = cir.cmp(eq, %[[#A]], %{{.+}}) : !cir.float, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#LHS:]] = fpext half %{{.+}} to float
// CHECK-LLVM: %{{.+}} = fcmp oeq float %[[#LHS]], %{{.+}}

test = (f1 == h1);
// CHECK: %[[#A:]] = cir.cast(floating, %{{.+}} : !cir.f16), !cir.float
// CHECK-NEXT: %[[#B:]] = cir.cmp(eq, %{{.+}}, %[[#A]]) : !cir.float, !s32i
// CHECK-NEXT: %[[#B:]] = cir.cmp(eq, %{{.+}}, %[[#A]]) : !cir.float, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#RHS:]] = fpext half %{{.+}} to float
// CHECK-LLVM-NEXT: %{{.+}} = fcmp oeq float %{{.+}}, %[[#RHS]]

test = (i0 == h0);
// CHECK: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.f16
// CHECK: %[[#B:]] = cir.cmp(eq, %[[#A]], %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#B:]] = cir.cmp(eq, %[[#A]], %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#LHS:]] = sitofp i32 %{{.+}} to half
// CHECK-LLVM: %{{.+}} = fcmp oeq half %[[#LHS]], %{{.+}}

test = (h0 == i0);
// CHECK: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.f16
// CHECK-NEXT: %[[#B:]] = cir.cmp(eq, %{{.+}}, %[[#A]]) : !cir.f16, !s32i
// CHECK-NEXT: %[[#B:]] = cir.cmp(eq, %{{.+}}, %[[#A]]) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#RHS:]] = sitofp i32 %{{.+}} to half
// CHECK-LLVM-NEXT: %{{.=}} = fcmp oeq half %{{.+}}, %[[#RHS]]

test = (h1 != h2);
// CHECK: %[[#A:]] = cir.cmp(ne, %{{.+}}, %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#A:]] = cir.cmp(ne, %{{.+}}, %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#A]] : !s32i), !u32i

// CHECK-LLVM: %{{.+}} = fcmp une half %{{.+}}, %{{.+}}

test = (h1 != (__fp16)1.0);
// CHECK: %[[#A:]] = cir.const #cir.fp<1.000000e+00> : !cir.double
// CHECK-NEXT: %[[#B:]] = cir.cast(floating, %[[#A]] : !cir.double), !cir.f16
// CHECK-NEXT: %[[#C:]] = cir.cmp(ne, %{{.+}}, %[[#B]]) : !cir.f16, !s32i
// CHECK-NEXT: %[[#C:]] = cir.cmp(ne, %{{.+}}, %[[#B]]) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#C]] : !s32i), !u32i

// CHECK-LLVM: %{{.+}} = fcmp une half %{{.+}}, 0xH3C00

test = (h1 != f1);
// CHECK: %[[#A:]] = cir.cast(floating, %{{.+}} : !cir.f16), !cir.float
// CHECK: %[[#B:]] = cir.cmp(ne, %[[#A]], %{{.+}}) : !cir.float, !s32i
// CHECK: %[[#B:]] = cir.cmp(ne, %[[#A]], %{{.+}}) : !cir.float, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#LHS:]] = fpext half %{{.=}} to float
// CHECK-LLVM: %{{.+}} = fcmp une float %[[#LHS]], %{{.+}}

test = (f1 != h1);
// CHECK: %[[#A:]] = cir.cast(floating, %{{.+}} : !cir.f16), !cir.float
// CHECK-NEXT: %[[#B:]] = cir.cmp(ne, %{{.+}}, %[[#A]]) : !cir.float, !s32i
// CHECK-NEXT: %[[#B:]] = cir.cmp(ne, %{{.+}}, %[[#A]]) : !cir.float, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#A:]] = fpext half %{{.+}} to float
// CHECK-LLVM-NEXT: %{{.+}} = fcmp une float %{{.+}}, %[[#A]]

test = (i0 != h0);
// CHECK: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.f16
// CHECK: %[[#B:]] = cir.cmp(ne, %[[#A]], %{{.+}}) : !cir.f16, !s32i
// CHECK: %[[#B:]] = cir.cmp(ne, %[[#A]], %{{.+}}) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#LHS:]] = sitofp i32 %{{.+}} to half
// CHECK-LLVM: %{{.+}} = fcmp une half %[[#LHS]], %{{.+}}

test = (h0 != i0);
// CHECK: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.f16
// CHECK-NEXT: %[[#B:]] = cir.cmp(ne, %{{.+}}, %[[#A]]) : !cir.f16, !s32i
// CHECK-NEXT: %[[#B:]] = cir.cmp(ne, %{{.+}}, %[[#A]]) : !cir.f16, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.cast(integral, %[[#B]] : !s32i), !u32i

// CHECK-LLVM: %[[#RHS:]] = sitofp i32 %{{.+}} to half
Expand Down
10 changes: 10 additions & 0 deletions clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -1437,3 +1437,13 @@ cir.global external @f = #cir.fp<0x7FC00000 : !cir.float> : !cir.float
// expected-error @below {{unexpected decimal integer literal for a floating point value}}
// expected-note @below {{add a trailing dot to make the literal a float}}
cir.global external @f = #cir.fp<42> : !cir.float

// -----

// Verify
!s32i = !cir.int<s, 32>
cir.func @cast0(%arg0: !s32i, %arg1: !s32i) {
// expected-error @below {{custom op 'cir.cmp' invalid kind of Type specified}}
%1 = cir.cmp(eq, %arg0, %arg1): !s32i, !s32i
cir.return
}
Loading

0 comments on commit 48f4934

Please sign in to comment.