-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MooreToCore] Properly deal with OOB access in dyn_extract #8201
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -825,12 +825,30 @@ struct DynExtractOpConversion : public OpConversionPattern<DynExtractOp> { | |
op->getLoc()); | ||
|
||
if (isa<hw::ArrayType>(resultType)) { | ||
// FIXME: for packed arrays, the part that is OOB must be 0 or X and the | ||
// part overlapping with the range must match the values of the range; | ||
// for unpacked arrays, if part of the accessed slice is OOB the entire | ||
// result is 0 or X | ||
rewriter.replaceOpWithNewOp<hw::ArraySliceOp>(op, resultType, | ||
adaptor.getInput(), idx); | ||
return success(); | ||
} | ||
|
||
rewriter.replaceOpWithNewOp<hw::ArrayGetOp>(op, adaptor.getInput(), idx); | ||
Value size = rewriter.create<hw::ConstantOp>( | ||
op.getLoc(), adaptor.getLowBit().getType(), arrType.getNumElements()); | ||
Value isOOB = rewriter.create<comb::ICmpOp>( | ||
op.getLoc(), ICmpPredicate::uge, adaptor.getLowBit(), size); | ||
Value access = | ||
rewriter.create<hw::ArrayGetOp>(op.getLoc(), adaptor.getInput(), idx); | ||
int64_t bw = hw::getBitWidth(arrType.getElementType()); | ||
if (bw < 0) | ||
return failure(); | ||
|
||
Value zeroValueRaw = | ||
rewriter.create<hw::ConstantOp>(op.getLoc(), APInt(bw, 0)); | ||
Value zeroValue = rewriter.createOrFold<hw::BitcastOp>( | ||
op.getLoc(), arrType.getElementType(), zeroValueRaw); | ||
rewriter.replaceOpWithNewOp<comb::MuxOp>(op, isOOB, zeroValue, access); | ||
Comment on lines
+841
to
+851
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks reasonable assuming that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation of the HW aggregate ops is generally a bit sparse, but I'd say a OOB |
||
return success(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That can cause problems if the lowBit bitwidth is too small to hold the array size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. In that case we might be guaranteed to always access in bounds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 👍
But I need to make sure this IR is not built in that case because the pass would crash.