@@ -1372,44 +1372,42 @@ mlir::LogicalResult CIRToLLVMCmpOpLowering::matchAndRewrite(
1372
1372
mlir::LogicalResult CIRToLLVMShiftOpLowering::matchAndRewrite (
1373
1373
cir::ShiftOp op, OpAdaptor adaptor,
1374
1374
mlir::ConversionPatternRewriter &rewriter) const {
1375
- auto cirAmtTy = mlir::dyn_cast<cir::IntType>( op.getAmount ().getType ());
1376
- auto cirValTy = mlir::dyn_cast<cir::IntType>(op. getValue (). getType () );
1375
+ assert (( op.getValue ().getType () == op. getType ()) &&
1376
+ " inconsistent operands' types NYI " );
1377
1377
1378
- // Operands could also be vector type
1379
- auto cirAmtVTy = mlir::dyn_cast<cir::VectorType>(op.getAmount ().getType ());
1380
- auto cirValVTy = mlir::dyn_cast<cir::VectorType>(op.getValue ().getType ());
1381
- mlir::Type llvmTy = getTypeConverter ()->convertType (op.getType ());
1378
+ const mlir::Type llvmTy = getTypeConverter ()->convertType (op.getType ());
1382
1379
mlir::Value amt = adaptor.getAmount ();
1383
1380
mlir::Value val = adaptor.getValue ();
1384
1381
1385
- assert (((cirValTy && cirAmtTy) || (cirAmtVTy && cirValVTy)) &&
1386
- " shift input type must be integer or vector type, otherwise NYI" );
1387
-
1388
- assert ((cirValTy == op.getType () || cirValVTy == op.getType ()) &&
1389
- " inconsistent operands' types NYI" );
1390
-
1391
- // Ensure shift amount is the same type as the value. Some undefined
1392
- // behavior might occur in the casts below as per [C99 6.5.7.3].
1393
- // Vector type shift amount needs no cast as type consistency is expected to
1394
- // be already be enforced at CIRGen.
1395
- if (cirAmtTy)
1396
- amt = getLLVMIntCast (rewriter, amt, mlir::cast<mlir::IntegerType>(llvmTy),
1397
- true , cirAmtTy.getWidth (), cirValTy.getWidth ());
1382
+ auto cirAmtTy = mlir::dyn_cast<cir::IntType>(op.getAmount ().getType ());
1383
+ bool isUnsigned;
1384
+ if (cirAmtTy) {
1385
+ auto cirValTy = mlir::cast<cir::IntType>(op.getValue ().getType ());
1386
+ isUnsigned = cirValTy.isUnsigned ();
1387
+
1388
+ // Ensure shift amount is the same type as the value. Some undefined
1389
+ // behavior might occur in the casts below as per [C99 6.5.7.3].
1390
+ // Vector type shift amount needs no cast as type consistency is expected to
1391
+ // be already be enforced at CIRGen.
1392
+ if (cirAmtTy)
1393
+ amt = getLLVMIntCast (rewriter, amt, llvmTy, true , cirAmtTy.getWidth (),
1394
+ cirValTy.getWidth ());
1395
+ } else {
1396
+ auto cirValVTy = mlir::cast<cir::VectorType>(op.getValue ().getType ());
1397
+ isUnsigned =
1398
+ mlir::cast<cir::IntType>(cirValVTy.getElementType ()).isUnsigned ();
1399
+ }
1398
1400
1399
1401
// Lower to the proper LLVM shift operation.
1400
1402
if (op.getIsShiftleft ()) {
1401
1403
rewriter.replaceOpWithNewOp <mlir::LLVM::ShlOp>(op, llvmTy, val, amt);
1402
- } else {
1403
- const bool isUnsigned =
1404
- cirValTy
1405
- ? !cirValTy.isSigned ()
1406
- : !mlir::cast<cir::IntType>(cirValVTy.getElementType ()).isSigned ();
1407
- if (isUnsigned)
1408
- rewriter.replaceOpWithNewOp <mlir::LLVM::LShrOp>(op, llvmTy, val, amt);
1409
- else
1410
- rewriter.replaceOpWithNewOp <mlir::LLVM::AShrOp>(op, llvmTy, val, amt);
1404
+ return mlir::success ();
1411
1405
}
1412
1406
1407
+ if (isUnsigned)
1408
+ rewriter.replaceOpWithNewOp <mlir::LLVM::LShrOp>(op, llvmTy, val, amt);
1409
+ else
1410
+ rewriter.replaceOpWithNewOp <mlir::LLVM::AShrOp>(op, llvmTy, val, amt);
1413
1411
return mlir::success ();
1414
1412
}
1415
1413
0 commit comments