================
@@ -88,6 +88,54 @@ findARMVectorIntrinsicInMap(ArrayRef<AArch64BuiltinInfo> 
intrinsicMap,
   return nullptr;
 }
 
+//===----------------------------------------------------------------------===//
+//  Emit-helpers
+//===----------------------------------------------------------------------===//
+mlir::Value CIRGenFunction::emitAArch64CompareBuiltinExpr(
+    mlir::Location loc, mlir::Value src, mlir::Type ty,
+    const llvm::CmpInst::Predicate pred) {
+
+  mlir::Value res;
+  if (isa<cir::VectorType>(ty) && !cast<cir::VectorType>(ty).getIsScalable()) {
+    // Vector types are cast to i8 vectors. Recover original type.
+    cgm.errorNYI(loc, std::string("unimplemented vector compare"));
+  }
+
+  // Scalar compare is a special case that is artifically converted to a
+  // 1-element vector compare. This is to guarantee that the output result is
+  // sign- rather than zero-extended.
+  //
+  // Specifically, a compare Op will generate an i1 result that needs to be
+  // extended to match the in/out type, `ty`. Regular scalar cast wwould lead
+  // to ZExt to preserve the value, e.g. 0b1 --> 0x00000001 (i1 -0> i16).
+  // Vector compare are meant to generate masks and these are exteded via SExt,
+  // so that 0b1 --> 0x11111111 and 0b0 --> 0x00000000.
+  bool scalarInputs = isa<cir::IntType>(src.getType());
+
+  mlir::Value zero = builder.getNullValue(ty, loc);
+  if (CmpInst::isFPPredicate(pred)) {
+    cgm.errorNYI(loc, std::string("unimplemented FP compare"));
+    // TODO:
+    //   if (Pred == CmpInst::FCMP_OEQ)
+    //   else
+  } else {
+    if (scalarInputs) {
+      cir::VectorType ty = cir::VectorType::get(src.getType(), 1, false);
+      src = cir::VecSplatOp::create(builder, loc, ty, src);
----------------
andykaylor wrote:

Rather than doing the vector splat and everything else here, could you just 
bitcast the compare result from `cir.bool` to `cir.int<s, 1>`? 

https://github.com/llvm/llvm-project/pull/179779
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to