Repository navigation
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsTrying to address this issue: #67869 Description We added a new lowering op 'GT_MSUB' for ARM64. It only emits 'msub'. However, the existing 'GT_MADD' can also emit 'msub' if only one of the multiply ops is a GT_NEG. For consistency, 'GT_MADD' should simply emit 'madd' and we should do the transformation earlier when one of the multiply ops is 'GT_NEG'. I'm trying out the transformation in morph to see how it goes. We should not at all regress anything as a result of this PR. Acceptance Criteria
|
|
This is ready if CI passes. From the diffs I've looked it, this is what was changed: - mul w0, w21, w0
- add w1, w0, #5
+ mov w1, #5
+ madd w1, w21, w0, w1 |
BruceForstall
left a comment
There was a problem hiding this comment.
A few questions.
Also, looks like a lot of tests failed.
Please run jitstress when other pipelines succeed.
| useMsub = !useMsub; // it's either "a * -b" or "-a * -b" which is the same as "a * b" | ||
| } | ||
| GenTree* a = tree->gtGetOp1(); | ||
| GenTree* b = tree->gtGetOp2()->gtGetOp1(); |
There was a problem hiding this comment.
Is tree->gtGetOp2() expected to be GT_MUL? Is that because we don't have a GenTree node that contains all three arguments directly (should we? like some of the block ops, for example) Can you assert that?
There was a problem hiding this comment.
Is tree->gtGetOp2() expected to be GT_MUL?
Yes and I believe it is because we don't have a three-argument node.
should we?
I don't think we need to.
It feels a little odd to have a tree like this:
MADD(a, MUL(b, c))
I don't think it is necessary to even have GT_MADD/GT_MSUB nodes.
Before containment, if the expr looks like this:
ADD(a, MUL(b, c)) - we really only need to mark the MUL as contained, then at codegen, we look to see if op2 is GT_MUL and contained to do the 'madd'. I did this with GT_MSUB here: #68363
I might end up combining this PR and that one because they are so similar.
| { | ||
| // Find "a * b + c" or "c + a * b" in order to emit MADD/MSUB | ||
| if (node->OperIs(GT_ADD) && !node->gtOverflow() && (op1->OperIs(GT_MUL) || op2->OperIs(GT_MUL))) | ||
| // Find "a + b * c" in order to emit MADD |
There was a problem hiding this comment.
Why don't you handle the a * b + c case anymore?
There was a problem hiding this comment.
It does get handled if you look at the change in Lowering::LowerAdd:
// Transform "a * b + c" to "c + a * b"
else if (op1->OperIs(GT_MUL))
{
node->gtOp1 = c;
node->gtOp2 = mul;
}| return next; | ||
| } | ||
| #ifdef TARGET_ARM64 | ||
| if (BlockRange().TryGetUse(node, &use)) |
There was a problem hiding this comment.
Add some comments here about the purpose of the following code?
There was a problem hiding this comment.
I can do that, though this kind of code is pretty common in lowering.
| #ifdef TARGET_ARM64 | ||
| if (BlockRange().TryGetUse(node, &use)) | ||
| { | ||
| if (comp->opts.OptimizationEnabled() && varTypeIsIntegral(node) && !node->gtOverflow() && |
There was a problem hiding this comment.
Is there a reason why this optimization is done during lower instead of morph?
There was a problem hiding this comment.
Yes. There are a couple of reasons:
- There are no
GT_MADD/GT_MSUBHIR ops that can be used in the morph phase. - Re-arranging the nodes in morph, like what we are doing in lowering, change what CSEs get picked up.
- Originally in this PR, I did the re-arrangement in morph. When I looked at the codegen, there were several places that regressed. I wish we had a morph-like phase after all CSE phases are complete instead of having to do the work in lowering.
|
Thank you for the review @BruceForstall . Almost all CI failures here are for x64 which is very weird; it should not be as the result of these changes. I think I'm going to combine this with #68363 . |
|
#68363 now has these changes - I'm going to combine them in there. |
Trying to address this issue: #67869
Description
We added a new lowering op 'GT_MSUB' for ARM64. It only emits 'msub'. However, the existing 'GT_MADD' can also emit 'msub' if only one of the multiply ops is a GT_NEG.
For consistency, 'GT_MADD' should simply emit 'madd' and we should do the transformation earlier when one of the multiply ops is 'GT_NEG'.
I'm trying out the transformation in morph or lowering to see how it goes. We should not at all regress anything as a result of this PR.
Acceptance Criteria