@@ -1985,6 +1985,15 @@ mlir::LogicalResult CIRToLLVMVecCreateOpLowering::matchAndRewrite(
19851985 return mlir::success ();
19861986}
19871987
1988+ static bool isCIRZeroVector (mlir::Value value) {
1989+ if (auto constantOp = value.getDefiningOp <cir::ConstantOp>()) {
1990+ if (auto zeroAttr = mlir::dyn_cast<cir::ZeroAttr>(constantOp.getValue ())) {
1991+ return true ;
1992+ }
1993+ }
1994+ return false ;
1995+ }
1996+
19881997mlir::LogicalResult CIRToLLVMVecCmpOpLowering::matchAndRewrite (
19891998 cir::VecCmpOp op, OpAdaptor adaptor,
19901999 mlir::ConversionPatternRewriter &rewriter) const {
@@ -1993,9 +2002,16 @@ mlir::LogicalResult CIRToLLVMVecCmpOpLowering::matchAndRewrite(
19932002 auto elementType = elementTypeIfVector (op.getLhs ().getType ());
19942003 mlir::Value bitResult;
19952004 if (auto intType = mlir::dyn_cast<cir::IntType>(elementType)) {
2005+
2006+ bool shouldUseSigned = intType.isSigned ();
2007+ // Special treatment For sign-bit extraction patterns (lt comparison with
2008+ // zero), always use signed comparison to preserve the semantic intent
2009+ if (op.getKind () == cir::CmpOpKind::lt && isCIRZeroVector (op.getRhs ())) {
2010+ shouldUseSigned = true ;
2011+ }
19962012 bitResult = rewriter.create <mlir::LLVM::ICmpOp>(
19972013 op.getLoc (),
1998- convertCmpKindToICmpPredicate (op.getKind (), intType. isSigned () ),
2014+ convertCmpKindToICmpPredicate (op.getKind (), shouldUseSigned ),
19992015 adaptor.getLhs (), adaptor.getRhs ());
20002016 } else if (mlir::isa<cir::FPTypeInterface>(elementType)) {
20012017 bitResult = rewriter.create <mlir::LLVM::FCmpOp>(
0 commit comments