1919#include " mlir/Dialect/DLTI/DLTI.h"
2020#include " mlir/Dialect/Func/IR/FuncOps.h"
2121#include " mlir/Dialect/LLVMIR/LLVMDialect.h"
22+ #include " mlir/IR/BuiltinAttributes.h"
2223#include " mlir/IR/BuiltinDialect.h"
2324#include " mlir/IR/BuiltinOps.h"
2425#include " mlir/IR/Types.h"
2829#include " mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
2930#include " mlir/Target/LLVMIR/Export.h"
3031#include " mlir/Transforms/DialectConversion.h"
32+ #include " clang/CIR/Dialect/IR/CIRAttrs.h"
3133#include " clang/CIR/Dialect/IR/CIRDialect.h"
3234#include " clang/CIR/Dialect/Passes.h"
3335#include " clang/CIR/LoweringHelpers.h"
@@ -1318,8 +1320,7 @@ mlir::LogicalResult CIRToLLVMShiftOpLowering::matchAndRewrite(
13181320 // be already be enforced at CIRGen.
13191321 if (cirAmtTy)
13201322 amt = getLLVMIntCast (rewriter, amt, mlir::cast<mlir::IntegerType>(llvmTy),
1321- !cirAmtTy.isSigned (), cirAmtTy.getWidth (),
1322- cirValTy.getWidth ());
1323+ true , cirAmtTy.getWidth (), cirValTy.getWidth ());
13231324
13241325 // Lower to the proper LLVM shift operation.
13251326 if (op.getIsShiftleft ()) {
@@ -1339,32 +1340,32 @@ mlir::LogicalResult CIRToLLVMShiftOpLowering::matchAndRewrite(
13391340mlir::LogicalResult CIRToLLVMSelectOpLowering::matchAndRewrite (
13401341 cir::SelectOp op, OpAdaptor adaptor,
13411342 mlir::ConversionPatternRewriter &rewriter) const {
1342- auto getConstantBool = [](mlir::Value value) -> std::optional< bool > {
1343+ auto getConstantBool = [](mlir::Value value) -> cir::BoolAttr {
13431344 auto definingOp =
13441345 mlir::dyn_cast_if_present<cir::ConstantOp>(value.getDefiningOp ());
13451346 if (!definingOp)
1346- return std:: nullopt ;
1347+ return {} ;
13471348
13481349 auto constValue = mlir::dyn_cast<cir::BoolAttr>(definingOp.getValue ());
13491350 if (!constValue)
1350- return std:: nullopt ;
1351+ return {} ;
13511352
1352- return constValue. getValue () ;
1353+ return constValue;
13531354 };
13541355
13551356 // Two special cases in the LLVMIR codegen of select op:
13561357 // - select %0, %1, false => and %0, %1
13571358 // - select %0, true, %1 => or %0, %1
13581359 if (mlir::isa<cir::BoolType>(op.getTrueValue ().getType ())) {
1359- std::optional< bool > trueValue = getConstantBool (op.getTrueValue ());
1360- std::optional< bool > falseValue = getConstantBool (op.getFalseValue ());
1361- if (falseValue. has_value () && !* falseValue) {
1360+ cir::BoolAttr trueValue = getConstantBool (op.getTrueValue ());
1361+ cir::BoolAttr falseValue = getConstantBool (op.getFalseValue ());
1362+ if (falseValue && !falseValue. getValue () ) {
13621363 // select %0, %1, false => and %0, %1
13631364 rewriter.replaceOpWithNewOp <mlir::LLVM::AndOp>(op, adaptor.getCondition (),
13641365 adaptor.getTrueValue ());
13651366 return mlir::success ();
13661367 }
1367- if (trueValue. has_value () && * trueValue) {
1368+ if (trueValue && trueValue. getValue () ) {
13681369 // select %0, true, %1 => or %0, %1
13691370 rewriter.replaceOpWithNewOp <mlir::LLVM::OrOp>(op, adaptor.getCondition (),
13701371 adaptor.getFalseValue ());
0 commit comments