@@ -731,8 +731,9 @@ mlir::Value CirAttrToValue::visitCirAttr(cir::GlobalViewAttr globalAttr) {
731
731
}
732
732
auto resTy = addrOp.getType ();
733
733
auto eltTy = converter->convertType (sourceType);
734
- addrOp = rewriter.create <mlir::LLVM::GEPOp>(loc, resTy, eltTy, addrOp,
735
- indices, mlir::LLVM::GEPNoWrapFlags::inbounds);
734
+ addrOp = rewriter.create <mlir::LLVM::GEPOp>(
735
+ loc, resTy, eltTy, addrOp, indices,
736
+ mlir::LLVM::GEPNoWrapFlags::inbounds);
736
737
}
737
738
738
739
if (auto intTy = mlir::dyn_cast<cir::IntType>(globalAttr.getType ())) {
@@ -1205,8 +1206,9 @@ mlir::LogicalResult CIRToLLVMVTTAddrPointOpLowering::matchAndRewrite(
1205
1206
offsets.push_back (0 );
1206
1207
offsets.push_back (adaptor.getOffset ());
1207
1208
}
1208
- rewriter.replaceOpWithNewOp <mlir::LLVM::GEPOp>(op, resultType, eltType,
1209
- llvmAddr, offsets, mlir::LLVM::GEPNoWrapFlags::inbounds);
1209
+ rewriter.replaceOpWithNewOp <mlir::LLVM::GEPOp>(
1210
+ op, resultType, eltType, llvmAddr, offsets,
1211
+ mlir::LLVM::GEPNoWrapFlags::inbounds);
1210
1212
return mlir::success ();
1211
1213
}
1212
1214
@@ -2052,9 +2054,24 @@ mlir::LogicalResult CIRToLLVMVecCmpOpLowering::matchAndRewrite(
2052
2054
auto elementType = elementTypeIfVector (op.getLhs ().getType ());
2053
2055
mlir::Value bitResult;
2054
2056
if (auto intType = mlir::dyn_cast<cir::IntType>(elementType)) {
2057
+
2058
+ auto isCIRZeroVector = [](mlir::Value value) {
2059
+ if (auto constantOp = value.getDefiningOp <cir::ConstantOp>())
2060
+ if (auto zeroAttr =
2061
+ mlir::dyn_cast<cir::ZeroAttr>(constantOp.getValue ()))
2062
+ return true ;
2063
+ return false ;
2064
+ };
2065
+
2066
+ bool shouldUseSigned = intType.isSigned ();
2067
+ // Special treatment for sign-bit extraction patterns (lt comparison with
2068
+ // zero), always use signed comparison to preserve the semantic intent
2069
+ if (op.getKind () == cir::CmpOpKind::lt && isCIRZeroVector (op.getRhs ()))
2070
+ shouldUseSigned = true ;
2071
+
2055
2072
bitResult = rewriter.create <mlir::LLVM::ICmpOp>(
2056
2073
op.getLoc (),
2057
- convertCmpKindToICmpPredicate (op.getKind (), intType. isSigned () ),
2074
+ convertCmpKindToICmpPredicate (op.getKind (), shouldUseSigned ),
2058
2075
adaptor.getLhs (), adaptor.getRhs ());
2059
2076
} else if (mlir::isa<cir::FPTypeInterface>(elementType)) {
2060
2077
bitResult = rewriter.create <mlir::LLVM::FCmpOp>(
@@ -3881,8 +3898,9 @@ mlir::LogicalResult CIRToLLVMVTableAddrPointOpLowering::matchAndRewrite(
3881
3898
op.getAddressPointAttr ().getOffset ()};
3882
3899
3883
3900
assert (eltType && " Shouldn't ever be missing an eltType here" );
3884
- rewriter.replaceOpWithNewOp <mlir::LLVM::GEPOp>(op, targetType, eltType,
3885
- symAddr, offsets, mlir::LLVM::GEPNoWrapFlags::inbounds);
3901
+ rewriter.replaceOpWithNewOp <mlir::LLVM::GEPOp>(
3902
+ op, targetType, eltType, symAddr, offsets,
3903
+ mlir::LLVM::GEPNoWrapFlags::inbounds);
3886
3904
3887
3905
return mlir::success ();
3888
3906
}
@@ -3908,7 +3926,8 @@ mlir::LogicalResult CIRToLLVMVTableGetVirtualFnAddrOpLowering::matchAndRewrite(
3908
3926
llvm::SmallVector<mlir::LLVM::GEPArg> offsets =
3909
3927
llvm::SmallVector<mlir::LLVM::GEPArg>{op.getIndex ()};
3910
3928
rewriter.replaceOpWithNewOp <mlir::LLVM::GEPOp>(
3911
- op, targetType, eltType, adaptor.getVptr (), offsets, mlir::LLVM::GEPNoWrapFlags::inbounds);
3929
+ op, targetType, eltType, adaptor.getVptr (), offsets,
3930
+ mlir::LLVM::GEPNoWrapFlags::inbounds);
3912
3931
return mlir::success ();
3913
3932
}
3914
3933
@@ -4000,7 +4019,9 @@ mlir::LogicalResult CIRToLLVMInlineAsmOpLowering::matchAndRewrite(
4000
4019
op, llResTy, llvmOperands, op.getAsmStringAttr (), op.getConstraintsAttr (),
4001
4020
op.getSideEffectsAttr (),
4002
4021
/* is_align_stack*/ mlir::UnitAttr (),
4003
- /* tail_call_kind*/ mlir::LLVM::TailCallKindAttr::get (getContext (), mlir::LLVM::tailcallkind::TailCallKind::None),
4022
+ /* tail_call_kind*/
4023
+ mlir::LLVM::TailCallKindAttr::get (
4024
+ getContext (), mlir::LLVM::tailcallkind::TailCallKind::None),
4004
4025
mlir::LLVM::AsmDialectAttr::get (getContext (), llDialect),
4005
4026
rewriter.getArrayAttr (opAttrs));
4006
4027
0 commit comments