================
@@ -264,15 +264,31 @@ static mlir::Value emitX86MaskTest(CIRGenBuilderTy 
&builder, mlir::Location loc,
                              mlir::ValueRange{lhsVec, rhsVec});
 }
 
-// TODO: The cgf parameter should be removed when all the NYI cases are
-// implemented.
 static std::optional<mlir::Value>
-emitX86MaskedCompareResult(CIRGenFunction &cgf, CIRGenBuilderTy &builder,
-                           mlir::Value cmp, unsigned numElts,
-                           mlir::Value maskIn, mlir::Location loc) {
+emitX86MaskedCompareResult(CIRGenBuilderTy &builder, mlir::Value cmp,
+                           unsigned numElts, mlir::Value maskIn,
+                           mlir::Location loc) {
   if (maskIn) {
-    cgf.cgm.errorNYI(loc, "emitX86MaskedCompareResult");
-    return {};
+    bool isAllOnes = false;
+    mlir::Value maskInValue = maskIn;
+    auto castOp = mlir::dyn_cast_or_null<cir::CastOp>(maskIn.getDefiningOp());
+    if (castOp && castOp.getKind() == cir::CastKind::integral) {
+      maskInValue = castOp.getResult();
+      isAllOnes = true;
+    }
+    auto unaryOp =
+        mlir::dyn_cast_or_null<cir::UnaryOp>(maskInValue.getDefiningOp());
+    if (unaryOp && unaryOp.getKind() == cir::UnaryOpKind::Minus) {
----------------
andykaylor wrote:

I'm not sure this is the approach we want. In classic codegen, the LLVM 
IRBuilder automatically folds the minus operator into the constant. I've been 
working on a patch to do that in CIR, but I'm not sure how far to go with that. 
For now, it would be good to have a helper function that checked whether the 
input value is all ones, and put the cast and unary op handling logic there.

BTW, your implementation misses the case where the input is a literal that is 
all ones, such as 0xFFFF.

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

Reply via email to