[mlir][Vector] Update VectorEmulateNarrowType.cpp #123633
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims at improving "VectorEmulateNarrowType.cpp". This is mainly
minor refactoring, no major functional changes are made/added.
Implements #123630.
CHANGE 1
Renames
srcBits/dstBits
tooldBits/newBits
to improve consistency innaming within the file. This is illustrated below:
Also adds some comments and unifies related "rewriter notification"
messages.
CHANGE 2
Renames the variable "scale". Note, "scale" could mean either:
While from the context it is clear that it's always the former (original
type is always a sub-byte type and the emulated type is usually
i8
),this PR reduces the cognitive load by making this clear.
CHANGE 3
Replaces
isUnalignedEmulation
withisFullyAligned
Note,
isUnalignedEmulation
is always computed following a"per-element-alignment" condition:
Given that
isUnalignedEmulation
captures only one of two conditionsrequired for "full alignment", it should be re-named as
isPartiallyUnalignedEmulation
. Instead, I've flipped the condition andrenamed it as
isFullyAligned
:CHANGE 4
Unifies various comments throughout the file (for consistency).
CHANGE 5
Adds new comments throughout the file and adds TODOs where high-level
comments are missing.
CHANGE 6
Update
alignedConversionPrecondition
(1):This method didn't require the vector type for the "destination"
argument. The underlying element type is sufficient. The corresponding
argument has been renamed as
multiByteScalarTy
- this is meant as themulti-byte emulated type (
i8
,i16
,i32
, etc).CHANGE 7
Update
alignedConversionPrecondition
(2):In #121298, we replaced
dstElemBitwidt
in this calculation:with the hard-coded value of 8:
That was correct as for the patterns for which this hook was/is used:
RewriteAlignedSubByteIntExt
,RewriteAlignedSubByteIntTrunc
.The destination type (or, more precisely, the emulated type) was always
i8
.In this PR, I am switching back to a more generic approach - the
calculation should take into account the bit-width of the emulated type.
Note that at the call sites I am passing
i8
as the emulated type, so theend-result is effectively identical. However, the intent is clearer, i.e.,
the underlying value is 8 because the emulated type happens to be
i8
(as opposed using a magic number).
CHANGE 8
Update alignedConversionPrecondition (3):
The final check has been replaced with a new helper method,
isSubByteVecFittable
. This new method is also re-used within the codeand hopefully will allow us more code re-use moving forward (to avoid
re-implementing the same condition).