================
@@ -501,19 +417,94 @@ static mlir::Value emitX86vpcom(CIRGenBuilderTy &builder, 
mlir::Location loc,
   return builder.createVecCompare(loc, pred, op0, op1);
 }
 
-std::optional<mlir::Value>
-CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID, const CallExpr *expr) {
+static mlir::Value emitX86MaskedCompare(CIRGenBuilderTy &builder, 
mlir::Location loc,
+                                        llvm::SmallVector<mlir::Value> ops, 
bool isSigned = true)
+{
+
+  uint64_t imm = CIRGenFunction::getZExtIntValueFromConstOp(ops[2]) & 0x7;
+  cir::VectorType ty = cast<cir::VectorType>(ops[0].getType());
+  cir::IntType elementTy = cast<cir::IntType>(ty.getElementType());
+  unsigned numElts = ty.getSize();
+  mlir::Value cmp;
+  if (imm == 3)
+  {
+    cmp = builder.getNullValue(cir::VectorType::get(builder.getSIntNTy(1), 
numElts), loc);
+  }
+  else if (imm == 7)
+  {
+    llvm::APInt allOnes = llvm::APInt::getAllOnes(elementTy.getWidth());
+    cmp = cir::VecSplatOp::create(
+        builder, loc, ty, builder.getConstAPInt(loc, elementTy, allOnes));
+  }
+  else
+  {
+    cir::CmpOpKind pred;
+    switch(imm) {
+      default:
+        llvm_unreachable("Unknown condition code");
+      case 0:
+        pred = cir::CmpOpKind::eq;
+        break;
+      case 1:
+        pred = cir::CmpOpKind::lt;
+        break;
+      case 2:
+        pred = cir::CmpOpKind::le;
+        break;
+      case 4:
+        pred = cir::CmpOpKind::ne;
+        break;
+      case 5:
+        pred = cir::CmpOpKind::ge;
+        break;
+      case 6:
+        pred = cir::CmpOpKind::gt;
+        break;
+    }
+      cir::VectorType integralVecTy = 
cir::VectorType::get(builder.getUIntNTy(1), numElts);
+      cmp = cir::VecCmpOp::create(builder, loc, integralVecTy, pred, ops[0], 
ops[1]);
+    }
+  mlir::Value maskIn = nullptr;
+  if (ops.size() == 4)
+    maskIn = ops[3];
+
+  if (maskIn)
+  {
+    auto castOp = mlir::dyn_cast_or_null<cir::CastOp>(maskIn.getDefiningOp());
+    if (!castOp)
+    {
+      auto maskVec = getMaskVecValue(builder, loc, maskIn, numElts);
----------------
Lancern wrote:

```suggestion
      mlir::Value maskVec = getMaskVecValue(builder, loc, maskIn, numElts);
```

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

Reply via email to