@@ -207,9 +207,11 @@ static bool findBaseAndIndices(mlir::Value addr, mlir::Value &base,
207
207
while (mlir::Operation *addrOp = addr.getDefiningOp ()) {
208
208
if (!isa<mlir::memref::ReinterpretCastOp>(addrOp))
209
209
break ;
210
- indices.push_back (addrOp->getOperand (1 ));
211
210
addr = addrOp->getOperand (0 );
212
211
eraseList.push_back (addrOp);
212
+ // If there is another operand, assume it is the lowered index
213
+ if (addrOp->getNumOperands () == 2 )
214
+ indices.push_back (addrOp->getOperand (1 ));
213
215
}
214
216
base = addr;
215
217
if (indices.size () == 0 )
@@ -1150,6 +1152,23 @@ class CIRCastOpLowering : public mlir::OpConversionPattern<cir::CastOp> {
1150
1152
op, newDstType, src, 0 , std::nullopt, std::nullopt);
1151
1153
return mlir::success ();
1152
1154
}
1155
+ case CIR::bitcast: {
1156
+ // clang-format off
1157
+ // %7 = cir.cast(bitcast, %6 : !cir.ptr<!s32i>), !cir.ptr<!cir.array<!s32i x 8192>>
1158
+ // Is lowered as
1159
+ // memref<i32> → memref.reinterpret_cast → memref<8192xi32>
1160
+ // clang-format on
1161
+ auto newDstType = convertTy (dstType);
1162
+ if (!(mlir::isa<mlir::MemRefType>(adaptor.getSrc ().getType ()) &&
1163
+ mlir::isa<mlir::MemRefType>(newDstType)))
1164
+ return op.emitError () << " NYI bitcast from " << op.getSrc ().getType ()
1165
+ << " to " << dstType;
1166
+ auto dstMR = mlir::cast<mlir::MemRefType>(newDstType);
1167
+ auto [strides, offset] = dstMR.getStridesAndOffset ();
1168
+ rewriter.replaceOpWithNewOp <mlir::memref::ReinterpretCastOp>(
1169
+ op, dstMR, src, offset, dstMR.getShape (), strides);
1170
+ return mlir::success ();
1171
+ }
1153
1172
case CIR::int_to_bool: {
1154
1173
auto zero = rewriter.create <cir::ConstantOp>(
1155
1174
src.getLoc (), op.getSrc ().getType (),
0 commit comments