@@ -2044,6 +2044,15 @@ mlir::LogicalResult CIRToLLVMVecCreateOpLowering::matchAndRewrite(
2044
2044
return mlir::success ();
2045
2045
}
2046
2046
2047
+ static bool isCIRZeroVector (mlir::Value value) {
2048
+ if (auto constantOp = value.getDefiningOp <cir::ConstantOp>()) {
2049
+ if (auto zeroAttr = mlir::dyn_cast<cir::ZeroAttr>(constantOp.getValue ())) {
2050
+ return true ;
2051
+ }
2052
+ }
2053
+ return false ;
2054
+ }
2055
+
2047
2056
mlir::LogicalResult CIRToLLVMVecCmpOpLowering::matchAndRewrite (
2048
2057
cir::VecCmpOp op, OpAdaptor adaptor,
2049
2058
mlir::ConversionPatternRewriter &rewriter) const {
@@ -2052,9 +2061,16 @@ mlir::LogicalResult CIRToLLVMVecCmpOpLowering::matchAndRewrite(
2052
2061
auto elementType = elementTypeIfVector (op.getLhs ().getType ());
2053
2062
mlir::Value bitResult;
2054
2063
if (auto intType = mlir::dyn_cast<cir::IntType>(elementType)) {
2064
+
2065
+ bool shouldUseSigned = intType.isSigned ();
2066
+ // Special treatment For sign-bit extraction patterns (lt comparison with
2067
+ // zero), always use signed comparison to preserve the semantic intent
2068
+ if (op.getKind () == cir::CmpOpKind::lt && isCIRZeroVector (op.getRhs ())) {
2069
+ shouldUseSigned = true ;
2070
+ }
2055
2071
bitResult = rewriter.create <mlir::LLVM::ICmpOp>(
2056
2072
op.getLoc (),
2057
- convertCmpKindToICmpPredicate (op.getKind (), intType. isSigned () ),
2073
+ convertCmpKindToICmpPredicate (op.getKind (), shouldUseSigned ),
2058
2074
adaptor.getLhs (), adaptor.getRhs ());
2059
2075
} else if (mlir::isa<cir::FPTypeInterface>(elementType)) {
2060
2076
bitResult = rewriter.create <mlir::LLVM::FCmpOp>(
0 commit comments